Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit aac75ed

Browse files
author
Tianyi Chen
committed
try to fix ssl crt permission denied on client side
1 parent e7a58e1 commit aac75ed

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

test/network/ssl_test.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include <pqxx/pqxx> /* libpqxx is used to instantiate C++ client */
1314
#include "common/harness.h"
14-
#include "gtest/gtest.h"
1515
#include "common/logger.h"
16+
#include "gtest/gtest.h"
17+
#include "network/connection_handle_factory.h"
1618
#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 */
2019
#include "network/postgres_protocol_handler.h"
20+
#include "network/protocol_handler_factory.h"
2121
#include "peloton_config.h"
22-
#include "network/connection_handle_factory.h"
22+
#include "util/string_util.h"
2323

2424
#define NUM_THREADS 1
2525

@@ -32,22 +32,34 @@ namespace test {
3232

3333
class SSLTests : public PelotonTest {};
3434

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+
3542
/**
3643
* Basic SSL connection test: Tested with valid certificats and key files
3744
*/
3845
void *BasicTest(int port) {
3946
try {
4047
// forcing the factory to generate psql protocol handler
4148
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+
4353
pqxx::work txn1(C);
4454

4555
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();
4859

4960
network::PostgresProtocolHandler *handler =
50-
dynamic_cast<network::PostgresProtocolHandler *>(conn->GetProtocolHandler().get());
61+
dynamic_cast<network::PostgresProtocolHandler *>(
62+
conn->GetProtocolHandler().get());
5163
EXPECT_NE(handler, nullptr);
5264

5365
// basic test
@@ -63,7 +75,7 @@ void *BasicTest(int port) {
6375

6476
pqxx::result R = txn2.exec("SELECT name FROM employee where id=1;");
6577
txn2.commit();
66-
78+
6779
EXPECT_EQ(R.size(), 1);
6880

6981
// SSL large write test
@@ -104,16 +116,13 @@ TEST_F(SSLTests, BasicTest) {
104116
peloton::network::PelotonServer peloton_server;
105117
int port = 15721;
106118
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();
117126
} catch (peloton::ConnectionException &exception) {
118127
LOG_INFO("[LaunchServer] exception in thread");
119128
}

0 commit comments

Comments
 (0)