From b0e569a8f89efb8f40d3ade0b685178521ec2c8b Mon Sep 17 00:00:00 2001 From: Stefano Bonicatti Date: Sat, 19 Oct 2024 12:09:47 +0200 Subject: [PATCH] Check that the server is actually ready to serve http --- osquery/remote/tests/test_utils.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/osquery/remote/tests/test_utils.cpp b/osquery/remote/tests/test_utils.cpp index 4643060ff23..cf9130c0875 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,25 @@ 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; + 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; + } + } + unsetClientConfig(); return true; }