2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[4259] Converted replace-client-name from boolean to enumeration

The D2 client configuration parameter, replace-client-name, was
    changed from a boolean, to an enumerated list of modes:

        "NEVER" - do not alter or supply the client name
        "ALWAYS" - always replace the client name, or supply it if
         not sent by the client
        "WHEN_PRESENT" - replace the client name sent by the client,
         do not supply one otherwise
        "WHEN_NOT_PRESENT" - supply the client name only if one was
        not sent by the client

    src/lib/dhcpsrv/d2_client_cfg.cc
    src/lib/dhcpsrv/d2_client_cfg.h
        Added the D2ClientConfig::ReplaceClientNameMode enumeration.

    src/lib/dhcpsrv/parsers/dhcp_parsers.cc
        - Alter replace-client-name parsing to parse the mode labels.
        - Maps boolean literals true and false to RCM_WHEN_PRESENT and
        RCM_NEVER respectively

    src/bin/dhcp4/dhcp6_srv.cc
    src/bin/dhcp4/dhcp4_srv.cc
    src/lib/dhcpsrv/d2_client_mgr.h
        - Adapted to use the enumeration

    src/bin/dhcp4/tests/config_parser_unittest.cc
    src/bin/dhcp4/tests/fqdn_unittest.cc
    src/bin/dhcp6/tests/config_parser_unittest.cc
    src/bin/dhcp6/tests/fqdn_unittest.cc
    src/lib/dhcpsrv/tests/cfgmgr_unittest.cc
    src/lib/dhcpsrv/tests/d2_client_unittest.cc
    src/lib/dhcpsrv/tests/d2_udp_unittest.cc
    src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
        - Alter existing tests to use the enumeration. Note false was replaced
        with RCM_NEVER and true with RCM_WHEN_PRESENT
This commit is contained in:
Thomas Markwalder
2016-04-04 07:18:24 -04:00
parent 849439da6c
commit d80e28d309
13 changed files with 209 additions and 108 deletions

View File

@@ -1196,8 +1196,8 @@ Dhcpv4Srv::processHostnameOption(Dhcpv4Exchange& ex) {
opt_hostname_resp->setValue(d2_mgr.qualifyName(ex.getContext()->host_->getHostname(),
false));
} else if ((d2_mgr.getD2ClientConfig()->getReplaceClientName()) ||
(label_count < 2)) {
} else if ((d2_mgr.getD2ClientConfig()->getReplaceClientNameMode()
!= D2ClientConfig::RCM_NEVER) || (label_count < 2)) {
// Set to root domain to signal later on that we should replace it.
// DHO_HOST_NAME is a string option which cannot be empty.
/// @todo We may want to reconsider whether it is appropriate for the

View File

@@ -3176,7 +3176,7 @@ TEST_F(Dhcp4ParserTest, d2ClientConfig) {
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : true, "
" \"replace-client-name\" : \"WHEN_PRESENT\", "
" \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" },"
"\"valid-lifetime\": 4000 }";
@@ -3210,7 +3210,7 @@ TEST_F(Dhcp4ParserTest, d2ClientConfig) {
EXPECT_TRUE(d2_client_config->getAlwaysIncludeFqdn());
EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
EXPECT_TRUE(d2_client_config->getReplaceClientName());
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());
}
@@ -3238,7 +3238,7 @@ TEST_F(Dhcp4ParserTest, invalidD2ClientConfig) {
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : true, "
" \"replace-client-name\" : \"WHEN_PRESENT\", "
" \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" },"
"\"valid-lifetime\": 4000 }";

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
@@ -172,7 +172,8 @@ public:
(mask & ALWAYS_INCLUDE_FQDN),
(mask & OVERRIDE_NO_UPDATE),
(mask & OVERRIDE_CLIENT_UPDATE),
(mask & REPLACE_CLIENT_NAME),
((mask & REPLACE_CLIENT_NAME) ?
D2ClientConfig::RCM_WHEN_PRESENT : D2ClientConfig::RCM_NEVER),
"myhost", "example.com")));
ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(cfg));
ASSERT_NO_THROW(srv_->startD2());

View File

