10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include < pqxx/pqxx> /* libpqxx is used to instantiate C++ client */
13
14
#include " common/harness.h"
14
- #include " gtest/gtest.h"
15
15
#include " common/logger.h"
16
+ #include " gtest/gtest.h"
17
+ #include " network/connection_handle_factory.h"
16
18
#include " network/peloton_server.h"
17
- #include " network/protocol_handler_factory.h"
18
- #include " util/string_util.h"
19
- #include < pqxx/pqxx> /* libpqxx is used to instantiate C++ client */
20
19
#include " network/postgres_protocol_handler.h"
20
+ #include " network/protocol_handler_factory.h"
21
21
#include " peloton_config.h"
22
- #include " network/connection_handle_factory .h"
22
+ #include " util/string_util .h"
23
23
24
24
#define NUM_THREADS 1
25
25
@@ -32,22 +32,34 @@ namespace test {
32
32
33
33
class SSLTests : public PelotonTest {};
34
34
35
+ std::string server_crt = std::string(StringUtil::Format(
36
+ " %s%s" , SOURCE_FOLDER, " /test/network/ssl/server_test.crt" ));
37
+ std::string server_key = std::string(StringUtil::Format(
38
+ " %s%s" , SOURCE_FOLDER, " /test/network/ssl/server_test.key" ));
39
+ std::string root_crt = std::string(StringUtil::Format(
40
+ " %s%s" , SOURCE_FOLDER, " /test/network/ssl/root_test.crt" ));
41
+
35
42
/* *
36
43
* Basic SSL connection test: Tested with valid certificats and key files
37
44
*/
38
45
void *BasicTest (int port) {
39
46
try {
40
47
// forcing the factory to generate psql protocol handler
41
48
pqxx::connection C (StringUtil::Format (
42
- " host=127.0.0.1 port=%d user=default_database application_name=psql sslmode=require" , port));
49
+ " host=127.0.0.1 port=%d user=default_database application_name=psql "
50
+ " sslmode=require sslcert=%s sslkey=%s sslrootcert=%s " ,
51
+ port, server_crt, server_key, root_crt));
52
+
43
53
pqxx::work txn1 (C);
44
54
45
55
peloton::network::ConnectionHandle *conn =
46
- peloton::network::ConnectionHandleFactory::GetInstance ().ConnectionHandleAt (
47
- peloton::network::PelotonServer::recent_connfd).get ();
56
+ peloton::network::ConnectionHandleFactory::GetInstance ()
57
+ .ConnectionHandleAt (peloton::network::PelotonServer::recent_connfd)
58
+ .get ();
48
59
49
60
network::PostgresProtocolHandler *handler =
50
- dynamic_cast <network::PostgresProtocolHandler *>(conn->GetProtocolHandler ().get ());
61
+ dynamic_cast <network::PostgresProtocolHandler *>(
62
+ conn->GetProtocolHandler ().get ());
51
63
EXPECT_NE (handler, nullptr );
52
64
53
65
// basic test
@@ -63,7 +75,7 @@ void *BasicTest(int port) {
63
75
64
76
pqxx::result R = txn2.exec (" SELECT name FROM employee where id=1;" );
65
77
txn2.commit ();
66
-
78
+
67
79
EXPECT_EQ (R.size (), 1 );
68
80
69
81
// SSL large write test
@@ -104,16 +116,13 @@ TEST_F(SSLTests, BasicTest) {
104
116
peloton::network::PelotonServer peloton_server;
105
117
int port = 15721 ;
106
118
try {
107
- std::string server_crt = " /test/network/ssl/server_test.crt" ;
108
- std::string server_key = " /test/network/ssl/server_test.key" ;
109
- std::string root_crt = " /test/network/ssl/root_test.crt" ;
110
- peloton::network::PelotonServer::certificate_file_ = SOURCE_FOLDER + server_crt;
111
- peloton::network::PelotonServer::private_key_file_ = SOURCE_FOLDER + server_key;
112
- peloton::network::PelotonServer::root_cert_file_ = SOURCE_FOLDER + root_crt;
113
- peloton::network::PelotonServer::SSLInit ();
114
-
115
- peloton_server.SetPort (port);
116
- peloton_server.SetupServer ();
119
+ peloton::network::PelotonServer::certificate_file_ = server_crt;
120
+ peloton::network::PelotonServer::private_key_file_ = server_key;
121
+ peloton::network::PelotonServer::root_cert_file_ = root_crt;
122
+ peloton::network::PelotonServer::SSLInit ();
123
+
124
+ peloton_server.SetPort (port);
125
+ peloton_server.SetupServer ();
117
126
} catch (peloton::ConnectionException &exception) {
118
127
LOG_INFO (" [LaunchServer] exception in thread" );
119
128
}
0 commit comments