]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4341] Made emulate flag static.class
authorFrancis Dupont <fdupont@isc.org>
Sun, 22 Feb 2026 13:30:30 +0000 (14:30 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 7 May 2026 08:15:53 +0000 (10:15 +0200)
14 files changed:
src/lib/config/cmd_response_creator.cc
src/lib/config/cmd_response_creator.h
src/lib/config/cmd_response_creator_factory.h
src/lib/config/http_command_config.cc
src/lib/config/http_command_config.h
src/lib/config/http_command_mgr.cc
src/lib/config/http_command_response_creator.cc
src/lib/config/http_command_response_creator.h
src/lib/config/http_command_response_creator_factory.h
src/lib/config/tests/cmd_response_creator_factory_unittests.cc
src/lib/config/tests/cmd_response_creator_unittests.cc
src/lib/config/tests/http_command_config_unittests.cc
src/lib/config/tests/http_command_response_creator_factory_unittests.cc
src/lib/config/tests/http_command_response_creator_unittests.cc

index e354d5aac646b63aa165a18d7062c719d17406c0..adf54aa9b31cb8c537a6a49994461d42e772c74e 100644 (file)
@@ -27,6 +27,8 @@ HttpAuthConfigPtr CmdResponseCreator::http_auth_config_;
 
 unordered_set<string> CmdResponseCreator::command_accept_list_;
 
+bool CmdResponseCreator::EMULATE_AGENT_RESPONSE = true;
+
 HttpRequestPtr
 CmdResponseCreator::createNewHttpRequest() const {
     return (HttpRequestPtr(new PostHttpRequestJson()));
@@ -112,7 +114,7 @@ CmdResponseCreator::createDynamicHttpResponse(HttpRequestPtr request) {
     // which contain responses from multiple daemons.
     // If we're emulating that for backward compatibility, then we need to wrap
     // the answer in a list if it isn't in one already.
-    if (emulateAgentResponse() && (response->getType() != Element::list)) {
+    if (EMULATE_AGENT_RESPONSE && (response->getType() != Element::list)) {
         ElementPtr response_list = Element::createList();
         response_list->add(boost::const_pointer_cast<Element>(response));
         response = response_list;
index bd29cbecd027d18fc41cc2ab1016c18b45d7a114..70703afd9dd3fef72490527a166a699360233588 100644 (file)
@@ -32,14 +32,6 @@ namespace config {
 class CmdResponseCreator : public http::HttpResponseCreator {
 public:
 
-    /// @brief Constructor
-    ///
-    /// @param emulate_agent_response if true, responses for normal
-    /// command outcomes are guaranteed to be wrapped in an Element::list.
-    /// This allows backward compatibility.  Defaults to true.
-    CmdResponseCreator(bool emulate_agent_response = true)
-    : emulate_agent_response_(emulate_agent_response) {};
-
     /// @brief Create a new request.
     ///
     /// This method creates a bare instance of the @ref
@@ -59,13 +51,6 @@ public:
     createStockHttpResponse(const http::HttpRequestPtr& request,
                             const http::HttpStatusCode& status_code) const;
 
-    /// @brief Indicates whether or not agent response emulation is enabled.
-    ///
-    /// @return true if emulation is enabled.
-    bool emulateAgentResponse() {
-        return (emulate_agent_response_);
-    }
-
     /// @brief Filter commands.
     ///
     /// From RBAC code: if the access list is empty or the command
@@ -93,6 +78,9 @@ public:
     /// Default to the empty list which means to accept everything.
     static std::unordered_set<std::string> command_accept_list_;
 
+    /// @brief The emulate agent response flag.
+    static bool EMULATE_AGENT_RESPONSE;
+
 private:
 
     /// @brief Creates un-finalized stock HTTP response.
@@ -115,12 +103,6 @@ private:
     /// @return Pointer to an object representing HTTP response.
     virtual http::HttpResponsePtr
     createDynamicHttpResponse(http::HttpRequestPtr request);
-
-    /// @brief Determines whether or not responses are enclosed in an Element::list.
-    /// For backward compatibility we need to wrap all responses in a list
-    /// of one element. If this is true, we'll ensure
-    /// responses (other than error responses) are in a list.
-    bool emulate_agent_response_;
 };
 
 /// @brief Pointer to the @ref CmdResponseCreator.
index 3961343ec711b1fad4c0e559993b84695253a9b7..d55d172d5c2f58d8502a5b76cf2f7fd3d01097c4 100644 (file)
@@ -15,11 +15,6 @@ namespace config {
 
 /// @brief HTTP response creator factory for an API listener
 ///
-/// @param emulate_agent_response if true results for normal command
-/// outcomes are wrapped in Element::list.  This allows
-/// backward compatibility. The value is passed into the
-/// CmdResponseCreator when created. Defaults to true.
-///
 /// See the documentation of the @ref isc::http::HttpResponseCreatorFactory
 /// for the details how the response factory object is used by the
 /// @ref isc::http::HttpListener.
@@ -35,12 +30,7 @@ public:
     ///
     /// Creates sole instance of the @ref CmdResponseCreator object
     /// returned by the @ref CmdResponseCreatorFactory::create.
-    ///
-    /// @param emulate_agent_response if true, responses for normal
-    /// command outcomes are guaranteed to be wrapped in an Element::list.
-    /// This allows backward compatibility. Defaults to true.
-    CmdResponseCreatorFactory(bool emulate_agent_response = true)
-        : sole_creator_(new CmdResponseCreator(emulate_agent_response)) {
+    CmdResponseCreatorFactory() : sole_creator_(new CmdResponseCreator) {
     }
 
     /// @brief Returns an instance of the @ref CmdResponseCreator which
index 065abe75922614676fed974e75adbc1b349100fc..478cbf7d5d44d24e09bd7fae08d8fb7cd6a6c467 100644 (file)
@@ -32,11 +32,12 @@ uint16_t HttpCommandConfig::DEFAULT_SOCKET_PORT = 8000;
 
 string HttpCommandConfig::DEFAULT_AUTHENTICATION_REALM = "";
 
+bool HttpCommandConfig::EMULATE_AGENT_RESPONSE = true;
+
 HttpCommandConfig::HttpCommandConfig(ConstElementPtr config)
     : socket_type_("http"), socket_address_(DEFAULT_SOCKET_ADDRESS),
       socket_port_(DEFAULT_SOCKET_PORT), http_headers_(), auth_config_(),
-      trust_anchor_(""), cert_file_(""), key_file_(""), cert_required_(true),
-      emulate_agent_response_(true) {
+      trust_anchor_(""), cert_file_(""), key_file_(""), cert_required_(true) {
     if (config->getType() != Element::map) {
         isc_throw(DhcpConfigError, "expected map type ("
                   << config->getPosition() << ")");
index 160379519f722080c780d7d1cf0e84db3756aa07..a4cc24e4c07b9e2d5f12051eba915ad009437a8a 100644 (file)
@@ -162,22 +162,6 @@ public:
         cert_required_ = required;
     }
 
-    /// @brief Returns emulate agent response flag.
-    ///
-    /// @return True when responses for normal command outcomes are
-    /// guaranteed to be wrapped in an Element::list. This allows
-    /// backward compatibility. Defaults to true.
-    bool getEmulateAgentResponse() const {
-        return (emulate_agent_response_);
-    }
-
-    /// @brief Sets emulate agent response flag.
-    ///
-    /// @param emulate_agent_response The new value of the emulation flag.
-    void setEmulateAgentResponse(const bool emulate_agent_response) {
-        emulate_agent_response_ = emulate_agent_response;
-    }
-
     /// @brief Unparse a configuration object.
     ///
     /// @return A pointer to configuration.
@@ -192,6 +176,9 @@ public:
     /// @brief Default HTTP authentication realm.
     static std::string DEFAULT_AUTHENTICATION_REALM;
 
+    /// @brief Emulation flag.
+    static bool EMULATE_AGENT_RESPONSE;
+
 private:
     /// @brief Check TLS configuration.
     ///
@@ -199,9 +186,9 @@ private:
     /// @return true if TLS parameters are all present, false
     /// otherwise.
     /// @throw DhcpConfigError if socket type is https and
-    /// TLS is missing or incomplete, or if socket type is 
+    /// TLS is missing or incomplete, or if socket type is
     /// http and some TLS parameters are specified but not
-    /// all. 
+    /// all.
     bool checkTlsSetup(bool require_tls) const;
 
     /// @brief Socket type ("http" or "https").
@@ -230,9 +217,6 @@ private:
 
     /// @brief Require client certificates flag.
     bool cert_required_;
-
-    /// @brief Emulation flag.
-    bool emulate_agent_response_;
 };
 
 /// @brief Pointer to a HttpCommandConfig object.
index d45d2f0d120a436cb836a3242dfb8ff74f294209..fb389fb60fc8bfb630602fd39e80a535b25a52ef 100644 (file)
@@ -149,11 +149,10 @@ HttpCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr config) {
                                           cmd_config->getCertFile(),
                                           cmd_config->getKeyFile(),
                                           cmd_config->getCertRequired());
-                    // Overwrite the authentication setup, the http headers and the emulation flag
+                    // Overwrite the authentication setup and the http headers
                     // in the response creator config.
                     it->second->config_->setAuthConfig(cmd_config->getAuthConfig());
                     it->second->config_->setHttpHeaders(cmd_config->getHttpHeaders());
-                    it->second->config_->setEmulateAgentResponse(cmd_config->getEmulateAgentResponse());
                     listener->setTlsContext(tls_context);
                     LOG_INFO(command_logger, HTTP_COMMAND_MGR_HTTPS_SERVICE_UPDATED)
                         .arg(server_address.toText())
@@ -168,11 +167,10 @@ HttpCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr config) {
                     isc_throw(BadValue,
                               "Can not switch from HTTP to HTTPS sockets using the same address and port.");
                 } else {
-                    // Overwrite the authentication setup, the http headers and the emulation flag
+                    // Overwrite the authentication setup and the http headers
                     // in the response creator config.
                     it->second->config_->setAuthConfig(cmd_config->getAuthConfig());
                     it->second->config_->setHttpHeaders(cmd_config->getHttpHeaders());
-                    it->second->config_->setEmulateAgentResponse(cmd_config->getEmulateAgentResponse());
                     LOG_INFO(command_logger, HTTP_COMMAND_MGR_HTTP_SERVICE_UPDATED)
                         .arg(server_address.toText())
                         .arg(server_port);
index b6900cff4169c44854bbd7adc89359889b1abcce..46401055e72562dafe5e310758df54b3df0d5461 100644 (file)
@@ -182,7 +182,7 @@ HttpCommandResponseCreator::createDynamicHttpResponse(HttpRequestPtr request) {
     // a list as they may contain responses from multiple daemons.
     // If we're emulating that for backward compatibility, then we need to wrap
     // the answer in a list if it isn't in one already.
-    if ((!config_ || config_->getEmulateAgentResponse()) &&
+    if (HttpCommandConfig::EMULATE_AGENT_RESPONSE &&
         (response->getType() != Element::list)) {
         ElementPtr response_list = Element::createList();
         response_list->add(boost::const_pointer_cast<Element>(response));
index 8f72665c8a6cef8caf6f3f30ff3c4eac3da1b0e1..74f6696042d1ed140377b87def9ddb3f14d36789 100644 (file)
@@ -89,7 +89,7 @@ private:
 
     /// @brief Returns HTTP control socket config.
     ///
-    /// Used for HTTP authentication and CA emulation.
+    /// Used for HTTP authentication.
     HttpCommandConfigPtr config_;
 };
 
index 9ccd6f2d630d1f88a13f7d2b5d6383f336419947..41502fc8965ade3e6535e5789824270883dddef8 100644 (file)
@@ -16,11 +16,6 @@ namespace config {
 
 /// @brief HTTP response creator factory for HTTP control socket.
 ///
-/// @param emulate_agent_response if true results for normal command
-/// outcomes are wrapped in Element::list. This allows
-/// backward compatibility. The value is passed into the
-/// HttpCommandResponseCreator when created. Defaults to true.
-///
 /// See the documentation of the @ref isc::http::HttpResponseCreatorFactory
 /// for the details how the response factory object is used by the
 /// @ref isc::http::HttpListener.
index 50f2dd8c46b6665b96a186677b424c88676a89ec..fa4f4a1b6da313d5ae99ec0e3f3c4ce6dabaac4c 100644 (file)
@@ -28,7 +28,7 @@ TEST(CmdResponseCreatorFactory, createDefault) {
     ASSERT_TRUE(response1);
 
     // Agent response emulation should be enabled by default.
-    EXPECT_TRUE(response1->emulateAgentResponse());
+    EXPECT_TRUE(CmdResponseCreator::EMULATE_AGENT_RESPONSE);
 
     // Authorization configuration should be an empty pointer.
     EXPECT_FALSE(CmdResponseCreator::http_auth_config_);
@@ -49,8 +49,11 @@ TEST(CmdResponseCreatorFactory, createDefault) {
 // This test verifies that agent response emulation can
 // be turned off.
 TEST(CmdResponseCreatorFactory, createAgentEmulationDisabled) {
-    // Instantiate the factory with agent emulation disabled.
-    CmdResponseCreatorFactory factory(false);
+    // Instantiate the factory.
+    CmdResponseCreatorFactory factory;
+
+    // Disable agent emulation.
+    CmdResponseCreator::EMULATE_AGENT_RESPONSE = false;
 
     // Create the response creator.
     CmdResponseCreatorPtr response;
@@ -59,7 +62,7 @@ TEST(CmdResponseCreatorFactory, createAgentEmulationDisabled) {
     ASSERT_TRUE(response);
 
     // Agent response emulation should be disabled.
-    EXPECT_FALSE(response->emulateAgentResponse());
+    EXPECT_FALSE(CmdResponseCreator::EMULATE_AGENT_RESPONSE);
 
     // Authorization configuration should be an empty pointer.
     EXPECT_FALSE(CmdResponseCreator::http_auth_config_);
index 7ab27c081f20ba9b6946f447ab061c6f68caebf8..aea09e00f45a3a8821ad29118dc592bce58b4305 100644 (file)
@@ -68,7 +68,8 @@ public:
     /// @param emulate_agent_flag enables/disables agent response emulation
     /// in the CmdResponsCreator.
     void initCreator(bool emulate_agent_flag = true) {
-        response_creator_.reset(new CmdResponseCreator(emulate_agent_flag));
+        response_creator_.reset(new CmdResponseCreator);
+        CmdResponseCreator::EMULATE_AGENT_RESPONSE = emulate_agent_flag;
         request_ = response_creator_->createNewHttpRequest();
         ASSERT_TRUE(request_) << "initCreator failed to create request";
     }
@@ -189,7 +190,7 @@ TEST_F(CmdResponseCreatorTest, createDynamicHttpResponse) {
     ASSERT_TRUE(response_json);
 
     // Response should be in a list by default.
-    ASSERT_TRUE(response_creator_->emulateAgentResponse());
+    ASSERT_TRUE(CmdResponseCreator::EMULATE_AGENT_RESPONSE);
     ASSERT_TRUE(response_json->getBodyAsJson()->getType() == Element::list)
                 << "response is not a list: " << response_json->toString();
 
@@ -225,7 +226,7 @@ TEST_F(CmdResponseCreatorTest, createDynamicHttpResponseNoEmulation) {
     ASSERT_TRUE(response_json);
 
     // Response should be a map that is not enclosed in a list.
-    ASSERT_FALSE(response_creator_->emulateAgentResponse());
+    ASSERT_FALSE(CmdResponseCreator::EMULATE_AGENT_RESPONSE);
     ASSERT_TRUE(response_json->getBodyAsJson()->getType() == Element::map)
                 << "response is not a map: " << response_json->toString();
 
index f58a91c36e77bcfab2224e9eee554eda2910dd85..8dad416270ee1d6b9138342492d3cdd042c11c5d 100644 (file)
@@ -71,7 +71,7 @@ TEST_F(HttpCommandConfigTest, default) {
     EXPECT_EQ("", http_config_->getCertFile());
     EXPECT_EQ("", http_config_->getKeyFile());
     EXPECT_TRUE(http_config_->getCertRequired());
-    EXPECT_TRUE(http_config_->getEmulateAgentResponse());
+    EXPECT_TRUE(HttpCommandConfig::EMULATE_AGENT_RESPONSE);
 
     // Check unparse.
     string expected = R"(
@@ -390,7 +390,7 @@ TEST_F(HttpCommandConfigTest, tls) {
     EXPECT_EQ("my cert", http_config_->getCertFile());
     EXPECT_EQ("my key", http_config_->getKeyFile());
     EXPECT_FALSE(http_config_->getCertRequired());
-    EXPECT_TRUE(http_config_->getEmulateAgentResponse());
+    EXPECT_TRUE(HttpCommandConfig::EMULATE_AGENT_RESPONSE);
 
     // Check unparse.
     string expected = R"(
index 71956b1729053a6692d59301084001e5d29d20a8..8da413db2970f4ff1b10393eac99d1703a19f6a0 100644 (file)
@@ -65,10 +65,6 @@ TEST_F(HttpCommandResponseCreatorFactoryTest, create) {
     // Expect equality.
     EXPECT_EQ(http_config->toElement()->str(), got->toElement()->str());
 
-    // The emulation flag is hidden so check it too.
-    EXPECT_EQ(http_config->getEmulateAgentResponse(),
-              got->getEmulateAgentResponse());
-
     // Get again a response creator.
     HttpCommandResponseCreatorPtr rcf2;
     ASSERT_NO_THROW(rcf2 = boost::dynamic_pointer_cast<
index 9b72d9ddd89ef889fff817049a00404e45f85984..8cfb7d1b53791d07bec192f8ce793038f77ba333 100644 (file)
@@ -75,7 +75,7 @@ public:
         ElementPtr json;
         ASSERT_NO_THROW(json = Element::fromJSON(BASIC_CONFIG));
         ASSERT_NO_THROW(http_config_.reset(new HttpCommandConfig(json)));
-        http_config_->setEmulateAgentResponse(emulate_agent_flag);
+        HttpCommandConfig::EMULATE_AGENT_RESPONSE = emulate_agent_flag;
         http_config_->setAuthConfig(auth_config);
     }
 
@@ -262,7 +262,7 @@ TEST_F(HttpCommandResponseCreatorTest, createDynamicHttpResponse) {
     ASSERT_TRUE(response_json);
 
     // Response should be in a list by default.
-    ASSERT_TRUE(http_config_->getEmulateAgentResponse());
+    ASSERT_TRUE(HttpCommandConfig::EMULATE_AGENT_RESPONSE);
     ASSERT_TRUE(response_json->getBodyAsJson()->getType() == Element::list)
                 << "response is not a list: " << response_json->toString();
 
@@ -332,7 +332,7 @@ TEST_F(HttpCommandResponseCreatorTest, createDynamicHttpResponseNoEmulation) {
     ASSERT_TRUE(response_json);
 
     // Response should be a map that is not enclosed in a list.
-    ASSERT_FALSE(http_config_->getEmulateAgentResponse());
+    ASSERT_FALSE(HttpCommandConfig::EMULATE_AGENT_RESPONSE);
     ASSERT_TRUE(response_json->getBodyAsJson()->getType() == Element::map)
                 << "response is not a map: " << response_json->toString();