Commit 1a04bbea authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[master] Merge branch 'trac3765'

parents bde28351 ea2f6751
......@@ -188,12 +188,21 @@ D2ClientMgr::qualifyName(const std::string& partial_name,
const bool trailing_dot) const {
std::ostringstream gen_name;
gen_name << partial_name << "." << d2_client_config_->getQualifyingSuffix();
gen_name << partial_name;
if (!d2_client_config_->getQualifyingSuffix().empty()) {
std::string str = gen_name.str();
size_t len = str.length();
if ((len > 0) && (str[len - 1] != '.')) {
gen_name << ".";
}
gen_name << d2_client_config_->getQualifyingSuffix();
}
std::string str = gen_name.str();
size_t len = str.length();
if(trailing_dot) {
if (trailing_dot) {
// If trailing dot should be added but there is no trailing dot,
// append it.
if ((len > 0) && (str[len - 1] != '.')) {
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -187,8 +187,10 @@ public:
/// <partial_name>.<qualifying-suffix>.
///
/// @param partial_name domain name to qualify
/// @param trailing_dot A boolean value which indicates whether trailing
/// dot should be appended (if true) or not (false).
/// @param trailing_dot A boolean value which when true guarantees the
/// result will end with a "." and when false that the result will not
/// end with a "." Note that this rule is applied even if the qualifying
/// suffix itself is empty (i.e. "").
///
/// @return std::string containing the qualified name.
std::string qualifyName(const std::string& partial_name,
......
// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -614,7 +614,7 @@ TEST(D2ClientMgr, qualifyName) {
// Verify that the qualifying suffix gets appended with trailing dot added.
std::string partial_name = "somehost";
std::string qualified_name = mgr.qualifyName(partial_name,true);
std::string qualified_name = mgr.qualifyName(partial_name, true);
EXPECT_EQ("somehost.suffix.com.", qualified_name);
......@@ -628,7 +628,7 @@ TEST(D2ClientMgr, qualifyName) {
"prefix", "suffix.com")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
qualified_name = mgr.qualifyName(partial_name,false); //false means no dot
qualified_name = mgr.qualifyName(partial_name, false); //false means no dot
EXPECT_EQ("somehost.suffix.com", qualified_name);
......@@ -642,7 +642,7 @@ TEST(D2ClientMgr, qualifyName) {
"prefix", ""))); //empty suffix
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
partial_name = "somehost";
qualified_name = mgr.qualifyName(partial_name,false); //false means no dot
qualified_name = mgr.qualifyName(partial_name, false); //false means no dot
EXPECT_EQ("somehost", qualified_name);
// Verify that the qualifying suffix gets appended with trailing dot added.
......@@ -656,8 +656,44 @@ TEST(D2ClientMgr, qualifyName) {
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
// Verify that the qualifying suffix gets appended without dot added.
qualified_name = mgr.qualifyName(partial_name,true);
qualified_name = mgr.qualifyName(partial_name, true);
EXPECT_EQ("somehost.hasdot.com.", qualified_name);
// Verify that the qualifying suffix gets appended without an
// extraneous dot when partial_name ends with a "."
qualified_name = mgr.qualifyName("somehost.", true);
EXPECT_EQ("somehost.hasdot.com.", qualified_name);
// Reconfigure to a "" suffix
ASSERT_NO_THROW(cfg.reset(new D2ClientConfig(true,
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,
false, false, true, false,
"prefix", "")));
ASSERT_NO_THROW(mgr.setD2ClientConfig(cfg));
// Verify that a name with a trailing dot does not get an extraneous
// dot when the suffix is blank
qualified_name = mgr.qualifyName("somehost.", true);
EXPECT_EQ("somehost.", qualified_name);
// Verify that a name with no trailing dot gets just a dot when the
// suffix is blank
qualified_name = mgr.qualifyName("somehost", true);
EXPECT_EQ("somehost.", qualified_name);
// Verify that a name with no trailing dot does not get dotted when the
// suffix is blank and trailing dot is false
qualified_name = mgr.qualifyName("somehost", false);
EXPECT_EQ("somehost", qualified_name);
// Verify that a name with trailing dot gets "undotted" when the
// suffix is blank and trailing dot is false
qualified_name = mgr.qualifyName("somehost.", false);
EXPECT_EQ("somehost", qualified_name);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment