diff --git a/osquery/remote/tests/test_utils.cpp b/osquery/remote/tests/test_utils.cpp index 4643060ff23..fa04818791f 100644 --- a/osquery/remote/tests/test_utils.cpp +++ b/osquery/remote/tests/test_utils.cpp @@ -7,6 +7,7 @@ * SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only) */ +#include "osquery/remote/transports/tls.h" #include #include @@ -18,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -25,8 +28,6 @@ #include #include -namespace fs = boost::filesystem; - namespace osquery { DECLARE_string(tls_hostname); @@ -156,7 +157,35 @@ bool TLSServerRunner::start(const std::string& server_cert, return false; } - LOG(WARNING) << "Python server started correctly"; + LOG(WARNING) << "Python server process started correctly"; + + // Verify that the server is also actually ready to serve + retry = 0; + bool ready_to_serve = false; + setClientConfig(); + while (retry < max_retry) { + std::string ping_server_uri = + "https://localhost:" + std::string(self.port_); + + Request request(ping_server_uri); + Status status = request.call(); + if (!status.ok()) { + LOG(WARNING) << "Python HTTP Server not ready yet: " + << status.getMessage(); + sleepFor(1000); + ++retry; + continue; + } + + ready_to_serve = true; + break; + } + unsetClientConfig(); + + if (!ready_to_serve) { + LOG(ERROR) << "The Python server was not ready to serve in time"; + return false; + } return true; }