@@ -3410,7 +3410,7 @@ TEST_F(Dhcp6ParserTest, d2ClientConfig) {
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : true, "
" \"replace-client-name\" : \"WHEN_PRESENT\", "
" \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" },"
"\"valid-lifetime\": 4000 }";
@@ -3444,7 +3444,7 @@ TEST_F(Dhcp6ParserTest, d2ClientConfig) {
EXPECT_TRUE(d2_client_config->getAlwaysIncludeFqdn());
EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
EXPECT_TRUE(d2_client_config->getReplaceClientName());
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());
}
@@ -3472,7 +3472,7 @@ TEST_F(Dhcp6ParserTest, invalidD2ClientConfig) {
" \"allow-client-update\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : true, "
" \"replace-client-name\" : \"WHEN_PRESENT\", "
" \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" },"
"\"valid-lifetime\": 4000 }";

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
@@ -112,7 +112,8 @@ public:
(mask & ALWAYS_INCLUDE_FQDN),
(mask & OVERRIDE_NO_UPDATE),
(mask & OVERRIDE_CLIENT_UPDATE),
(mask & REPLACE_CLIENT_NAME),
((mask & REPLACE_CLIENT_NAME) ? D2ClientConfig::RCM_WHEN_PRESENT
: D2ClientConfig::RCM_NEVER),
"myhost", "example.com")));
ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(cfg));
ASSERT_NO_THROW(srv_->startD2());
@@ -731,7 +732,7 @@ TEST_F(FqdnDhcpv6SrvTest, createRemovalNameChangeRequestFwdRev) {
}
// Checks that calling queueNCR would not result in error if DDNS updates are
// disabled.
// disabled.
TEST_F(FqdnDhcpv6SrvTest, noRemovalsWhenDisabled) {
// Disable DDNS updates.
disableD2();

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
@@ -10,6 +10,8 @@
#include <dhcpsrv/d2_client_cfg.h>
#include <dhcpsrv/dhcpsrv_log.h>
#include <boost/algorithm/string/predicate.hpp>
#include <string>
using namespace std;
@@ -17,19 +19,60 @@ using namespace std;
namespace isc {
namespace dhcp {
const char *D2ClientConfig::DFT_SERVER_IP = "127.0.0.1";
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";
const char *D2ClientConfig::DFT_V6_SENDER_IP = "::";
const char* D2ClientConfig::DFT_V4_SENDER_IP = "0.0.0.0";
const char* D2ClientConfig::DFT_V6_SENDER_IP = "::";
const size_t D2ClientConfig::DFT_SENDER_PORT = 0;
const size_t D2ClientConfig::DFT_MAX_QUEUE_SIZE = 1024;
const char *D2ClientConfig::DFT_NCR_PROTOCOL = "UDP";
const char *D2ClientConfig::DFT_NCR_FORMAT = "JSON";
const char* D2ClientConfig::DFT_NCR_PROTOCOL = "UDP";
const char* D2ClientConfig::DFT_NCR_FORMAT = "JSON";
const bool D2ClientConfig::DFT_ALWAYS_INCLUDE_FQDN = false;
const bool D2ClientConfig::DFT_OVERRIDE_NO_UPDATE = false;
const bool D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE = false;
const bool D2ClientConfig::DFT_REPLACE_CLIENT_NAME = false;
const char *D2ClientConfig::DFT_GENERATED_PREFIX = "myhost";
const char* D2ClientConfig::DFT_REPLACE_CLIENT_NAME_MODE = "NEVER";
const char* D2ClientConfig::DFT_GENERATED_PREFIX = "myhost";
D2ClientConfig::ReplaceClientNameMode stringToReplaceClientNameMode(const std::string& mode_str) {
if (boost::iequals(mode_str, "NEVER")) {
return (D2ClientConfig::RCM_NEVER);
}
if (boost::iequals(mode_str, "ALWAYS")) {
return (D2ClientConfig::RCM_ALWAYS);
}
if (boost::iequals(mode_str, "WHEN_PRESENT")) {
return (D2ClientConfig::RCM_WHEN_PRESENT);
}
if (boost::iequals(mode_str, "WHEN_NOT_PRESENT")) {
return (D2ClientConfig::RCM_WHEN_NOT_PRESENT);
}
isc_throw(BadValue,
"Invalid ReplaceClientNameMode: " << mode_str);
}
std::string replaceClientNameModeToString(D2ClientConfig::ReplaceClientNameMode mode) {
switch (mode) {
case D2ClientConfig::RCM_NEVER:
return ("NEVER");
case D2ClientConfig::RCM_ALWAYS:
return ("ALWAYS");
case D2ClientConfig::RCM_WHEN_PRESENT:
return ("WHEN_PRESENT");
case D2ClientConfig::RCM_WHEN_NOT_PRESENT:
return ("WHEN_NOT_PRESENT");
default:
break;
}
std::ostringstream stream;
stream << "UNKNOWN(" << mode << ")";
return (stream.str());
}
D2ClientConfig::D2ClientConfig(const bool enable_updates,
const isc::asiolink::IOAddress& server_ip,
@@ -44,7 +87,7 @@ D2ClientConfig::D2ClientConfig(const bool enable_updates,
const bool always_include_fqdn,
const bool override_no_update,
const bool override_client_update,
const bool replace_client_name,
const ReplaceClientNameMode replace_client_name_mode,
const std::string& generated_prefix,
const std::string& qualifying_suffix)
: enable_updates_(enable_updates),
@@ -58,7 +101,7 @@ D2ClientConfig::D2ClientConfig(const bool enable_updates,
always_include_fqdn_(always_include_fqdn),
override_no_update_(override_no_update),
override_client_update_(override_client_update),
replace_client_name_(replace_client_name),
replace_client_name_mode_(replace_client_name_mode),
generated_prefix_(generated_prefix),
qualifying_suffix_(qualifying_suffix) {
validateContents();
@@ -76,7 +119,7 @@ D2ClientConfig::D2ClientConfig()
always_include_fqdn_(DFT_ALWAYS_INCLUDE_FQDN),
override_no_update_(DFT_OVERRIDE_NO_UPDATE),
override_client_update_(DFT_OVERRIDE_CLIENT_UPDATE),
replace_client_name_(DFT_REPLACE_CLIENT_NAME),
replace_client_name_mode_(stringToReplaceClientNameMode(DFT_REPLACE_CLIENT_NAME_MODE)),
generated_prefix_(DFT_GENERATED_PREFIX),
qualifying_suffix_("") {
validateContents();
@@ -134,7 +177,7 @@ D2ClientConfig::operator == (const D2ClientConfig& other) const {
(always_include_fqdn_ == other.always_include_fqdn_) &&
(override_no_update_ == other.override_no_update_) &&
(override_client_update_ == other.override_client_update_) &&
(replace_client_name_ == other.replace_client_name_) &&
(replace_client_name_mode_ == other.replace_client_name_mode_) &&
(generated_prefix_ == other.generated_prefix_) &&
(qualifying_suffix_ == other.qualifying_suffix_));
}
@@ -155,16 +198,16 @@ D2ClientConfig::toText() const {
<< ", sender_ip: " << sender_ip_.toText()
<< ", sender_port: " << sender_port_
<< ", max_queue_size: " << max_queue_size_
<< ", ncr_protocol: " << ncr_protocol_
<< ", ncr_format: " << ncr_format_
<< ", ncr_protocol: " << ncrProtocolToString(ncr_protocol_)
<< ", ncr_format: " << ncrFormatToString(ncr_format_)
<< ", always_include_fqdn: " << (always_include_fqdn_ ?
"yes" : "no")
<< ", override_no_update: " << (override_no_update_ ?
"yes" : "no")
<< ", override_client_update: " << (override_client_update_ ?
"yes" : "no")
<< ", replace_client_name: " << (replace_client_name_ ?
"yes" : "no")
<< ", replace_client_name: "
<< replaceClientNameModeToString(replace_client_name_mode_)
<< ", generated_prefix: [" << generated_prefix_ << "]"
<< ", qualifying_suffix: [" << qualifying_suffix_ << "]";
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
@@ -39,6 +39,7 @@ public:
: isc::Exception(file, line, what) {}
};
/// @brief Acts as a storage vault for D2 client configuration
///
/// A simple container class for storing and retrieving the configuration
@@ -47,24 +48,30 @@ public:
///
class D2ClientConfig {
public:
/// @brief Default configuration constants.
/// @todo For now these are hard-coded as configuraiton layer cannot
/// readily provide them (see Trac #3358).
static const char *DFT_SERVER_IP;
static const char* DFT_SERVER_IP;
static const size_t DFT_SERVER_PORT;
static const char *DFT_V4_SENDER_IP;
static const char *DFT_V6_SENDER_IP;
static const char* DFT_V4_SENDER_IP;
static const char* DFT_V6_SENDER_IP;
static const size_t DFT_SENDER_PORT;
static const size_t DFT_MAX_QUEUE_SIZE;
static const char *DFT_NCR_PROTOCOL;
static const char *DFT_NCR_FORMAT;
static const char* DFT_NCR_PROTOCOL;
static const char* DFT_NCR_FORMAT;
static const bool DFT_ALWAYS_INCLUDE_FQDN;
static const bool DFT_OVERRIDE_NO_UPDATE;
static const bool DFT_OVERRIDE_CLIENT_UPDATE;
static const bool DFT_REPLACE_CLIENT_NAME;
static const char *DFT_GENERATED_PREFIX;
static const char* DFT_REPLACE_CLIENT_NAME_MODE;
static const char* DFT_GENERATED_PREFIX;
/// @brief Defines the client name replacement modes.
enum ReplaceClientNameMode {
RCM_NEVER,
RCM_ALWAYS,
RCM_WHEN_PRESENT,
RCM_WHEN_NOT_PRESENT
};
/// @brief Constructor
///
@@ -84,7 +91,7 @@ public:
/// updates.
/// @param override_client_update Perform updates, even if client requested
/// delegation.
/// @param replace_client_name enables replacement of the domain-name
/// @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.
@@ -104,7 +111,7 @@ public:
const bool always_include_fqdn,
const bool override_no_update,
const bool override_client_update,
const bool replace_client_name,
const ReplaceClientNameMode replace_client_name_mode,
const std::string& generated_prefix,
const std::string& qualifying_suffix);
@@ -170,9 +177,9 @@ public:
return(override_client_update_);
}
/// @brief Return whether or not client's domain-name is always replaced.
bool getReplaceClientName() const {
return(replace_client_name_);
/// @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.
@@ -248,8 +255,8 @@ private:
/// @brief Should Kea perform updates, even if client requested delegation.
bool override_client_update_;
/// @brief Should Kea replace the domain-name supplied by the client.
bool replace_client_name_;
/// @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_;
@@ -261,6 +268,26 @@ private:
std::ostream&
operator<<(std::ostream& os, const D2ClientConfig& config);
/// @brief Function which converts labels to ReplaceClientNameMode enum values.
///
/// @param mode_str text to convert to an enum.
/// Valid string values: "NEVER", "ALWAYS", "WHEN_PRESENT", "WHEN_NOT_PRESENT"
///
/// @return NameChangeFormat value which maps to the given string.
///
/// @throw isc::BadValue if given a string value which does not map to an
/// enum value.
extern D2ClientConfig::ReplaceClientNameMode stringToReplaceClientNameMode(const std::string& mode_str);
/// @brief Function which converts NameChangeFormat enums to text labels.
///
/// @param mode enum value to convert to label
///
/// @return std:string containing the text label if the value is valid, or
/// "UNKNOWN" if not.
extern std::string replaceClientNameModeToString(D2ClientConfig::ReplaceClientNameMode mode);
/// @brief Defines a pointer for D2ClientConfig instances.
typedef boost::shared_ptr<D2ClientConfig> D2ClientConfigPtr;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2016 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
@@ -457,7 +457,7 @@ void
D2ClientMgr::adjustDomainName(const T& fqdn, T& fqdn_resp) {
// If we're configured to replace it or the supplied name is blank
// set the response name to blank.
if (d2_client_config_->getReplaceClientName() ||
if ((d2_client_config_->getReplaceClientNameMode() != D2ClientConfig::RCM_NEVER) ||
fqdn.getDomainName().empty()) {
fqdn_resp.setDomainName("", T::PARTIAL);
} else {

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
@@ -1406,10 +1406,22 @@ D2ClientConfigParser::build(isc::data::ConstElementPtr client_config) {
D2ClientConfig::
DFT_OVERRIDE_CLIENT_UPDATE);
bool replace_client_name =
boolean_values_->getOptionalParam("replace-client-name",
D2ClientConfig::
DFT_REPLACE_CLIENT_NAME);
// Formerly, replace-client-name was boolean, so for now we'll support boolean
// values by mapping them to the appropriate mode
D2ClientConfig::ReplaceClientNameMode replace_client_name_mode;
std::string mode_str = string_values_->getOptionalParam("replace-client-name",
D2ClientConfig::
DFT_REPLACE_CLIENT_NAME_MODE);
if (boost::iequals(mode_str, "FALSE")) {
// @todo add a debug log
replace_client_name_mode = D2ClientConfig::RCM_NEVER;
}
else if (boost::iequals(mode_str, "TRUE")) {
// @todo add a debug log
replace_client_name_mode = D2ClientConfig::RCM_WHEN_PRESENT;
} else {
replace_client_name_mode = stringToReplaceClientNameMode(mode_str);
}
// Attempt to create the new client config.
local_client_config_.reset(new D2ClientConfig(enable_updates,
@@ -1423,7 +1435,7 @@ D2ClientConfigParser::build(isc::data::ConstElementPtr client_config) {
always_include_fqdn,
override_no_update,
override_client_update,
replace_client_name,
replace_client_name_mode,
generated_prefix,
qualifying_suffix));
@@ -1445,14 +1457,14 @@ D2ClientConfigParser::createConfigParser(const std::string& config_id) {
(config_id.compare("ncr-format") == 0) ||
(config_id.compare("generated-prefix") == 0) ||
(config_id.compare("sender-ip") == 0) ||
(config_id.compare("qualifying-suffix") == 0)) {
(config_id.compare("qualifying-suffix") == 0) ||
(config_id.compare("replace-client-name") == 0)) {
parser = new StringParser(config_id, string_values_);
} else if ((config_id.compare("enable-updates") == 0) ||
(config_id.compare("always-include-fqdn") == 0) ||
(config_id.compare("allow-client-update") == 0) ||
(config_id.compare("override-no-update") == 0) ||
(config_id.compare("override-client-update") == 0) ||
(config_id.compare("replace-client-name") == 0)) {
(config_id.compare("override-client-update") == 0)) {
parser = new BooleanParser(config_id, boolean_values_);
} else {
isc_throw(NotImplemented,

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2016 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
@@ -405,7 +405,7 @@ TEST_F(CfgMgrTest, d2ClientConfig) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
true, true, true, true,
true, true, true, D2ClientConfig::RCM_ALWAYS,
"pre-fix", "suf-fix")));
// Verify that we can assign a new, non-empty configuration.

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2016 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
@@ -20,6 +20,22 @@ using namespace isc;
namespace {
/// @brief Tests conversion of NameChangeFormat between enum and strings.
TEST(ReplaceClientNameModeTest, formatEnumConversion){
ASSERT_EQ(stringToReplaceClientNameMode("NEVER"), D2ClientConfig::RCM_NEVER);
ASSERT_EQ(stringToReplaceClientNameMode("ALWAYS"), D2ClientConfig::RCM_ALWAYS);
ASSERT_EQ(stringToReplaceClientNameMode("WHEN_PRESENT"), D2ClientConfig::RCM_WHEN_PRESENT);
ASSERT_EQ(stringToReplaceClientNameMode("WHEN_NOT_PRESENT"),
D2ClientConfig::RCM_WHEN_NOT_PRESENT);
ASSERT_THROW(stringToReplaceClientNameMode("BOGUS"), isc::BadValue);
ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_NEVER), "NEVER");
ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_ALWAYS), "ALWAYS");
ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_WHEN_PRESENT), "WHEN_PRESENT");
ASSERT_EQ(replaceClientNameModeToString(D2ClientConfig::RCM_WHEN_NOT_PRESENT),
"WHEN_NOT_PRESENT");
}
/// @brief Checks constructors and accessors of D2ClientConfig.
TEST(D2ClientConfigTest, constructorsAndAccessors) {
D2ClientConfigPtr d2_client_config;
@@ -47,7 +63,8 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
bool always_include_fqdn = true;
bool override_no_update = true;
bool override_client_update = true;
bool replace_client_name = true;
D2ClientConfig::ReplaceClientNameMode replace_client_name_mode = D2ClientConfig::
RCM_WHEN_PRESENT;
std::string generated_prefix = "the_prefix";
std::string qualifying_suffix = "the.suffix.";
@@ -63,8 +80,8 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
ncr_format,
always_include_fqdn,
override_no_update,
override_client_update,
replace_client_name,
override_client_update,
replace_client_name_mode,
generated_prefix,
qualifying_suffix)));
@@ -84,7 +101,7 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
EXPECT_EQ(d2_client_config->getOverrideNoUpdate(), override_no_update);
EXPECT_EQ(d2_client_config->getOverrideClientUpdate(),
override_client_update);
EXPECT_EQ(d2_client_config->getReplaceClientName(), replace_client_name);
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);
@@ -106,7 +123,7 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
always_include_fqdn,
override_no_update,
override_client_update,
replace_client_name,
replace_client_name_mode,
generated_prefix,
qualifying_suffix)),
D2ClientError);
@@ -127,7 +144,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(ref_config);
@@ -135,7 +152,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_TRUE(*ref_config == *test_config);
@@ -145,7 +162,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -155,7 +172,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -165,7 +182,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -175,7 +192,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -185,7 +202,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -195,7 +212,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -205,7 +222,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
false, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -215,7 +232,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true, true,
true, false, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -225,7 +242,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, false, true,
true, true, false, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -235,7 +252,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, false,
true, true, true, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -245,7 +262,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"bogus", "suf-fix")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -255,7 +272,7 @@ TEST(D2ClientConfigTest, equalityOperator) {
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, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "bogus")));
ASSERT_TRUE(test_config);
EXPECT_FALSE(*ref_config == *test_config);
@@ -300,7 +317,7 @@ TEST(D2ClientMgr, validConfig) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
true, true, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"pre-fix", "suf-fix")));
// Verify that we can assign a new, non-empty configuration.
@@ -344,7 +361,7 @@ TEST(D2ClientMgr, analyzeFqdnInvalidCombination) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, false,
false, false, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
@@ -368,7 +385,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledNoOverrides) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, false,
false, false, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
@@ -412,7 +429,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledOverrideNoUpdate) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, true, false, false,
false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
@@ -455,7 +472,7 @@ TEST(D2ClientMgr, analyzeFqdnEnabledOverrideClientUpdate) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
@@ -499,7 +516,7 @@ TEST(D2ClientMgr, adjustFqdnFlagsV4) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, true, false, false,
false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());
@@ -600,7 +617,7 @@ TEST(D2ClientMgr, qualifyName) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
@@ -616,7 +633,7 @@ TEST(D2ClientMgr, qualifyName) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
@@ -630,7 +647,7 @@ TEST(D2ClientMgr, qualifyName) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", ""))); //empty suffix
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
@@ -643,7 +660,7 @@ TEST(D2ClientMgr, qualifyName) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "hasdot.com.")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
@@ -662,7 +679,7 @@ TEST(D2ClientMgr, qualifyName) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
@@ -700,7 +717,7 @@ TEST(D2ClientMgr, generateFqdn) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, true, false,
false, false, true, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
@@ -734,10 +751,10 @@ TEST(D2ClientMgr, adjustDomainNameV4) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, false,
false, false, false, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_FALSE(cfg->getReplaceClientName());
ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode());
// replace-client-name is false, client passes in empty fqdn
// reponse domain should be empty/partial.
@@ -777,10 +794,10 @@ TEST(D2ClientMgr, adjustDomainNameV4) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, true,
false, false, false, D2ClientConfig::RCM_WHEN_PRESENT,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(cfg->getReplaceClientName());
ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode());
// replace-client-name is true, client passes in empty fqdn
// reponse domain should be empty/partial.
@@ -827,10 +844,10 @@ TEST(D2ClientMgr, adjustDomainNameV6) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, false,
false, false, false, D2ClientConfig::RCM_NEVER,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_FALSE(cfg->getReplaceClientName());
ASSERT_EQ(D2ClientConfig::RCM_NEVER, cfg->getReplaceClientNameMode());
// replace-client-name is false, client passes in empty fqdn
// reponse domain should be empty/partial.
@@ -867,10 +884,10 @@ TEST(D2ClientMgr, adjustDomainNameV6) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, false, false, true,
false, false, false, D2ClientConfig::RCM_WHEN_PRESENT,
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(cfg->getReplaceClientName());
ASSERT_EQ(D2ClientConfig::RCM_WHEN_PRESENT, cfg->getReplaceClientNameMode());
// replace-client-name is true, client passes in empty fqdn
// reponse domain should be empty/partial.
@@ -917,7 +934,7 @@ TEST(D2ClientMgr, adjustFqdnFlagsV6) {
isc::asiolink::IOAddress("127.0.0.1"), 478,
1024,
dhcp_ddns::NCR_UDP, dhcp_ddns::FMT_JSON,
false, true, false, false,
false, true, false, D2ClientConfig::RCM_NEVER,
"pre-fix", "suf-fix")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
ASSERT_TRUE(mgr.ddnsEnabled());

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2016 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:
sender_ip, D2ClientConfig::DFT_SENDER_PORT,
D2ClientConfig::DFT_MAX_QUEUE_SIZE,
protocol, dhcp_ddns::FMT_JSON,
true, true, true, true,
true, true, true, D2ClientConfig::RCM_WHEN_PRESENT,
"myhost", ".example.com.")));
ASSERT_NO_THROW(setD2ClientConfig(new_cfg));

View File

@@ -1391,7 +1391,7 @@ TEST_F(ParseConfigTest, validD2Config) {
" \"always-include-fqdn\" : true, "
" \"override-no-update\" : true, "
" \"override-client-update\" : true, "
" \"replace-client-name\" : true, "
" \"replace-client-name\" : \"WHEN_PRESENT\", "
" \"generated-prefix\" : \"test.prefix\", "
" \"qualifying-suffix\" : \"test.suffix.\" "
" }"
@@ -1416,7 +1416,7 @@ TEST_F(ParseConfigTest, validD2Config) {
EXPECT_TRUE(d2_client_config->getAlwaysIncludeFqdn());
EXPECT_TRUE(d2_client_config->getOverrideNoUpdate());
EXPECT_TRUE(d2_client_config->getOverrideClientUpdate());
EXPECT_TRUE(d2_client_config->getReplaceClientName());
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());
@@ -1437,7 +1437,7 @@ TEST_F(ParseConfigTest, validD2Config) {
" \"always-include-fqdn\" : false, "
" \"override-no-update\" : false, "
" \"override-client-update\" : false, "
" \"replace-client-name\" : false, "
" \"replace-client-name\" : \"NEVER\", "
" \"generated-prefix\" : \"\", "
" \"qualifying-suffix\" : \"\" "
" }"
@@ -1461,7 +1461,7 @@ TEST_F(ParseConfigTest, validD2Config) {
EXPECT_FALSE(d2_client_config->getAlwaysIncludeFqdn());
EXPECT_FALSE(d2_client_config->getOverrideNoUpdate());
EXPECT_FALSE(d2_client_config->getOverrideClientUpdate());
EXPECT_FALSE(d2_client_config->getReplaceClientName());
EXPECT_EQ(D2ClientConfig::RCM_NEVER, d2_client_config->getReplaceClientNameMode());
EXPECT_EQ("", d2_client_config->getGeneratedPrefix());
EXPECT_EQ("", d2_client_config->getQualifyingSuffix());
}
@@ -1533,8 +1533,8 @@ TEST_F(ParseConfigTest, parserDefaultsD2Config) {
d2_client_config->getOverrideNoUpdate());
EXPECT_EQ(D2ClientConfig::DFT_OVERRIDE_CLIENT_UPDATE,
d2_client_config->getOverrideClientUpdate());
EXPECT_EQ(D2ClientConfig::DFT_REPLACE_CLIENT_NAME,
d2_client_config->getReplaceClientName());
EXPECT_EQ(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.",