const dhcp_ddns::
NameChangeProtocol& ncr_protocol,
const dhcp_ddns::
- NameChangeFormat& ncr_format,
- const bool override_no_update,
- const bool override_client_update,
- const ReplaceClientNameMode replace_client_name_mode,
- const std::string& generated_prefix,
- const std::string& qualifying_suffix,
- Optional<std::string> hostname_char_set,
- Optional<std::string> hostname_char_replacement)
+ NameChangeFormat& ncr_format)
: enable_updates_(enable_updates),
server_ip_(server_ip),
server_port_(server_port),
sender_port_(sender_port),
max_queue_size_(max_queue_size),
ncr_protocol_(ncr_protocol),
- ncr_format_(ncr_format),
- override_no_update_(override_no_update),
- override_client_update_(override_client_update),
- replace_client_name_mode_(replace_client_name_mode),
- generated_prefix_(generated_prefix),
- qualifying_suffix_(qualifying_suffix),
- hostname_char_set_(hostname_char_set),
- hostname_char_replacement_(hostname_char_replacement),
- hostname_sanitizer_(0),
- fetch_globals_fn_(0) {
+ ncr_format_(ncr_format) {
validateContents();
}
sender_port_(DFT_SENDER_PORT),
max_queue_size_(DFT_MAX_QUEUE_SIZE),
ncr_protocol_(dhcp_ddns::stringToNcrProtocol(DFT_NCR_PROTOCOL)),
- ncr_format_(dhcp_ddns::stringToNcrFormat(DFT_NCR_FORMAT)),
- override_no_update_(DFT_OVERRIDE_NO_UPDATE),
- override_client_update_(DFT_OVERRIDE_CLIENT_UPDATE),
- replace_client_name_mode_(stringToReplaceClientNameMode(DFT_REPLACE_CLIENT_NAME_MODE)),
- generated_prefix_(DFT_GENERATED_PREFIX),
- qualifying_suffix_(""),
- hostname_char_set_(DFT_HOSTNAME_CHAR_SET, true),
- hostname_char_replacement_(DFT_HOSTNAME_CHAR_SET, true),
- hostname_sanitizer_(0),
- fetch_globals_fn_(0) {
+ ncr_format_(dhcp_ddns::stringToNcrFormat(DFT_NCR_FORMAT)) {
validateContents();
}
<< server_ip_.toText() << "/" << server_port_);
}
- if (!getHostnameCharSet().unspecified() && !getHostnameCharSet().empty()) {
- try {
- hostname_sanitizer_.reset(new isc::util::str::StringSanitizer(getHostnameCharSet(),
- getHostnameCharReplacement()));
- } catch (const std::exception& ex) {
- isc_throw(D2ClientError, "D2ClientConfig: hostname-char-set"
- " is not a valid regular expression");
- }
- }
-
/// @todo perhaps more validation we should do yet?
/// Are there any invalid combinations of options we need to test against?
}
(sender_port_ == other.sender_port_) &&
(max_queue_size_ == other.max_queue_size_) &&
(ncr_protocol_ == other.ncr_protocol_) &&
- (ncr_format_ == other.ncr_format_) &&
- (override_no_update_ == other.override_no_update_) &&
- (override_client_update_ == other.override_client_update_) &&
- (replace_client_name_mode_ == other.replace_client_name_mode_) &&
- (generated_prefix_ == other.generated_prefix_) &&
- (qualifying_suffix_ == other.qualifying_suffix_) &&
- (hostname_char_set_ == other.hostname_char_set_) &&
- (hostname_char_replacement_ == other.hostname_char_replacement_));
+ (ncr_format_ == other.ncr_format_));
}
bool
<< ", sender-port: " << sender_port_
<< ", max-queue-size: " << max_queue_size_
<< ", ncr-protocol: " << ncrProtocolToString(ncr_protocol_)
- << ", ncr-format: " << ncrFormatToString(ncr_format_)
- << ", override-no-update: " << (override_no_update_ ?
- "yes" : "no")
- << ", override-client-update: " << (override_client_update_ ?
- "yes" : "no")
- << ", replace-client-name: "
- << replaceClientNameModeToString(replace_client_name_mode_)
- << ", generated-prefix: [" << generated_prefix_ << "]"
- << ", qualifying-suffix: [" << qualifying_suffix_ << "]"
- << ", hostname-char-set: [" << getHostnameCharSet() << "]"
- << ", hostname-char-replacement: [" << getHostnameCharReplacement() << "]";
+ << ", ncr-format: " << ncrFormatToString(ncr_format_);
}
+
return (stream.str());
}
contextToElement(result);
// Set enable-updates
result->set("enable-updates", Element::create(enable_updates_));
- // Set qualifying-suffix
- result->set("qualifying-suffix", Element::create(qualifying_suffix_));
// Set server-ip
result->set("server-ip", Element::create(server_ip_.toText()));
// Set server-port
// Set ncr-format
result->set("ncr-format", Element::create(dhcp_ddns::ncrFormatToString(ncr_format_)));
// Set override-no-update
- result->set("override-no-update", Element::create(override_no_update_));
- // Set override-client-update
- result->set("override-client-update", Element::create(override_client_update_));
- // Set replace-client-name
- result->set("replace-client-name",
- Element::create(replaceClientNameModeToString(replace_client_name_mode_)));
- // Set generated-prefix
- result->set("generated-prefix", Element::create(generated_prefix_));
- // Set hostname-char-set
- if (!hostname_char_set_.unspecified()) {
- result->set("hostname-char-set", Element::create(hostname_char_set_));
- }
- // Set hostname-char-replacement
- if (!hostname_char_replacement_.unspecified()) {
- result->set("hostname-char-replacement", Element::create(hostname_char_replacement_));
- }
return (result);
}
/// Currently only UDP is supported.
/// @param ncr_format Format of the kea-dhcp-ddns requests.
/// Currently only JSON format is supported.
- /// @param override_no_update Enables updates, even if clients request no
- /// updates.
- /// @param override_client_update Perform updates, even if client requested
- /// delegation.
- /// @param replace_client_name_mode enables replacement of the domain-name
- /// supplied by the client with a generated name.
- /// @param generated_prefix Prefix to use when generating domain-names.
- /// @param qualifying_suffix Suffix to use to qualify partial domain-names.
- /// @param hostname_char_set regular expression string which describes invalid
- /// characters to be scrubbed from client host names
- /// @param hostname_char_replacement string of zero or more characters to
- /// replace invalid chars when sanitizing client host names
- ///
- /// @c enable_updates is mandatory, @c qualifying_suffix is mandatory
- /// when updates are enabled, other parameters are optional.
+ /// @c enable_updates is mandatory, other parameters are optional.
///
/// @throw D2ClientError if given an invalid protocol or format.
D2ClientConfig(const bool enable_updates,
const size_t sender_port,
const size_t max_queue_size,
const dhcp_ddns::NameChangeProtocol& ncr_protocol,
- const dhcp_ddns::NameChangeFormat& ncr_format,
- const bool override_no_update,
- const bool override_client_update,
- const ReplaceClientNameMode replace_client_name_mode,
- const std::string& generated_prefix,
- const std::string& qualifying_suffix,
- util::Optional<std::string> hostname_char_set,
- util::Optional<std::string> hostname_char_replacement);
-
+ const dhcp_ddns::NameChangeFormat& ncr_format);
/// @brief Default constructor
/// The default constructor creates an instance that has updates disabled.
return(ncr_format_);
}
- /// @brief Return if updates are done even if clients request no updates.
- bool getOverrideNoUpdate() const {
- return(override_no_update_);
- }
-
- /// @brief Return if updates are done even when clients request delegation.
- bool getOverrideClientUpdate() const {
- return(override_client_update_);
- }
-
- /// @brief Return mode of replacement to use regarding client's client's domain-name
- ReplaceClientNameMode getReplaceClientNameMode() const {
- return(replace_client_name_mode_);
- }
-
- /// @brief Return the prefix to use when generating domain-names.
- const std::string& getGeneratedPrefix() const {
- return(generated_prefix_);
- }
-
- /// @brief Return the suffix to use to qualify partial domain-names.
- const std::string& getQualifyingSuffix() const {
- return(qualifying_suffix_);
- }
-
- /// @brief Return the char set regexp used to sanitize client hostnames.
- util::Optional<std::string> getHostnameCharSet() const {
- if (hostname_char_set_.unspecified() && fetch_globals_fn_) {
- data::ConstElementPtr globals = fetch_globals_fn_();
- if (globals && (globals->getType() == data::Element::map)) {
- data::ConstElementPtr global_param =
- globals->get("hostname-char-set");
- if (global_param) {
- return (global_param->stringValue());
- }
- }
- }
-
- return (hostname_char_set_);
- }
-
- /// @brief Return the invalid char replacement used to sanitize client hostnames.
- util::Optional<std::string> getHostnameCharReplacement() const {
- if (hostname_char_replacement_.unspecified() && fetch_globals_fn_) {
- data::ConstElementPtr globals = fetch_globals_fn_();
- if (globals && (globals->getType() == data::Element::map)) {
- data::ConstElementPtr global_param =
- globals->get("hostname-char-replacement");
- if (global_param) {
- return (global_param->stringValue());
- }
- }
- }
-
- return (hostname_char_replacement_);
- }
-
- /// @brief Return pointer to compiled regular expression string sanitizer
- /// Will be empty if hostname-char-set is empty.
- util::str::StringSanitizerPtr getHostnameSanitizer() const {
- return(hostname_sanitizer_);
- }
-
- /// @brief Sets the optional callback function used to fetch globally
- /// configured parameters.
- ///
- /// @param fetch_globals_fn Pointer to the function.
- void setFetchGlobalsFn(FetchNetworkGlobalsFn fetch_globals_fn) {
- fetch_globals_fn_ = fetch_globals_fn;
- }
-
- /// @brief Checks if the D2 client config is associated with a function
- /// used to fetch globally configured parameters.
- ///
- /// @return true if it is associated, false otherwise.
- bool hasFetchGlobalsFn() const {
- return (static_cast<bool>(fetch_globals_fn_));
- }
-
/// @brief Compares two D2ClientConfigs for equality
bool operator == (const D2ClientConfig& other) const;
/// @brief Format of the kea-dhcp-ddns requests.
/// Currently only JSON format is supported.
dhcp_ddns::NameChangeFormat ncr_format_;
-
- /// @brief Should Kea perform updates, even if client requested no updates.
- /// Overrides the client request for no updates via the N flag.
- bool override_no_update_;
-
- /// @brief Should Kea perform updates, even if client requested delegation.
- bool override_client_update_;
-
- /// @brief How Kea should handle the domain-name supplied by the client.
- ReplaceClientNameMode replace_client_name_mode_;
-
- /// @brief Prefix Kea should use when generating domain-names.
- std::string generated_prefix_;
-
- /// @brief Suffix Kea should use when to qualify partial domain-names.
- std::string qualifying_suffix_;
-
- /// @brief Regular expression describing invalid characters for client hostnames.
- /// If empty, host name scrubbing is not done.
- util::Optional<std::string> hostname_char_set_;
-
- /// @brief A string to replace invalid characters when scrubbing hostnames.
- /// Meaningful only if hostname_char_set_ is not empty.
- util::Optional<std::string> hostname_char_replacement_;
-
- /// @brief Pointer to compiled regular expression string sanitizer
- util::str::StringSanitizerPtr hostname_sanitizer_;
-
- /// @brief Pointer to the optional callback used to fetch globally
- /// configured parameters inherited to the @c D2ClientConfig object.
- FetchNetworkGlobalsFn fetch_globals_fn_;
};
std::ostream&
dhcp_ddns::NameChangeFormat ncr_format =
getFormat(client_config, "ncr-format");
- bool override_no_update =
- getBoolean(client_config, "override-no-update");
-
- bool override_client_update =
- getBoolean(client_config, "override-client-update");
-
- D2ClientConfig::ReplaceClientNameMode replace_client_name_mode =
- getMode(client_config, "replace-client-name");
-
- std::string generated_prefix =
- getString(client_config, "generated-prefix");
-
- Optional<std::string> hostname_char_set(D2ClientConfig::DFT_HOSTNAME_CHAR_SET, true);
- if (client_config->contains("hostname-char-set")) {
- hostname_char_set = getString(client_config, "hostname-char-set");
- }
-
- Optional<std::string> hostname_char_replacement(D2ClientConfig::DFT_HOSTNAME_CHAR_REPLACEMENT, true);
- if (client_config->contains("hostname-char-replacement")) {
- hostname_char_replacement =
- getString(client_config, "hostname-char-replacement");
- }
-
- // qualifying-suffix is the only parameter which has no default
- std::string qualifying_suffix = "";
-#if 0
- bool found_qualifying_suffix = false;
- if (client_config->contains("qualifying-suffix")) {
- qualifying_suffix = getString(client_config, "qualifying-suffix");
- found_qualifying_suffix = true;
- }
-#endif
-
IOAddress sender_ip(0);
if (sender_ip_str.empty()) {
// The default sender IP depends on the server IP family
}
}
-#if 0
- // Qualifying-suffix is required when updates are enabled
- if (enable_updates && !found_qualifying_suffix) {
- isc_throw(DhcpConfigError,
- "parameter 'qualifying-suffix' is required when "
- "updates are enabled ("
- << client_config->getPosition() << ")");
- }
-#endif
-
// Now we check for logical errors. This repeats what is done in
// D2ClientConfig::validate(), but doing it here permits us to
// emit meaningful parameter position info in the error.
sender_port,
max_queue_size,
ncr_protocol,
- ncr_format,
- override_no_update,
- override_client_update,
- replace_client_name_mode,
- generated_prefix,
- qualifying_suffix,
- hostname_char_set,
- hostname_char_replacement));
+ ncr_format));
} catch (const std::exception& ex) {
isc_throw(DhcpConfigError, ex.what() << " ("
<< client_config->getPosition() << ")");
new_config->setContext(user_context);
}
- // In order to take advantage of the dynamic inheritance of global
- // parameters to a subnet we need to set a callback function for
- // the d2 client config to allow for fetching global parameters.
- new_config->setFetchGlobalsFn([]() -> ConstElementPtr {
- return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals());
- });
-
return(new_config);
}
{ "sender-port", Element::integer, "0" },
{ "max-queue-size", Element::integer, "1024" },
{ "ncr-protocol", Element::string, "UDP" },
- { "ncr-format", Element::string, "JSON" },
- { "override-no-update", Element::boolean, "false" },
- { "override-client-update", Element::boolean, "false" },
- { "replace-client-name", Element::string, "never" },
- { "generated-prefix", Element::string, "myhost" }
- // hostname-char-set and hostname-char-replacement moved to global
- // qualifying-suffix has no default
+ { "ncr-format", Element::string, "JSON" }
};
size_t
{ "t1-percent", Element::real },
{ "t2-percent", Element::real },
{ "loggers", Element::list },
+ { "ddns-send-updates", Element::boolean },
+ { "ddns-override-no-update", Element::boolean },
+ { "ddns-override-client-update", Element::boolean },
+ { "ddns-replace-client-name", Element::string },
+ { "ddns-generated-prefix", Element::string },
+ { "ddns-qualifying-suffix", Element::string }
{ "hostname-char-set", Element::string },
{ "hostname-char-replacement", Element::string }
};
/// in Dhcp4) are optional. If not defined, the following values will be
/// used.
const SimpleDefaults SimpleParser4::GLOBAL4_DEFAULTS = {
- { "valid-lifetime", Element::integer, "7200" },
- { "decline-probation-period", Element::integer, "86400" }, // 24h
- { "dhcp4o6-port", Element::integer, "0" },
- { "echo-client-id", Element::boolean, "true" },
- { "match-client-id", Element::boolean, "true" },
- { "authoritative", Element::boolean, "false" },
- { "next-server", Element::string, "0.0.0.0" },
- { "server-hostname", Element::string, "" },
- { "boot-file-name", Element::string, "" },
- { "server-tag", Element::string, "" },
- { "reservation-mode", Element::string, "all" },
- { "calculate-tee-times", Element::boolean, "false" },
- { "t1-percent", Element::real, ".50" },
- { "t2-percent", Element::real, ".875" }
+ { "valid-lifetime", Element::integer, "7200" },
+ { "decline-probation-period", Element::integer, "86400" }, // 24h
+ { "dhcp4o6-port", Element::integer, "0" },
+ { "echo-client-id", Element::boolean, "true" },
+ { "match-client-id", Element::boolean, "true" },
+ { "authoritative", Element::boolean, "false" },
+ { "next-server", Element::string, "0.0.0.0" },
+ { "server-hostname", Element::string, "" },
+ { "boot-file-name", Element::string, "" },
+ { "server-tag", Element::string, "" },
+ { "reservation-mode", Element::string, "all" },
+ { "calculate-tee-times", Element::boolean, "false" },
+ { "t1-percent", Element::real, ".50" },
+ { "t2-percent", Element::real, ".875" },
+ { "ddns-send-updates", Element::boolean, "false" },
+ { "ddns-override-no-update", Element::boolean, "false" },
+ { "ddns-override-client-update", Element::boolean, "false" },
+ { "ddns-replace-client-name", Element::string, "never" },
+ { "ddns-generated-prefix", Element::string, "myhost" }
+ // TKM should this still be true? qualifying-suffix has no default ??
+ { "ddns-generated-suffix", Element::string, "" }
};
/// @brief This table defines all option definition parameters.
isc::asiolink::IOAddress("127.0.0.1"), 477,
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_ALWAYS,
- "pre-fix", "suf-fix", "[^A-z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
// Verify that we can assign a new, non-empty configuration.
ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(new_cfg));
sender_port,
max_queue_size,
ncr_protocol,
- ncr_format,
- override_no_update,
- override_client_update,
- replace_client_name_mode,
- generated_prefix,
- qualifying_suffix,
- hostname_char_set,
- hostname_char_replacement)));
+ ncr_format)));
ASSERT_TRUE(d2_client_config);
// Add user context
EXPECT_EQ(d2_client_config->getMaxQueueSize(), max_queue_size);
EXPECT_EQ(d2_client_config->getNcrProtocol(), ncr_protocol);
EXPECT_EQ(d2_client_config->getNcrFormat(), ncr_format);
- EXPECT_EQ(d2_client_config->getOverrideNoUpdate(), override_no_update);
- EXPECT_EQ(d2_client_config->getOverrideClientUpdate(),
- override_client_update);
- EXPECT_EQ(d2_client_config->getReplaceClientNameMode(), replace_client_name_mode);
- EXPECT_EQ(d2_client_config->getGeneratedPrefix(), generated_prefix);
- EXPECT_EQ(d2_client_config->getQualifyingSuffix(), qualifying_suffix);
-
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ(d2_client_config->getHostnameCharSet(), hostname_char_set);
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ(d2_client_config->getHostnameCharReplacement(), hostname_char_replacement);
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
-
ASSERT_TRUE(d2_client_config->getContext());
EXPECT_EQ(d2_client_config->getContext()->str(), user_context);
"\"max-queue-size\": 2048,\n"
"\"ncr-protocol\": \"UDP\",\n"
"\"ncr-format\": \"JSON\",\n"
- "\"override-no-update\": true,\n"
- "\"override-client-update\": true,\n"
- "\"replace-client-name\": \"when-present\",\n"
- "\"generated-prefix\": \"the_prefix\",\n"
- "\"qualifying-suffix\": \"the.suffix.\",\n"
- "\"hostname-char-set\": \"[^A-Z]\",\n"
- "\"hostname-char-replacement\": \"*\",\n"
"\"user-context\": { \"foo\": 1 }\n"
"}\n";
runToElementTest<D2ClientConfig>(expected, *d2_client_config);
sender_port,
max_queue_size,
dhcp_ddns::NCR_TCP,
- ncr_format,
- override_no_update,
- override_client_update,
- replace_client_name_mode,
- generated_prefix,
- qualifying_suffix,
- hostname_char_set,
- hostname_char_replacement)),
+ ncr_format)),
D2ClientError);
Optional<std::string> opt_hostname_char_set("", true);
sender_port,
max_queue_size,
ncr_protocol,
- ncr_format,
- override_no_update,
- override_client_update,
- replace_client_name_mode,
- generated_prefix,
- qualifying_suffix,
- opt_hostname_char_set,
- opt_hostname_char_replacement)));
+ ncr_format)));
ASSERT_TRUE(d2_client_config);
- // Verify that the accessors return the expected values.
- EXPECT_TRUE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ(d2_client_config->getHostnameCharSet(), opt_hostname_char_set);
- EXPECT_TRUE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ(d2_client_config->getHostnameCharReplacement(), opt_hostname_char_replacement);
- EXPECT_FALSE(d2_client_config->getHostnameSanitizer());
-
// Verify what toElement returns.
expected = "{\n"
"\"enable-updates\": true,\n"
"\"sender-port\": 478,\n"
"\"max-queue-size\": 2048,\n"
"\"ncr-protocol\": \"UDP\",\n"
- "\"ncr-format\": \"JSON\",\n"
- "\"override-no-update\": true,\n"
- "\"override-client-update\": true,\n"
- "\"replace-client-name\": \"when-present\",\n"
- "\"generated-prefix\": \"the_prefix\",\n"
- "\"qualifying-suffix\": \"the.suffix.\"\n"
+ "\"ncr-format\": \"JSON\"\n"
"}\n";
runToElementTest<D2ClientConfig>(expected, *d2_client_config);
// Create an instance to use as a reference.
ASSERT_NO_THROW(ref_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(ref_config);
// Check a configuration that is identical to reference configuration.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_TRUE(*ref_config == *test_config);
EXPECT_FALSE(*ref_config != *test_config);
// Check a configuration that differs only by enable flag.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(false,
ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
// Check a configuration that differs only by server ip.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
test_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
// Check a configuration that differs only by server port.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 333, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
// Check a configuration that differs only by sender ip.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, test_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
// Check a configuration that differs only by sender port.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 333, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
// Check a configuration that differs only by max queue size.
ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
ref_address, 477, ref_address, 478, 2048,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by override_no_update.
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- false, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by override_client_update.
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, false, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by replace_client_name.
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_NEVER,
- "pre-fix", "suf-fix", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by generated_prefix.
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "bogus", "suf-fix", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by qualifying_suffix.
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "bogus", "[^A-Z]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by hostname_char_set
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[abc]", "*")));
- ASSERT_TRUE(test_config);
- EXPECT_FALSE(*ref_config == *test_config);
- EXPECT_TRUE(*ref_config != *test_config);
-
- // Check a configuration that differs only by hostname_char_replacment
- ASSERT_NO_THROW(test_config.reset(new D2ClientConfig(true,
- ref_address, 477, ref_address, 478, 1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "[^A-Z]", "x")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
EXPECT_TRUE(*ref_config != *test_config);
isc::asiolink::IOAddress("127.0.0.1"), 477,
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "", "")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
// Verify that we can assign a new, non-empty configuration.
ASSERT_NO_THROW(d2_client_mgr->setD2ClientConfig(new_cfg));
isc::asiolink::IOAddress("::1"), 477,
isc::asiolink::IOAddress("::1"), 478,
1024,
- dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "pre-fix", "suf-fix", "", "")));
+ dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON)));
// Verify that we can assign a new, non-empty configuration.
ASSERT_NO_THROW(d2_client_mgr->setD2ClientConfig(new_cfg));
server_ip, server_port,
sender_ip, D2ClientConfig::DFT_SENDER_PORT,
D2ClientConfig::DFT_MAX_QUEUE_SIZE,
- protocol, dhcp_ddns::FMT_JSON,
- true, true, D2ClientConfig::RCM_WHEN_PRESENT,
- "myhost", ".example.com.", "", "")));
+ protocol, dhcp_ddns::FMT_JSON)));
ASSERT_NO_THROW(setD2ClientConfig(new_cfg));
ASSERT_TRUE(ddnsEnabled());
" \"max-queue-size\" : 2048, "
" \"ncr-protocol\" : \"UDP\", "
" \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : \"when-present\", "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\", "
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\", "
" \"user-context\": { \"foo\": \"bar\" } "
" }"
"}";
EXPECT_EQ(3432, d2_client_config->getServerPort());
EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
- EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("test.prefix", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("test.suffix.", d2_client_config->getQualifyingSuffix());
ASSERT_TRUE(d2_client_config->getContext());
EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
// Verify that the configuration object unparses.
ConstElementPtr expected;
" \"max-queue-size\" : 2048, "
" \"ncr-protocol\" : \"UDP\", "
" \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : false, "
- " \"override-client-update\" : false, "
- " \"replace-client-name\" : \"never\", "
- " \"generated-prefix\" : \"\", "
- " \"qualifying-suffix\" : \"\", "
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\", "
" \"user-context\": { \"foo\": \"bar\" } "
" }"
"}";
EXPECT_EQ(43567, d2_client_config->getServerPort());
EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_FALSE(d2_client_config->getOverrideNoUpdate());
- EXPECT_FALSE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_NEVER, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("", d2_client_config->getQualifyingSuffix());
ASSERT_TRUE(d2_client_config->getContext());
EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
-
- ASSERT_NO_THROW(expected = Element::fromJSON(config_str2)->get("dhcp-ddns"));
- ASSERT_TRUE(expected);
- runToElementTest<D2ClientConfig>(expected, *d2_client_config);
-}
-
-/// @brief Checks that a valid, enabled D2 client configuration works correctly
-/// with hostname-char stuff moved to global.
-TEST_F(ParseConfigTest, validD2ConfigGlobal) {
-
- // Configuration string containing valid values.
- std::string config_str =
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : true, "
- " \"server-ip\" : \"192.0.2.0\", "
- " \"server-port\" : 3432, "
- " \"sender-ip\" : \"192.0.2.1\", "
- " \"sender-port\" : 3433, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : \"when-present\", "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\", "
- " \"user-context\": { \"foo\": \"bar\" } "
- " },"
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\" "
- "}";
-
- // Verify that the configuration string parses.
- int rcode = parseConfiguration(config_str);
- ASSERT_TRUE(rcode == 0) << error_text_;
-
- // Verify that DHCP-DDNS is enabled and we can fetch the configuration.
- EXPECT_TRUE(CfgMgr::instance().ddnsEnabled());
- D2ClientConfigPtr d2_client_config;
- ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
- ASSERT_TRUE(d2_client_config);
-
- // Verify that the configuration values are as expected.
- EXPECT_TRUE(d2_client_config->getEnableUpdates());
- EXPECT_EQ("192.0.2.0", d2_client_config->getServerIp().toText());
- EXPECT_EQ(3432, d2_client_config->getServerPort());
- EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
- EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
- EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("test.prefix", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("test.suffix.", d2_client_config->getQualifyingSuffix());
- ASSERT_TRUE(d2_client_config->getContext());
- EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
-
- // Verify that the configuration object unparses.
- ConstElementPtr expected;
- ASSERT_NO_THROW(expected = Element::fromJSON(config_str)->get("dhcp-ddns"));
- ASSERT_TRUE(expected);
- runToElementTest<D2ClientConfig>(expected, *d2_client_config);
-
- // Another valid Configuration string.
- // This one is disabled, has IPV6 server ip, control flags false,
- // empty prefix/suffix
- std::string config_str2 =
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : false, "
- " \"server-ip\" : \"2001:db8::\", "
- " \"server-port\" : 43567, "
- " \"sender-ip\" : \"2001:db8::1\", "
- " \"sender-port\" : 3433, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : false, "
- " \"override-client-update\" : false, "
- " \"replace-client-name\" : \"never\", "
- " \"generated-prefix\" : \"\", "
- " \"qualifying-suffix\" : \"\", "
- " \"user-context\": { \"foo\": \"bar\" } "
- " },"
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\" "
- "}";
-
- // Verify that the configuration string parses.
- rcode = parseConfiguration(config_str2);
- ASSERT_TRUE(rcode == 0) << error_text_;
-
- // Verify that DHCP-DDNS is disabled and we can fetch the configuration.
- EXPECT_FALSE(CfgMgr::instance().ddnsEnabled());
- ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
- ASSERT_TRUE(d2_client_config);
-
- // Verify that the configuration values are as expected.
- EXPECT_FALSE(d2_client_config->getEnableUpdates());
- EXPECT_EQ("2001:db8::", d2_client_config->getServerIp().toText());
- EXPECT_EQ(43567, d2_client_config->getServerPort());
- EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
- EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_FALSE(d2_client_config->getOverrideNoUpdate());
- EXPECT_FALSE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_NEVER, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("", d2_client_config->getQualifyingSuffix());
- ASSERT_TRUE(d2_client_config->getContext());
- EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
-
- ASSERT_NO_THROW(expected = Element::fromJSON(config_str2)->get("dhcp-ddns"));
- ASSERT_TRUE(expected);
- runToElementTest<D2ClientConfig>(expected, *d2_client_config);
-}
-
-/// @brief Checks that a valid, enabled D2 client configuration works correctly
-/// with hostname-char stuff in both local and global (local has the priority).
-TEST_F(ParseConfigTest, validD2ConfigBoth) {
-
- // Configuration string containing valid values.
- std::string config_str =
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : true, "
- " \"server-ip\" : \"192.0.2.0\", "
- " \"server-port\" : 3432, "
- " \"sender-ip\" : \"192.0.2.1\", "
- " \"sender-port\" : 3433, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : \"when-present\", "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\", "
- " \"user-context\": { \"foo\": \"bar\" } "
- " },"
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\" "
- "}";
-
- // Verify that the configuration string parses.
- int rcode = parseConfiguration(config_str);
- ASSERT_TRUE(rcode == 0) << error_text_;
-
- // Verify that DHCP-DDNS is enabled and we can fetch the configuration.
- EXPECT_TRUE(CfgMgr::instance().ddnsEnabled());
- D2ClientConfigPtr d2_client_config;
- ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
- ASSERT_TRUE(d2_client_config);
-
- // Verify that the configuration values are as expected.
- EXPECT_TRUE(d2_client_config->getEnableUpdates());
- EXPECT_EQ("192.0.2.0", d2_client_config->getServerIp().toText());
- EXPECT_EQ(3432, d2_client_config->getServerPort());
- EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
- EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
- EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("test.prefix", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("test.suffix.", d2_client_config->getQualifyingSuffix());
- ASSERT_TRUE(d2_client_config->getContext());
- EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
-
- // Verify that the configuration object unparses.
- ConstElementPtr expected;
- ASSERT_NO_THROW(expected = Element::fromJSON(config_str)->get("dhcp-ddns"));
- ASSERT_TRUE(expected);
- runToElementTest<D2ClientConfig>(expected, *d2_client_config);
-
- // Another valid Configuration string.
- // This one is disabled, has IPV6 server ip, control flags false,
- // empty prefix/suffix
- std::string config_str2 =
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : false, "
- " \"server-ip\" : \"2001:db8::\", "
- " \"server-port\" : 43567, "
- " \"sender-ip\" : \"2001:db8::1\", "
- " \"sender-port\" : 3433, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : false, "
- " \"override-client-update\" : false, "
- " \"replace-client-name\" : \"never\", "
- " \"generated-prefix\" : \"\", "
- " \"qualifying-suffix\" : \"\", "
- " \"user-context\": { \"foo\": \"bar\" } "
- " },"
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\" "
- "}";
-
- // Verify that the configuration string parses.
- rcode = parseConfiguration(config_str2);
- ASSERT_TRUE(rcode == 0) << error_text_;
-
- // Verify that DHCP-DDNS is disabled and we can fetch the configuration.
- EXPECT_FALSE(CfgMgr::instance().ddnsEnabled());
- ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
- ASSERT_TRUE(d2_client_config);
-
- // Verify that the configuration values are as expected.
- EXPECT_FALSE(d2_client_config->getEnableUpdates());
- EXPECT_EQ("2001:db8::", d2_client_config->getServerIp().toText());
- EXPECT_EQ(43567, d2_client_config->getServerPort());
- EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol());
- EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat());
- EXPECT_FALSE(d2_client_config->getOverrideNoUpdate());
- EXPECT_FALSE(d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::RCM_NEVER, d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ("", d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("", d2_client_config->getQualifyingSuffix());
- ASSERT_TRUE(d2_client_config->getContext());
- EXPECT_EQ("{ \"foo\": \"bar\" }", d2_client_config->getContext()->str());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
ASSERT_NO_THROW(expected = Element::fromJSON(config_str2)->get("dhcp-ddns"));
ASSERT_TRUE(expected);
ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
EXPECT_TRUE(d2_client_config);
EXPECT_FALSE(d2_client_config->getEnableUpdates());
- EXPECT_TRUE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_TRUE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_FALSE(d2_client_config->getHostnameSanitizer());
-
- // Retry with hostname-char-* globals.
- std::string config_str2 =
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : false"
- " },"
- " \"hostname-char-set\" : \"[^A-Z]\", "
- " \"hostname-char-replacement\" : \"*\" "
- "}";
-
- // Verify that the configuration string parses.
- rcode = parseConfiguration(config_str2);
- ASSERT_TRUE(rcode == 0) << error_text_;
-
- // Verify that DHCP-DDNS is disabled.
- EXPECT_FALSE(CfgMgr::instance().ddnsEnabled());
-
- // Make sure fetched config agrees.
- ASSERT_NO_THROW(d2_client_config = CfgMgr::instance().getD2ClientConfig());
- EXPECT_TRUE(d2_client_config);
- EXPECT_FALSE(d2_client_config->getEnableUpdates());
- EXPECT_FALSE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_EQ("[^A-Z]", d2_client_config->getHostnameCharSet().get());
- EXPECT_FALSE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_EQ("*", d2_client_config->getHostnameCharReplacement().get());
- EXPECT_TRUE(d2_client_config->getHostnameSanitizer());
}
/// @brief Checks that given a partial configuration, parser supplies
std::string config_str =
"{ \"dhcp-ddns\" :"
" {"
- " \"enable-updates\" : true, "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"enable-updates\" : true "
" }"
"}";
d2_client_config->getNcrProtocol());
EXPECT_EQ(dhcp_ddns::stringToNcrFormat(D2ClientConfig::DFT_NCR_FORMAT),
d2_client_config->getNcrFormat());
- EXPECT_EQ(D2ClientConfig::DFT_OVERRIDE_NO_UPDATE,
- d2_client_config->getOverrideNoUpdate());
- EXPECT_EQ(D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE,
- d2_client_config->getOverrideClientUpdate());
- EXPECT_EQ(D2ClientConfig::
- stringToReplaceClientNameMode(D2ClientConfig::
- DFT_REPLACE_CLIENT_NAME_MODE),
- d2_client_config->getReplaceClientNameMode());
- EXPECT_EQ(D2ClientConfig::DFT_GENERATED_PREFIX,
- d2_client_config->getGeneratedPrefix());
- EXPECT_EQ("test.suffix.",
- d2_client_config->getQualifyingSuffix());
- EXPECT_TRUE(d2_client_config->getHostnameCharSet().unspecified());
- EXPECT_TRUE(d2_client_config->getHostnameCharSet().empty());
- EXPECT_TRUE(d2_client_config->getHostnameCharReplacement().unspecified());
- EXPECT_TRUE(d2_client_config->getHostnameCharReplacement().empty());
- EXPECT_FALSE(d2_client_config->getHostnameSanitizer());
}
/// @brief Check various invalid D2 client configurations.
TEST_F(ParseConfigTest, invalidD2Config) {
std::string invalid_configs[] = {
- // Must supply qualifying-suffix when updates are enabled
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : true"
- " }"
- "}",
// Invalid server ip value
"{ \"dhcp-ddns\" :"
" {"
" \"server-ip\" : \"x192.0.2.0\", "
" \"server-port\" : 53001, "
" \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// Unknown protocol
" \"server-ip\" : \"192.0.2.0\", "
" \"server-port\" : 53001, "
" \"ncr-protocol\" : \"Bogus\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// Unsupported protocol
" \"server-ip\" : \"192.0.2.0\", "
" \"server-port\" : 53001, "
" \"ncr-protocol\" : \"TCP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// Unknown format
" \"server-ip\" : \"192.0.2.0\", "
" \"server-port\" : 53001, "
" \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"Bogus\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"Bogus\" "
" }"
"}",
// Invalid Port
" \"server-ip\" : \"192.0.2.0\", "
" \"server-port\" : \"bogus\", "
" \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// Mismatched server and sender IPs
" \"sender-port\" : 3433, "
" \"max-queue-size\" : 2048, "
" \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// Identical server and sender IP/port
" \"sender-port\" : 3433, "
" \"max-queue-size\" : 2048, "
" \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : true, "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
- " }"
- "}",
- // Invalid replace-client-name value
- "{ \"dhcp-ddns\" :"
- " {"
- " \"enable-updates\" : true, "
- " \"server-ip\" : \"3001::5\", "
- " \"server-port\" : 3433, "
- " \"sender-ip\" : \"3001::5\", "
- " \"sender-port\" : 3434, "
- " \"max-queue-size\" : 2048, "
- " \"ncr-protocol\" : \"UDP\", "
- " \"ncr-format\" : \"JSON\", "
- " \"override-no-update\" : true, "
- " \"override-client-update\" : true, "
- " \"replace-client-name\" : \"BOGUS\", "
- " \"generated-prefix\" : \"test.prefix\", "
- " \"qualifying-suffix\" : \"test.suffix.\" "
+ " \"ncr-format\" : \"JSON\" "
" }"
"}",
// stop