From 6932d0dd4f3fa19dd17e4312e35e52832b8b4d58 Mon Sep 17 00:00:00 2001 From: Gabor Gyimesi Date: Mon, 10 Feb 2025 17:17:01 +0100 Subject: [PATCH 1/2] MINIFICPP-2475: Fix CivetWeb build dependencies --- CMakeLists.txt | 2 +- cmake/CivetWeb.cmake | 3 + extensions/civetweb/CMakeLists.txt | 2 +- .../civetweb/tests}/C2VerifyServeResults.cpp | 0 extensions/civetweb/tests/CMakeLists.txt | 4 +- .../tests}/HttpPostIntegrationTest.cpp | 3 - extensions/elasticsearch/tests/CMakeLists.txt | 7 +- extensions/grafana-loki/tests/CMakeLists.txt | 7 +- extensions/splunk/tests/CMakeLists.txt | 7 +- .../standard-processors/tests/CMakeLists.txt | 4 +- .../tests/integration/InvokeHTTPTests.cpp | 128 ++++++++++-------- .../test/integration/C2NullConfiguration.cpp | 2 - .../integration/C2VerifyHeartbeatAndStop.cpp | 2 - .../C2VerifyLightweightHeartbeatAndStop.cpp | 2 - ...C2VerifyResourceConsumptionInHeartbeat.cpp | 2 - libminifi/test/integration/CMakeLists.txt | 2 +- libminifi/test/libtest/CMakeLists.txt | 6 + .../test/libtest/integration/CMakeLists.txt | 4 +- libminifi/test/unit/CertificateUtilsTests.cpp | 4 +- 19 files changed, 102 insertions(+), 89 deletions(-) rename {libminifi/test/integration => extensions/civetweb/tests}/C2VerifyServeResults.cpp (100%) rename {libminifi/test/integration => extensions/civetweb/tests}/HttpPostIntegrationTest.cpp (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c1cc6a6019..94835dc0b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -350,7 +350,7 @@ if (ENABLE_ALL OR ENABLE_AZURE) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/libxml2/dummy") endif() -if (ENABLE_ALL OR ENABLE_PROMETHEUS OR ENABLE_CIVET) +if (ENABLE_ALL OR ENABLE_PROMETHEUS OR ENABLE_GRAFANA_LOKI OR ENABLE_CIVET) include(GetCivetWeb) get_civetweb() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/civetweb/dummy") diff --git a/cmake/CivetWeb.cmake b/cmake/CivetWeb.cmake index 7ab39e9a89..612b27c737 100644 --- a/cmake/CivetWeb.cmake +++ b/cmake/CivetWeb.cmake @@ -43,3 +43,6 @@ target_compile_definitions(civetweb-c-library PRIVATE SOCKET_TIMEOUT_QUANTUM=200 add_library(civetweb::c-library ALIAS civetweb-c-library) add_library(civetweb::civetweb-cpp ALIAS civetweb-cpp) + +set(CIVETWEB_INCLUDE_DIR "${civetweb_SOURCE_DIR}/include") +set(CIVETWEB_INCLUDE_DIRS "${CIVETWEB_INCLUDE_DIR}") diff --git a/extensions/civetweb/CMakeLists.txt b/extensions/civetweb/CMakeLists.txt index c6f45d280c..eb7e5f30da 100644 --- a/extensions/civetweb/CMakeLists.txt +++ b/extensions/civetweb/CMakeLists.txt @@ -30,7 +30,7 @@ target_include_directories(minifi-civet-extensions BEFORE PUBLIC ${CMAKE_SOURCE_DIR}/libminifi/include ${CMAKE_SOURCE_DIR}/libminifi/include/core ${CMAKE_SOURCE_DIR}/thirdparty/ - ${civetweb_SOURCE_DIR}/include + ${CIVETWEB_INCLUDE_DIRS}/include ./include) target_link_libraries(minifi-civet-extensions ${LIBMINIFI} Threads::Threads civetweb::civetweb-cpp) diff --git a/libminifi/test/integration/C2VerifyServeResults.cpp b/extensions/civetweb/tests/C2VerifyServeResults.cpp similarity index 100% rename from libminifi/test/integration/C2VerifyServeResults.cpp rename to extensions/civetweb/tests/C2VerifyServeResults.cpp diff --git a/extensions/civetweb/tests/CMakeLists.txt b/extensions/civetweb/tests/CMakeLists.txt index 6d9ad431a2..c4041361e4 100644 --- a/extensions/civetweb/tests/CMakeLists.txt +++ b/extensions/civetweb/tests/CMakeLists.txt @@ -27,8 +27,9 @@ FOREACH(testfile ${CIVETWEB_INTEGRATION_TESTS}) target_link_libraries(${testfilename} minifi-civet-extensions) target_link_libraries(${testfilename} minifi-standard-processors) + target_compile_definitions(${testfilename} PRIVATE TEST_RESOURCES="${TEST_RESOURCES}") - createTests("${testfilename}") + createIntegrationTests("${testfilename}") target_link_libraries(${testfilename} Catch2WithMain) MATH(EXPR CIVETWEB-EXTENSIONS_TEST_COUNT "${CIVETWEB-EXTENSIONS_TEST_COUNT}+1") add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR}) @@ -42,4 +43,5 @@ FOREACH(testfile ${CIVETWEB_INTEGRATION_TESTS}) ) set_tests_properties("${testfilename}" PROPERTIES LABELS "civetweb") ENDFOREACH() + message("-- Finished building ${CIVETWEB-EXTENSIONS_TEST_COUNT} civetweb related test file(s)...") diff --git a/libminifi/test/integration/HttpPostIntegrationTest.cpp b/extensions/civetweb/tests/HttpPostIntegrationTest.cpp similarity index 94% rename from libminifi/test/integration/HttpPostIntegrationTest.cpp rename to extensions/civetweb/tests/HttpPostIntegrationTest.cpp index b07b8e0c26..601b19d96d 100644 --- a/libminifi/test/integration/HttpPostIntegrationTest.cpp +++ b/extensions/civetweb/tests/HttpPostIntegrationTest.cpp @@ -19,7 +19,6 @@ #include #include #include "processors/InvokeHTTP.h" -#include "processors/ListenHTTP.h" #include "processors/LogAttribute.h" #include "unit/TestBase.h" #include "core/logging/Logger.h" @@ -47,8 +46,6 @@ class HttpTestHarness : public HTTPIntegrationBase { LogTestController::getInstance().setDebug(); LogTestController::getInstance().setTrace(); LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); diff --git a/extensions/elasticsearch/tests/CMakeLists.txt b/extensions/elasticsearch/tests/CMakeLists.txt index 6fbd8b07b0..a39986de8e 100644 --- a/extensions/elasticsearch/tests/CMakeLists.txt +++ b/extensions/elasticsearch/tests/CMakeLists.txt @@ -25,13 +25,10 @@ FOREACH(testfile ${ELASTICSEARCH_TESTS}) add_minifi_executable("${testfilename}" "${testfile}") target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/elasticsearch") - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") createTests("${testfilename}") - target_link_libraries(${testfilename} Catch2WithMain) - target_link_libraries(${testfilename} minifi-elasticsearch) - target_link_libraries(${testfilename} minifi-civet-extensions) - target_link_libraries(${testfilename} minifi-standard-processors) + target_link_libraries(${testfilename} Catch2WithMain civetweb::civetweb-cpp minifi-elasticsearch minifi-standard-processors) MATH(EXPR ELASTICSEARCH_TEST_COUNT "${ELASTICSEARCH_TEST_COUNT}+1") add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR}) set_tests_properties("${testfilename}" PROPERTIES LABELS "elasticsearch;memchecked") diff --git a/extensions/grafana-loki/tests/CMakeLists.txt b/extensions/grafana-loki/tests/CMakeLists.txt index 8c17383585..b9764ebea7 100644 --- a/extensions/grafana-loki/tests/CMakeLists.txt +++ b/extensions/grafana-loki/tests/CMakeLists.txt @@ -31,13 +31,10 @@ FOREACH(testfile ${GRAFANA_LOKI_TESTS}) if (ENABLE_GRPC_FOR_LOKI) target_include_directories(${testfilename} SYSTEM PRIVATE BEFORE "${CMAKE_BINARY_DIR}/grafana-loki-protobuf-generated") endif() - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") createTests("${testfilename}") - target_link_libraries(${testfilename} Catch2WithMain) - target_link_libraries(${testfilename} minifi-grafana-loki) - target_link_libraries(${testfilename} minifi-civet-extensions) - target_link_libraries(${testfilename} minifi-standard-processors) + target_link_libraries(${testfilename} Catch2WithMain civetweb::civetweb-cpp minifi-grafana-loki minifi-standard-processors) MATH(EXPR GRAFANA_LOKI_TEST_COUNT "${GRAFANA_LOKI_TEST_COUNT}+1") add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR}) set_tests_properties("${testfilename}" PROPERTIES LABELS "grafana-loki;memchecked") diff --git a/extensions/splunk/tests/CMakeLists.txt b/extensions/splunk/tests/CMakeLists.txt index f00d2740b4..24849389da 100644 --- a/extensions/splunk/tests/CMakeLists.txt +++ b/extensions/splunk/tests/CMakeLists.txt @@ -25,13 +25,10 @@ FOREACH(testfile ${SPLUNK_TESTS}) add_minifi_executable("${testfilename}" "${testfile}") target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/standard-processors") target_include_directories(${testfilename} PRIVATE BEFORE "${CMAKE_SOURCE_DIR}/extensions/splunk") - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") createTests("${testfilename}") - target_link_libraries(${testfilename} Catch2WithMain) - target_link_libraries(${testfilename} minifi-splunk) - target_link_libraries(${testfilename} minifi-civet-extensions) - target_link_libraries(${testfilename} minifi-standard-processors) + target_link_libraries(${testfilename} Catch2WithMain civetweb::civetweb-cpp minifi-splunk minifi-standard-processors) MATH(EXPR SPLUNK_TEST_COUNT "${SPLUNK_TEST_COUNT}+1") add_test(NAME "${testfilename}" COMMAND "${testfilename}" WORKING_DIRECTORY ${TEST_DIR}) ENDFOREACH() diff --git a/extensions/standard-processors/tests/CMakeLists.txt b/extensions/standard-processors/tests/CMakeLists.txt index 4eff161456..edef43a466 100644 --- a/extensions/standard-processors/tests/CMakeLists.txt +++ b/extensions/standard-processors/tests/CMakeLists.txt @@ -33,7 +33,7 @@ FOREACH(testfile ${PROCESSOR_UNIT_TESTS}) target_include_directories(${testfilename} BEFORE PRIVATE "../") target_include_directories(${testfilename} BEFORE PRIVATE "../processors") target_include_directories(${testfilename} BEFORE PRIVATE ./include) - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/expression-language/") createTests("${testfilename}") target_link_libraries(${testfilename} Catch2WithMain) @@ -62,7 +62,7 @@ FOREACH(testfile ${PROCESSOR_INTEGRATION_TESTS}) target_include_directories(${testfilename} BEFORE PRIVATE "../http/") target_include_directories(${testfilename} BEFORE PRIVATE "../protocols/") target_include_directories(${testfilename} BEFORE PRIVATE "../sitetosite/") - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") target_include_directories(${testfilename} BEFORE PRIVATE ./include) createIntegrationTests("${testfilename}") target_link_libraries(${testfilename}) diff --git a/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp b/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp index b0872b8a12..2d884565ca 100644 --- a/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp +++ b/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp @@ -18,12 +18,12 @@ #include #include #include +#include #include "unit/TestBase.h" #include "unit/Catch.h" #include "core/Core.h" #include "http/HTTPClient.h" #include "InvokeHTTP.h" -#include "processors/ListenHTTP.h" #include "core/FlowFile.h" #include "unit/ProvenanceTestHelper.h" #include "core/Processor.h" @@ -34,61 +34,66 @@ #include "unit/SingleProcessorTestController.h" #include "integration/ConnectionCountingServer.h" #include "unit/TestUtils.h" +#include "integration/TestServer.h" +#include "utils/StringUtils.h" namespace org::apache::nifi::minifi::test { +class TestHandler : public CivetHandler { + public: + bool handleGet(CivetServer*, struct mg_connection* conn) override { + headers_.clear(); + auto req_info = mg_get_request_info(conn); + for (int i = 0; i < req_info->num_headers; ++i) { + auto header = &req_info->http_headers[i]; + headers_[std::string(header->name)] = std::string(header->value); + } + mg_printf(conn, "HTTP/1.1 200 OK\r\n"); + return true; + } + + [[nodiscard]] const std::unordered_map& getHeaders() const { + return headers_; + } + + private: + std::unordered_map headers_; +}; + class TestHTTPServer { public: - explicit TestHTTPServer(TestController& test_controller) { - LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); - - test_plan_ = test_controller.createPlan(); - - listen_http_ = dynamic_cast(test_plan_->addProcessor("ListenHTTP", PROCESSOR_NAME)); - log_attribute_ = dynamic_cast(test_plan_->addProcessor("LogAttribute", "LogAttribute", core::Relationship("success", "description"), true)); - REQUIRE(listen_http_); - REQUIRE(log_attribute_); - test_plan_->setProperty(listen_http_, org::apache::nifi::minifi::processors::ListenHTTP::BasePath, "testytesttest"); - test_plan_->setProperty(listen_http_, org::apache::nifi::minifi::processors::ListenHTTP::Port, "8681"); - test_plan_->setProperty(listen_http_, org::apache::nifi::minifi::processors::ListenHTTP::HeadersAsAttributesRegex, ".*"); - test_plan_->runProcessor(listen_http_); - test_plan_->runProcessor(log_attribute_); - thread_ = std::thread{[this] { - while (running_) { - if (listen_http_->isWorkAvailable()) { - test_plan_->runProcessor(listen_http_); - test_plan_->runProcessor(log_attribute_); - } - } - }}; + TestHTTPServer() : server_(std::make_unique("8681", "/testytesttest", &handler_)) { } TestHTTPServer(const TestHTTPServer&) = delete; TestHTTPServer(TestHTTPServer&&) = delete; TestHTTPServer& operator=(const TestHTTPServer&) = delete; TestHTTPServer& operator=(TestHTTPServer&&) = delete; + ~TestHTTPServer() = default; - static constexpr const char* PROCESSOR_NAME = "my_http_server"; static constexpr const char* URL = "http://localhost:8681/testytesttest"; - ~TestHTTPServer() { - running_ = false; - thread_.join(); + [[nodiscard]] const std::unordered_map& getHeaders() const { + return handler_.getHeaders(); + } + + [[nodiscard]] std::vector getHeaderKeys() const { + std::vector keys; + for (const auto& [key, _] : handler_.getHeaders()) { + keys.push_back(key); + } + return keys; } private: - processors::ListenHTTP* listen_http_ = nullptr; - processors::LogAttribute* log_attribute_ = nullptr; - std::shared_ptr test_plan_; - std::thread thread_; - std::atomic_bool running_{true}; + TestHandler handler_; + std::unique_ptr server_; }; TEST_CASE("HTTPTestsPenalizeNoRetry", "[httptest1]") { using minifi::processors::InvokeHTTP; TestController testController; - TestHTTPServer http_server(testController); + TestHTTPServer http_server; LogTestController::getInstance().setInfo(); @@ -120,7 +125,7 @@ TEST_CASE("InvokeHTTP fails with when flow contains invalid attribute names in H test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setDebug(); @@ -133,6 +138,7 @@ TEST_CASE("InvokeHTTP fails with when flow contains invalid attribute names in H auto file_contents = result.at(InvokeHTTP::RelFailure); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); + REQUIRE(http_server.getHeaders().empty()); } TEST_CASE("InvokeHTTP succeeds when the flow file contains an attribute that would be invalid as an HTTP header, and the policy is FAIL, but the attribute is not matched", @@ -141,7 +147,7 @@ TEST_CASE("InvokeHTTP succeeds when the flow file contains an attribute that wou test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setDebug(); @@ -154,8 +160,11 @@ TEST_CASE("InvokeHTTP succeeds when the flow file contains an attribute that wou REQUIRE(result.at(InvokeHTTP::RelFailure).empty()); const auto& success_contents = result.at(InvokeHTTP::Success); REQUIRE(success_contents.size() == 1); - REQUIRE(utils::verifyLogLinePresenceInPollTime(1s, "key:valid-header value:value2")); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:invalid")); + REQUIRE(http_server.getHeaders().at("valid-header") == "value2"); + auto header_keys = http_server.getHeaderKeys(); + REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { + return minifi::utils::string::startsWith(key, "invalid"); + }) == header_keys.end()); } TEST_CASE("InvokeHTTP replaces invalid characters of attributes", "[httptest1]") { @@ -163,7 +172,7 @@ TEST_CASE("InvokeHTTP replaces invalid characters of attributes", "[httptest1]") test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setTrace(); @@ -175,8 +184,8 @@ TEST_CASE("InvokeHTTP replaces invalid characters of attributes", "[httptest1]") auto file_contents = result.at(InvokeHTTP::Success); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); - REQUIRE(utils::verifyLogLinePresenceInPollTime(1s, "key:invalid-header value:value")); - REQUIRE(utils::verifyLogLinePresenceInPollTime(1s, "key:X-MiNiFi-Empty-Attribute-Name value:value2")); + REQUIRE(http_server.getHeaders().at("invalid-header") == "value"); + REQUIRE(http_server.getHeaders().at("X-MiNiFi-Empty-Attribute-Name") == "value2"); } TEST_CASE("InvokeHTTP drops invalid attributes from HTTP headers", "[httptest1]") { @@ -184,7 +193,7 @@ TEST_CASE("InvokeHTTP drops invalid attributes from HTTP headers", "[httptest1]" test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setTrace(); @@ -197,8 +206,11 @@ TEST_CASE("InvokeHTTP drops invalid attributes from HTTP headers", "[httptest1]" auto file_contents = result.at(InvokeHTTP::Success); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); - REQUIRE(utils::verifyLogLinePresenceInPollTime(1s, "key:legit-header value:value1")); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:invalid", 0s)); + REQUIRE(http_server.getHeaders().at("legit-header") == "value1"); + auto header_keys = http_server.getHeaderKeys(); + REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { + return minifi::utils::string::startsWith(key, "invalid"); + }) == header_keys.end()); } TEST_CASE("InvokeHTTP empty Attributes to Send means no attributes are sent", "[httptest1]") { @@ -206,7 +218,7 @@ TEST_CASE("InvokeHTTP empty Attributes to Send means no attributes are sent", "[ test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setTrace(); @@ -219,8 +231,11 @@ TEST_CASE("InvokeHTTP empty Attributes to Send means no attributes are sent", "[ auto file_contents = result.at(InvokeHTTP::Success); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:legit-header value:value1")); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:invalid", 0s)); + auto header_keys = http_server.getHeaderKeys(); + REQUIRE_FALSE(http_server.getHeaders().contains("legit-header")); + REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { + return minifi::utils::string::startsWith(key, "invalid"); + }) == header_keys.end()); } TEST_CASE("InvokeHTTP DateHeader", "[InvokeHTTP]") { @@ -228,7 +243,7 @@ TEST_CASE("InvokeHTTP DateHeader", "[InvokeHTTP]") { test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invoke_http = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setTrace(); @@ -250,7 +265,11 @@ TEST_CASE("InvokeHTTP DateHeader", "[InvokeHTTP]") { auto file_contents = result.at(InvokeHTTP::Success); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); - REQUIRE(utils::verifyEventHappenedInPollTime(1s, [&] {return LogTestController::getInstance().contains("key:Date", 0ms) == date_header;})); + if (date_header) { + REQUIRE(http_server.getHeaders().contains("Date")); + } else { + REQUIRE_FALSE(http_server.getHeaders().contains("Date")); + } } TEST_CASE("InvokeHTTP Attributes to Send uses full string matching, not substring", "[httptest1]") { @@ -258,7 +277,7 @@ TEST_CASE("InvokeHTTP Attributes to Send uses full string matching, not substrin test::SingleProcessorTestController test_controller{std::make_unique("InvokeHTTP")}; auto invokehttp = test_controller.getProcessor(); - TestHTTPServer http_server(test_controller); + TestHTTPServer http_server; LogTestController::getInstance().setTrace(); @@ -271,9 +290,12 @@ TEST_CASE("InvokeHTTP Attributes to Send uses full string matching, not substrin auto file_contents = result.at(InvokeHTTP::Success); REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); - REQUIRE(utils::verifyLogLinePresenceInPollTime(1s, "key:header value:value2")); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:header1 value:value1")); - REQUIRE_FALSE(LogTestController::getInstance().contains("key:invalid", 0s)); + REQUIRE(http_server.getHeaders().at("header") == "value2"); + REQUIRE_FALSE(http_server.getHeaders().contains("header1")); + auto header_keys = http_server.getHeaderKeys(); + REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { + return minifi::utils::string::startsWith(key, "invalid"); + }) == header_keys.end()); } TEST_CASE("HTTPTestsResponseBodyinAttribute", "[InvokeHTTP]") { diff --git a/libminifi/test/integration/C2NullConfiguration.cpp b/libminifi/test/integration/C2NullConfiguration.cpp index 5b1ee626db..b10df8b863 100644 --- a/libminifi/test/integration/C2NullConfiguration.cpp +++ b/libminifi/test/integration/C2NullConfiguration.cpp @@ -23,7 +23,6 @@ #include "core/logging/Logger.h" #include "core/ProcessGroup.h" #include "integration/TestServer.h" -#include "protocols/RESTReceiver.h" #include "c2/C2Agent.h" #include "processors/LogAttribute.h" #include "integration/HTTPIntegrationBase.h" @@ -42,7 +41,6 @@ class VerifyC2Server : public HTTPIntegrationBase { void testSetup() override { LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); diff --git a/libminifi/test/integration/C2VerifyHeartbeatAndStop.cpp b/libminifi/test/integration/C2VerifyHeartbeatAndStop.cpp index 3eb4eb7101..700e02e75c 100644 --- a/libminifi/test/integration/C2VerifyHeartbeatAndStop.cpp +++ b/libminifi/test/integration/C2VerifyHeartbeatAndStop.cpp @@ -19,7 +19,6 @@ #include "c2/C2Agent.h" #include "protocols/RESTProtocol.h" #include "protocols/RESTSender.h" -#include "protocols/RESTReceiver.h" #include "integration/HTTPIntegrationBase.h" #include "integration/HTTPHandlers.h" #include "unit/TestUtils.h" @@ -34,7 +33,6 @@ class VerifyC2Heartbeat : public VerifyC2Base { LogTestController::getInstance().setTrace(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); VerifyC2Base::testSetup(); } diff --git a/libminifi/test/integration/C2VerifyLightweightHeartbeatAndStop.cpp b/libminifi/test/integration/C2VerifyLightweightHeartbeatAndStop.cpp index dae07f1fed..aa26ce5248 100644 --- a/libminifi/test/integration/C2VerifyLightweightHeartbeatAndStop.cpp +++ b/libminifi/test/integration/C2VerifyLightweightHeartbeatAndStop.cpp @@ -21,7 +21,6 @@ #include "c2/C2Agent.h" #include "protocols/RESTProtocol.h" #include "protocols/RESTSender.h" -#include "protocols/RESTReceiver.h" #include "integration/HTTPIntegrationBase.h" #include "integration/HTTPHandlers.h" #include "unit/TestUtils.h" @@ -58,7 +57,6 @@ class VerifyLightWeightC2Heartbeat : public VerifyC2Base { LogTestController::getInstance().setTrace(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); VerifyC2Base::testSetup(); } diff --git a/libminifi/test/integration/C2VerifyResourceConsumptionInHeartbeat.cpp b/libminifi/test/integration/C2VerifyResourceConsumptionInHeartbeat.cpp index bda77d6f86..37e1f07de8 100644 --- a/libminifi/test/integration/C2VerifyResourceConsumptionInHeartbeat.cpp +++ b/libminifi/test/integration/C2VerifyResourceConsumptionInHeartbeat.cpp @@ -22,7 +22,6 @@ #include "c2/C2Agent.h" #include "protocols/RESTProtocol.h" #include "protocols/RESTSender.h" -#include "protocols/RESTReceiver.h" #include "integration/HTTPIntegrationBase.h" #include "integration/HTTPHandlers.h" #include "unit/TestUtils.h" @@ -111,7 +110,6 @@ class VerifyResourceConsumptionInHeartbeat : public VerifyC2Base { LogTestController::getInstance().setTrace(); LogTestController::getInstance().setDebug(); LogTestController::getInstance().setDebug(); - LogTestController::getInstance().setDebug(); VerifyC2Base::testSetup(); } diff --git a/libminifi/test/integration/CMakeLists.txt b/libminifi/test/integration/CMakeLists.txt index bd7bf697ad..3fb3fd88a2 100644 --- a/libminifi/test/integration/CMakeLists.txt +++ b/libminifi/test/integration/CMakeLists.txt @@ -25,7 +25,7 @@ FOREACH(testfile ${INTEGRATION_TESTS}) get_filename_component(testfilename "${testfile}" NAME_WE) add_minifi_executable("${testfilename}" "${TEST_DIR}/integration/${testfile}") createIntegrationTests("${testfilename}") - target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") + target_include_directories(${testfilename} BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") target_include_directories(${testfilename} BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/standard-processors/") target_link_libraries(${testfilename} minifi-standard-processors) target_link_libraries(${testfilename} Catch2WithMain Threads::Threads) diff --git a/libminifi/test/libtest/CMakeLists.txt b/libminifi/test/libtest/CMakeLists.txt index 95ab353f73..a186b9c697 100644 --- a/libminifi/test/libtest/CMakeLists.txt +++ b/libminifi/test/libtest/CMakeLists.txt @@ -16,5 +16,11 @@ # specific language governing permissions and limitations # under the License. # +if (NOT ENABLE_ALL AND NOT ENABLE_PROMETHEUS AND NOT ENABLE_GRAFANA_LOKI AND NOT ENABLE_CIVET) + message("CivetWeb was disabled for MiNiFi, but will be enabled for tests") + include(GetCivetWeb) + get_civetweb() +endif() + add_subdirectory(unit) add_subdirectory(integration) diff --git a/libminifi/test/libtest/integration/CMakeLists.txt b/libminifi/test/libtest/integration/CMakeLists.txt index 7225eb4b2e..dabf16203d 100644 --- a/libminifi/test/libtest/integration/CMakeLists.txt +++ b/libminifi/test/libtest/integration/CMakeLists.txt @@ -18,6 +18,6 @@ # file(GLOB SOURCES "*.cpp") add_minifi_library(libminifi-integrationtest STATIC ${SOURCES}) -target_link_libraries(libminifi-integrationtest libminifi-unittest minifi-civet-extensions) +target_link_libraries(libminifi-integrationtest libminifi-unittest civetweb::civetweb-cpp) target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/libminifi/include/" "${CMAKE_SOURCE_DIR}/libminifi/test/libtest/") -target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CMAKE_SOURCE_DIR}/extensions/civetweb/") +target_include_directories(libminifi-integrationtest BEFORE PRIVATE "${CIVETWEB_INCLUDE_DIRS}") diff --git a/libminifi/test/unit/CertificateUtilsTests.cpp b/libminifi/test/unit/CertificateUtilsTests.cpp index 912eebb07a..3700a75136 100644 --- a/libminifi/test/unit/CertificateUtilsTests.cpp +++ b/libminifi/test/unit/CertificateUtilsTests.cpp @@ -30,12 +30,12 @@ TEST_CASE("getCertificateExpiration() works correctly") { using namespace std::literals::chrono_literals; const auto executable_dir = utils::file::get_executable_dir(); - const auto cert_location = executable_dir / "resources" / "goodCA.crt"; + const auto cert_location = executable_dir / "resources" / "ca_A.crt"; size_t num_times_called = 0; utils::tls::processPEMCertificate(cert_location, {}, {[&](utils::tls::X509_unique_ptr cert) { ++num_times_called; - CHECK(utils::tls::getCertificateExpiration(cert) == date::sys_days(date::year_month_day(2053_y / 4 / 30)) + 9h + 3min); + CHECK(utils::tls::getCertificateExpiration(cert) == date::sys_days(date::year_month_day(2033_y / 6 / 26)) + 12h + 26min + 48s); return std::error_code{}; }, {}, {}}); CHECK(num_times_called == 1); From 9aeb9c7418bf723f85bb45c6d2c64a3239a5d236 Mon Sep 17 00:00:00 2001 From: Gabor Gyimesi Date: Wed, 12 Feb 2025 10:32:42 +0100 Subject: [PATCH 2/2] Review update --- cmake/CivetWeb.cmake | 3 +++ .../tests/integration/InvokeHTTPTests.cpp | 26 ++++++++----------- libminifi/test/libtest/CMakeLists.txt | 8 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/cmake/CivetWeb.cmake b/cmake/CivetWeb.cmake index 612b27c737..d2622de1cd 100644 --- a/cmake/CivetWeb.cmake +++ b/cmake/CivetWeb.cmake @@ -14,6 +14,9 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +if(TARGET civetweb::civetweb-cpp) + return() +endif() include(FetchContent) diff --git a/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp b/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp index 2d884565ca..5ff6a576e8 100644 --- a/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp +++ b/extensions/standard-processors/tests/integration/InvokeHTTPTests.cpp @@ -84,6 +84,13 @@ class TestHTTPServer { return keys; } + [[nodiscard]] bool noInvalidHeaderPresent() const { + auto header_keys = getHeaderKeys(); + return std::none_of(header_keys.begin(), header_keys.end(), [] (const auto& key) { + return minifi::utils::string::startsWith(key, "invalid"); + }); + } + private: TestHandler handler_; std::unique_ptr server_; @@ -161,10 +168,7 @@ TEST_CASE("InvokeHTTP succeeds when the flow file contains an attribute that wou const auto& success_contents = result.at(InvokeHTTP::Success); REQUIRE(success_contents.size() == 1); REQUIRE(http_server.getHeaders().at("valid-header") == "value2"); - auto header_keys = http_server.getHeaderKeys(); - REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { - return minifi::utils::string::startsWith(key, "invalid"); - }) == header_keys.end()); + REQUIRE(http_server.noInvalidHeaderPresent()); } TEST_CASE("InvokeHTTP replaces invalid characters of attributes", "[httptest1]") { @@ -207,10 +211,7 @@ TEST_CASE("InvokeHTTP drops invalid attributes from HTTP headers", "[httptest1]" REQUIRE(file_contents.size() == 1); REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); REQUIRE(http_server.getHeaders().at("legit-header") == "value1"); - auto header_keys = http_server.getHeaderKeys(); - REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { - return minifi::utils::string::startsWith(key, "invalid"); - }) == header_keys.end()); + REQUIRE(http_server.noInvalidHeaderPresent()); } TEST_CASE("InvokeHTTP empty Attributes to Send means no attributes are sent", "[httptest1]") { @@ -233,9 +234,7 @@ TEST_CASE("InvokeHTTP empty Attributes to Send means no attributes are sent", "[ REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); auto header_keys = http_server.getHeaderKeys(); REQUIRE_FALSE(http_server.getHeaders().contains("legit-header")); - REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { - return minifi::utils::string::startsWith(key, "invalid"); - }) == header_keys.end()); + REQUIRE(http_server.noInvalidHeaderPresent()); } TEST_CASE("InvokeHTTP DateHeader", "[InvokeHTTP]") { @@ -292,10 +291,7 @@ TEST_CASE("InvokeHTTP Attributes to Send uses full string matching, not substrin REQUIRE(test_controller.plan->getContent(file_contents[0]) == "data"); REQUIRE(http_server.getHeaders().at("header") == "value2"); REQUIRE_FALSE(http_server.getHeaders().contains("header1")); - auto header_keys = http_server.getHeaderKeys(); - REQUIRE(std::find_if(header_keys.begin(), header_keys.end(), [] (const auto& key) { - return minifi::utils::string::startsWith(key, "invalid"); - }) == header_keys.end()); + REQUIRE(http_server.noInvalidHeaderPresent()); } TEST_CASE("HTTPTestsResponseBodyinAttribute", "[InvokeHTTP]") { diff --git a/libminifi/test/libtest/CMakeLists.txt b/libminifi/test/libtest/CMakeLists.txt index a186b9c697..7d5bc957b1 100644 --- a/libminifi/test/libtest/CMakeLists.txt +++ b/libminifi/test/libtest/CMakeLists.txt @@ -16,11 +16,9 @@ # specific language governing permissions and limitations # under the License. # -if (NOT ENABLE_ALL AND NOT ENABLE_PROMETHEUS AND NOT ENABLE_GRAFANA_LOKI AND NOT ENABLE_CIVET) - message("CivetWeb was disabled for MiNiFi, but will be enabled for tests") - include(GetCivetWeb) - get_civetweb() -endif() + +include(GetCivetWeb) +get_civetweb() add_subdirectory(unit) add_subdirectory(integration)