unordered_set<string> CmdResponseCreator::command_accept_list_;
+bool CmdResponseCreator::EMULATE_AGENT_RESPONSE = true;
+
HttpRequestPtr
CmdResponseCreator::createNewHttpRequest() const {
return (HttpRequestPtr(new PostHttpRequestJson()));
// 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;
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
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
/// 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.
/// @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.
/// @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.
///
/// 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
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() << ")");
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.
/// @brief Default HTTP authentication realm.
static std::string DEFAULT_AUTHENTICATION_REALM;
+ /// @brief Emulation flag.
+ static bool EMULATE_AGENT_RESPONSE;
+
private:
/// @brief Check TLS configuration.
///
/// @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").
/// @brief Require client certificates flag.
bool cert_required_;
-
- /// @brief Emulation flag.
- bool emulate_agent_response_;
};
/// @brief Pointer to a HttpCommandConfig object.
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())
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);
// 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));
/// @brief Returns HTTP control socket config.
///
- /// Used for HTTP authentication and CA emulation.
+ /// Used for HTTP authentication.
HttpCommandConfigPtr 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.
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_);
// 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;
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_);
/// @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";
}
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();
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();
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"(
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"(
// 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<
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);
}
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();
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();