From: Thomas Markwalder Date: Mon, 9 Jul 2018 14:11:40 +0000 (-0400) Subject: [5680] Added support for D2 client hostname sanitizer parms to dhcpsrv lib X-Git-Tag: ha_phase2~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54bb07ee25b2724c4c19edcca396ba0349320873;p=thirdparty%2Fkea.git [5680] Added support for D2 client hostname sanitizer parms to dhcpsrv lib src/lib/dhcpsrv/d2_client_cfg.* src/lib/dhcpsrv/parsers/dhcp_parsers.cc src/lib/dhcpsrv/tests/cfgmgr_unittest.cc src/lib/dhcpsrv/tests/d2_client_unittest.cc src/lib/dhcpsrv/tests/d2_udp_unittest.cc Added defaults and handling for new params, hostname-char-set and hostname-char-replacement --- diff --git a/src/lib/dhcpsrv/d2_client_cfg.cc b/src/lib/dhcpsrv/d2_client_cfg.cc index 12718cf7ad..f1ecc3341d 100644 --- a/src/lib/dhcpsrv/d2_client_cfg.cc +++ b/src/lib/dhcpsrv/d2_client_cfg.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -21,6 +21,7 @@ using namespace isc::data; namespace isc { namespace dhcp { +/// These values need to match those used in D2ClientConfigParser::SimpleDefaults const char* D2ClientConfig::DFT_SERVER_IP = "127.0.0.1"; const size_t D2ClientConfig::DFT_SERVER_PORT = 53001; const char* D2ClientConfig::DFT_V4_SENDER_IP = "0.0.0.0"; @@ -34,7 +35,8 @@ const bool D2ClientConfig::DFT_OVERRIDE_NO_UPDATE = false; const bool D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE = false; const char* D2ClientConfig::DFT_REPLACE_CLIENT_NAME_MODE = "NEVER"; const char* D2ClientConfig::DFT_GENERATED_PREFIX = "myhost"; - +const char* D2ClientConfig::DFT_HOSTNAME_CHAR_SET = ""; +const char* D2ClientConfig::DFT_HOSTNAME_CHAR_REPLACEMENT = ""; D2ClientConfig::ReplaceClientNameMode D2ClientConfig::stringToReplaceClientNameMode(const std::string& mode_str) { @@ -93,7 +95,9 @@ D2ClientConfig::D2ClientConfig(const bool enable_updates, const bool override_client_update, const ReplaceClientNameMode replace_client_name_mode, const std::string& generated_prefix, - const std::string& qualifying_suffix) + const std::string& qualifying_suffix, + const std::string& hostname_char_set, + const std::string& hostname_char_replacement) : enable_updates_(enable_updates), server_ip_(server_ip), server_port_(server_port), @@ -107,7 +111,9 @@ D2ClientConfig::D2ClientConfig(const bool enable_updates, override_client_update_(override_client_update), replace_client_name_mode_(replace_client_name_mode), generated_prefix_(generated_prefix), - qualifying_suffix_(qualifying_suffix) { + qualifying_suffix_(qualifying_suffix), + hostname_char_set_(hostname_char_set), + hostname_char_replacement_(hostname_char_replacement) { validateContents(); } @@ -125,7 +131,9 @@ D2ClientConfig::D2ClientConfig() override_client_update_(DFT_OVERRIDE_CLIENT_UPDATE), replace_client_name_mode_(stringToReplaceClientNameMode(DFT_REPLACE_CLIENT_NAME_MODE)), generated_prefix_(DFT_GENERATED_PREFIX), - qualifying_suffix_("") { + qualifying_suffix_(""), + hostname_char_set_(DFT_HOSTNAME_CHAR_SET), + hostname_char_replacement_(DFT_HOSTNAME_CHAR_SET) { validateContents(); } @@ -183,7 +191,9 @@ D2ClientConfig::operator == (const D2ClientConfig& other) const { (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_)); + (qualifying_suffix_ == other.qualifying_suffix_) && + (hostname_char_set_ == other.hostname_char_set_) && + (hostname_char_replacement_ == other.hostname_char_replacement_)); } bool @@ -213,7 +223,9 @@ D2ClientConfig::toText() const { << ", replace_client_name: " << replaceClientNameModeToString(replace_client_name_mode_) << ", generated_prefix: [" << generated_prefix_ << "]" - << ", qualifying_suffix: [" << qualifying_suffix_ << "]"; + << ", qualifying_suffix: [" << qualifying_suffix_ << "]" + << ", hostname_char_set: [" << hostname_char_set_ << "]" + << ", hostname_char_replacement: [" << hostname_char_replacement_ << "]"; } return (stream.str()); @@ -253,6 +265,10 @@ D2ClientConfig::toElement() const { Element::create(replaceClientNameModeToString(replace_client_name_mode_))); // Set generated-prefix result->set("generated-prefix", Element::create(generated_prefix_)); + // Set hostname-char-set + result->set("hostname-char-set", Element::create(hostname_char_set_)); + // Set hostname-char-replacement + result->set("hostname-char-replacement", Element::create(hostname_char_replacement_)); return (result); } diff --git a/src/lib/dhcpsrv/d2_client_cfg.h b/src/lib/dhcpsrv/d2_client_cfg.h index b9e3b8a7a2..8c5470380b 100644 --- a/src/lib/dhcpsrv/d2_client_cfg.h +++ b/src/lib/dhcpsrv/d2_client_cfg.h @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -52,8 +52,6 @@ public: class D2ClientConfig : public UserContext, public isc::data::CfgToElement { public: /// @brief Default configuration constants. - /// @todo For now these are hard-coded as configuration layer cannot - /// readily provide them (see Trac #3358). static const char* DFT_SERVER_IP; static const size_t DFT_SERVER_PORT; static const char* DFT_V4_SENDER_IP; @@ -67,6 +65,8 @@ public: static const bool DFT_OVERRIDE_CLIENT_UPDATE; static const char* DFT_REPLACE_CLIENT_NAME_MODE; static const char* DFT_GENERATED_PREFIX; + static const char* DFT_HOSTNAME_CHAR_SET; + static const char* DFT_HOSTNAME_CHAR_REPLACEMENT; /// @brief Defines the client name replacement modes. enum ReplaceClientNameMode { @@ -116,7 +116,10 @@ public: const bool override_client_update, const ReplaceClientNameMode replace_client_name_mode, const std::string& generated_prefix, - const std::string& qualifying_suffix); + const std::string& qualifying_suffix, + const std::string& hostname_char_set, + const std::string& hostname_char_replacement); + /// @brief Default constructor /// The default constructor creates an instance that has updates disabled. @@ -195,6 +198,16 @@ public: return(qualifying_suffix_); } + /// @brief Return the char set regexp used to sanitize client hostnames. + const std::string& getHostnameCharSet() const { + return(hostname_char_set_); + } + + /// @brief Return the invalid char replacement used to sanitize client hostnames. + const std::string& getHostnameCharReplacement() const { + return(hostname_char_replacement_); + } + /// @brief Compares two D2ClientConfigs for equality bool operator == (const D2ClientConfig& other) const; @@ -291,6 +304,14 @@ private: /// @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. + std::string hostname_char_set_; + + /// @brief A string to replace invalid characters when scrubbing hostnames. + /// Meaningful only if hostname_char_set_ is not empty. + std::string hostname_char_replacement_; }; std::ostream& diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index 6f6209620c..7b9d26f995 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -1,11 +1,7 @@ // Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include - +// License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include #include #include #include @@ -1321,6 +1317,12 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) { std::string generated_prefix = getString(client_config, "generated-prefix"); + std::string hostname_char_set = + getString(client_config, "hostname-char-set"); + + std::string hostname_char_replacement = + getString(client_config, "hostname-char-replacement"); + // qualifying-suffix is the only parameter which has no default std::string qualifying_suffix = ""; bool found_qualifying_suffix = false; @@ -1402,8 +1404,9 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) { override_client_update, replace_client_name_mode, generated_prefix, - qualifying_suffix)); - + qualifying_suffix, + hostname_char_set, + hostname_char_replacement)); } catch (const std::exception& ex) { isc_throw(DhcpConfigError, ex.what() << " (" << client_config->getPosition() << ")"); @@ -1434,7 +1437,9 @@ const SimpleDefaults D2ClientConfigParser::D2_CLIENT_CONFIG_DEFAULTS = { { "override-no-update", Element::boolean, "false" }, { "override-client-update", Element::boolean, "false" }, { "replace-client-name", Element::string, "never" }, - { "generated-prefix", Element::string, "myhost" } + { "generated-prefix", Element::string, "myhost" }, + { "hostname-char-set", Element::string, "" }, + { "hostname-char-replacement", Element::string, "" } // qualifying-suffix has no default }; diff --git a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc index e35e7ad783..461cb45686 100644 --- a/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfgmgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -342,7 +342,7 @@ TEST_F(CfgMgrTest, d2ClientConfig) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_ALWAYS, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-z]", "*"))); // Verify that we can assign a new, non-empty configuration. ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(new_cfg)); diff --git a/src/lib/dhcpsrv/tests/d2_client_unittest.cc b/src/lib/dhcpsrv/tests/d2_client_unittest.cc index 4e2f8e8fa3..dbd397318a 100644 --- a/src/lib/dhcpsrv/tests/d2_client_unittest.cc +++ b/src/lib/dhcpsrv/tests/d2_client_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -82,6 +82,8 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) { RCM_WHEN_PRESENT; std::string generated_prefix = "the_prefix"; std::string qualifying_suffix = "the.suffix."; + std::string hostname_char_set = "[^A-Z]"; + std::string hostname_char_replacement = "*"; // Verify that we can construct a valid, enabled instance. ASSERT_NO_THROW(d2_client_config.reset(new @@ -98,8 +100,9 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) { override_client_update, replace_client_name_mode, generated_prefix, - qualifying_suffix))); - + qualifying_suffix, + hostname_char_set, + hostname_char_replacement))); ASSERT_TRUE(d2_client_config); // Add user context @@ -149,6 +152,8 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) { "\"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(expected, *d2_client_config); @@ -169,7 +174,9 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) { override_client_update, replace_client_name_mode, generated_prefix, - qualifying_suffix)), + qualifying_suffix, + hostname_char_set, + hostname_char_replacement)), D2ClientError); /// @todo if additional validation is added to ctor, this test needs to @@ -189,7 +196,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(ref_config); // Check a configuration that is identical to reference configuration. @@ -197,7 +204,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_TRUE(*ref_config == *test_config); EXPECT_FALSE(*ref_config != *test_config); @@ -207,7 +214,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -217,7 +224,7 @@ TEST(D2ClientConfigTest, equalityOperator) { test_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -227,7 +234,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 333, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -237,7 +244,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, test_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -247,7 +254,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 333, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -257,7 +264,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 2048, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -267,7 +274,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -277,7 +284,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, false, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -287,7 +294,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, false, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -297,7 +304,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -307,7 +314,7 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "bogus", "suf-fix"))); + "bogus", "suf-fix", "[^A-Z]", "*"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -317,7 +324,27 @@ TEST(D2ClientConfigTest, equalityOperator) { ref_address, 477, ref_address, 478, 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "bogus"))); + "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, 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, true, D2ClientConfig::RCM_WHEN_PRESENT, + "pre-fix", "suf-fix", "[^A-Z]", "x"))); ASSERT_TRUE(test_config); EXPECT_FALSE(*ref_config == *test_config); EXPECT_TRUE(*ref_config != *test_config); @@ -362,7 +389,7 @@ TEST(D2ClientMgr, validConfig) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); // Verify that we can assign a new, non-empty configuration. ASSERT_NO_THROW(d2_client_mgr->setD2ClientConfig(new_cfg)); @@ -399,7 +426,7 @@ TEST(D2ClientMgr, ipv6Config) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); // Verify that we can assign a new, non-empty configuration. ASSERT_NO_THROW(d2_client_mgr->setD2ClientConfig(new_cfg)); @@ -442,7 +469,7 @@ TEST(D2ClientMgr, analyzeFqdnInvalidCombination) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); @@ -466,7 +493,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledNoOverrides) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); ASSERT_FALSE(cfg->getOverrideClientUpdate()); @@ -510,7 +537,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledOverrideNoUpdate) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, true, false, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); ASSERT_TRUE(cfg->getOverrideNoUpdate()); @@ -553,7 +580,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledOverrideClientUpdate) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); ASSERT_FALSE(cfg->getOverrideNoUpdate()); @@ -597,7 +624,7 @@ TEST(D2ClientMgr, adjustFqdnFlagsV4) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, true, false, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); ASSERT_TRUE(cfg->getOverrideNoUpdate()); @@ -698,7 +725,7 @@ TEST(D2ClientMgr, qualifyName) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); // Verify that the qualifying suffix gets appended with trailing dot added. @@ -714,7 +741,7 @@ TEST(D2ClientMgr, qualifyName) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); partial_name = "somehost"; qualified_name = mgr.qualifyName(partial_name, false); //false means no dot @@ -728,7 +755,7 @@ TEST(D2ClientMgr, qualifyName) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", ""))); //empty suffix + "prefix", "", "", ""))); //empty suffix ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); partial_name = "somehost"; qualified_name = mgr.qualifyName(partial_name, false); //false means no dot @@ -741,7 +768,7 @@ TEST(D2ClientMgr, qualifyName) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", "hasdot.com."))); + "prefix", "hasdot.com.", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); // Verify that the qualifying suffix gets appended without dot added. @@ -760,7 +787,7 @@ TEST(D2ClientMgr, qualifyName) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", ""))); + "prefix", "", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); // Verify that a name with a trailing dot does not get an extraneous @@ -798,7 +825,7 @@ TEST(D2ClientMgr, generateFqdn) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, true, D2ClientConfig::RCM_NEVER, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); // Verify that it works with an IPv4 address. @@ -832,7 +859,7 @@ TEST(D2ClientMgr, adjustDomainNameV4) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_NEVER, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode()); @@ -875,7 +902,7 @@ TEST(D2ClientMgr, adjustDomainNameV4) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_WHEN_PRESENT, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode()); @@ -925,7 +952,7 @@ TEST(D2ClientMgr, adjustDomainNameV6) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_NEVER, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode()); @@ -965,7 +992,7 @@ TEST(D2ClientMgr, adjustDomainNameV6) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, false, false, D2ClientConfig::RCM_WHEN_PRESENT, - "prefix", "suffix.com"))); + "prefix", "suffix.com", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode()); @@ -1015,7 +1042,7 @@ TEST(D2ClientMgr, adjustFqdnFlagsV6) { 1024, dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON, false, true, false, D2ClientConfig::RCM_NEVER, - "pre-fix", "suf-fix"))); + "pre-fix", "suf-fix", "", ""))); ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg)); ASSERT_TRUE(mgr.ddnsEnabled()); ASSERT_TRUE(cfg->getOverrideNoUpdate()); diff --git a/src/lib/dhcpsrv/tests/d2_udp_unittest.cc b/src/lib/dhcpsrv/tests/d2_udp_unittest.cc index beb9bccdc7..333a368759 100644 --- a/src/lib/dhcpsrv/tests/d2_udp_unittest.cc +++ b/src/lib/dhcpsrv/tests/d2_udp_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -76,7 +76,7 @@ public: D2ClientConfig::DFT_MAX_QUEUE_SIZE, protocol, dhcp_ddns::FMT_JSON, true, true, true, D2ClientConfig::RCM_WHEN_PRESENT, - "myhost", ".example.com."))); + "myhost", ".example.com.", "", ""))); ASSERT_NO_THROW(setD2ClientConfig(new_cfg)); ASSERT_TRUE(ddnsEnabled()); diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index e61df2a400..8a4791ae46 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -1870,6 +1870,8 @@ TEST_F(ParseConfigTest, validD2Config) { " \"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\" } " " }" "}"; @@ -1925,6 +1927,8 @@ TEST_F(ParseConfigTest, validD2Config) { " \"replace-client-name\" : \"never\", " " \"generated-prefix\" : \"\", " " \"qualifying-suffix\" : \"\", " + " \"hostname-char-set\" : \"[^A-Z]\", " + " \"hostname-char-replacement\" : \"*\", " " \"user-context\": { \"foo\": \"bar\" } " " }" "}";