Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
thrift-server-test.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 #include "rpc/thrift-client.h"
17 #include "service/impala-server.h"
18 #include <string>
19 #include <gtest/gtest.h>
20 #include "common/init.h"
21 #include "service/fe-support.h"
22 
23 #include "common/names.h"
24 
25 using namespace impala;
26 
27 DECLARE_string(ssl_server_certificate);
28 DECLARE_string(ssl_private_key);
29 DECLARE_string(ssl_client_ca_certificate);
30 
31 DECLARE_int32(be_port);
32 DECLARE_int32(beeswax_port);
33 
34 TEST(SslTest, Connectivity) {
35  // Start a server using SSL and confirm that an SSL client can connect, while a non-SSL
36  // client cannot.
37  string impala_home(getenv("IMPALA_HOME"));
38  stringstream server_cert;
39  server_cert << impala_home << "/be/src/testutil/server-cert.pem";
40  FLAGS_ssl_server_certificate = server_cert.str();
41  FLAGS_ssl_client_ca_certificate = server_cert.str();
42  stringstream server_key;
43  server_key << impala_home << "/be/src/testutil/server-key.pem";
44  FLAGS_ssl_private_key = server_key.str();
45 
46  // TODO: Revert to stack-allocated when IMPALA-618 is fixed.
47  InProcessImpalaServer* impala =
48  new InProcessImpalaServer("localhost", FLAGS_be_port, 0, 0, "", 0);
50  impala->StartWithClientServers(FLAGS_beeswax_port, FLAGS_beeswax_port + 1, false));
51 
53  "localhost", FLAGS_beeswax_port, "", NULL, true);
54  EXPECT_TRUE(ssl_client.Open().ok());
55 
56  TPingImpalaServiceResp resp;
57  EXPECT_NO_THROW({
58  ssl_client.iface()->PingImpalaService(resp);
59  });
60 
61  ThriftClient<ImpalaServiceClient> non_ssl_client(
62  "localhost", FLAGS_beeswax_port, "", NULL, false);
63  EXPECT_TRUE(non_ssl_client.Open().ok());
64  EXPECT_THROW(non_ssl_client.iface()->PingImpalaService(resp), TTransportException);
65 }
66 
67 int main(int argc, char** argv) {
68  InitCommonRuntime(argc, argv, true);
69  InitFeSupport();
70  ::testing::InitGoogleTest(&argc, argv);
71  return RUN_ALL_TESTS();
72 }
DECLARE_int32(be_port)
void InitFeSupport()
Definition: fe-support.cc:346
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
Definition: init.cc:122
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
int main(int argc, char **argv)
#define EXIT_IF_ERROR(stmt)
Definition: status.h:248
DECLARE_string(ssl_server_certificate)
Status StartWithClientServers(int beeswax_port, int hs2_port, bool use_statestore)