Copilot commented on code in PR #3630:
URL: https://github.com/apache/thrift/pull/3630#discussion_r3564396332


##########
test/cpp/src/TestClient.cpp:
##########
@@ -204,10 +204,17 @@ BOOST_CONSTEXPR_OR_CONST int ERR_UNKNOWN = 64;
 int main(int argc, char** argv) {
   cout.precision(19);
 
-  string testDir  = 
boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
-  string caPath   = testDir + "/keys/CA.pem";
-  string certPath = testDir + "/keys/client.crt";
-  string keyPath  = testDir + "/keys/client.key";
+  boost::filesystem::path testDir = 
boost::filesystem::system_complete(argv[0]).parent_path();
+  while (!boost::filesystem::exists(testDir / "keys" / "CA.pem")) {
+    boost::filesystem::path parent = testDir.parent_path();
+    if (parent == testDir) {
+      throw runtime_error("Unable to locate test/keys from " + 
string(argv[0]));
+    }
+    testDir = parent;

Review Comment:
   The key-directory search throws an exception before any argument 
parsing/validation. If the keys directory can’t be found (even when TLS isn’t 
requested), the process will terminate via an uncaught exception instead of 
returning a normal failure code.



##########
test/cpp/src/TestServer.cpp:
##########
@@ -623,9 +623,16 @@ namespace po = boost::program_options;
 
 int main(int argc, char** argv) {
 
-  string testDir = 
boost::filesystem::system_complete(argv[0]).parent_path().parent_path().parent_path().string();
-  string certPath = testDir + "/keys/server.crt";
-  string keyPath = testDir + "/keys/server.key";
+  boost::filesystem::path testDir = 
boost::filesystem::system_complete(argv[0]).parent_path();
+  while (!boost::filesystem::exists(testDir / "keys" / "server.crt")) {
+    boost::filesystem::path parent = testDir.parent_path();
+    if (parent == testDir) {
+      throw runtime_error("Unable to locate test/keys from " + 
string(argv[0]));
+    }
+    testDir = parent;

Review Comment:
   The key-directory search throws an exception before any argument 
parsing/validation. If the keys directory can’t be found (even when TLS isn’t 
requested), the process will terminate via an uncaught exception instead of 
returning a normal failure code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to