THRIFT-2655 CPP tests should not use relative path when accessing ssh related files
diff --git a/test/cpp/src/TestClient.cpp b/test/cpp/src/TestClient.cpp
index 7a783d2..8c97dc0 100755
--- a/test/cpp/src/TestClient.cpp
+++ b/test/cpp/src/TestClient.cpp
@@ -33,6 +33,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/program_options.hpp>
+#include <boost/filesystem.hpp>
#include <thrift/cxxfunctional.h>
#if _WIN32
#include <thrift/windows/TWinsockSingleton.h>
@@ -47,6 +48,9 @@
using namespace thrift::test;
using namespace apache::thrift::async;
+// Length of argv[0] - Length of script dir
+#define EXECUTABLE_FILE_NAME_LENGTH 19
+
//extern uint32_t g_socket_syscalls;
// Current time, microseconds since the epoch
@@ -92,6 +96,8 @@
}
int main(int argc, char** argv) {
+ string file_path = boost::filesystem::system_complete(argv[0]).string();
+ string dir_path = file_path.substr(0, file_path.size()-EXECUTABLE_FILE_NAME_LENGTH);
#if _WIN32
transport::TWinsockSingleton::create();
#endif
@@ -155,7 +161,7 @@
if (vm.count("ssl")) {
ssl = true;
}
-
+
if (vm.count("noinsane")) {
noinsane = true;
}
@@ -169,7 +175,7 @@
if (ssl) {
factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
- factory->loadTrustedCertificates("keys/CA.pem");
+ factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str());
factory->authenticate(true);
socket = factory->createSocket(host, port);
} else {
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 7a16314..a343221 100755
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -45,6 +45,7 @@
#include <sstream>
#include <boost/program_options.hpp>
+#include <boost/filesystem.hpp>
#include <thrift/cxxfunctional.h>
#include <signal.h>
@@ -63,6 +64,9 @@
using namespace thrift::test;
+// Length of argv[0] - Length of script dir
+#define EXECUTABLE_FILE_NAME_LENGTH 19
+
class TestHandler : public ThriftTestIf {
public:
TestHandler() {}
@@ -494,7 +498,11 @@
int main(int argc, char **argv) {
-#if _WIN32
+
+ string file_path = boost::filesystem::system_complete(argv[0]).string();
+ string dir_path = file_path.substr(0, file_path.size()-EXECUTABLE_FILE_NAME_LENGTH);
+
+ #if _WIN32
transport::TWinsockSingleton::create();
#endif
int port = 9090;
@@ -600,8 +608,8 @@
if (ssl) {
sslSocketFactory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
- sslSocketFactory->loadCertificate("keys/server.crt");
- sslSocketFactory->loadPrivateKey("keys/server.key");
+ sslSocketFactory->loadCertificate((dir_path + "../keys/server.crt").c_str());
+ sslSocketFactory->loadPrivateKey((dir_path + "../keys/server.key").c_str());
sslSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
serverSocket = boost::shared_ptr<TServerSocket>(new TSSLServerSocket(port, sslSocketFactory));
} else {