"override-client-update" : true,
"replace-client-name" : "when-present",
"generated-prefix" : "test.prefix",
- "qualifying-suffix" : "test.suffix."
+ "qualifying-suffix" : "test.suffix.",
+ "hostname-char-set": "[^A-Za-z0-9.-]",
+ "hostname-char-replacement": "x"
}
},
"override-client-update" : true,
"replace-client-name" : "when-present",
"generated-prefix" : "test.prefix",
- "qualifying-suffix" : "test.suffix."
+ "qualifying-suffix" : "test.suffix.",
+ "hostname-char-set": "[^A-Za-z0-9.-]",
+ "hostname-char-replacement": "x"
}
},
Pkt4Ptr resp;
OptionStringPtr hostname;
- for (auto scenario = scenarios.begin(); scenario != scenarios.end(); ++scenario) {
- SCOPED_TRACE((*scenario).description_);
+ for (auto scenario : scenarios) {
+ SCOPED_TRACE((scenario).description_);
{
- // Set the hostname option.
- ASSERT_NO_THROW(client.includeHostname((*scenario).original_));
-
- // Send the DHCPDISCOVER and make sure that the server responded.
- ASSERT_NO_THROW(client.doDiscover());
- resp = client.getContext().response_;
- ASSERT_TRUE(resp);
- ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
-
- // Make sure the response hostname is what we expect.
- hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME));
- ASSERT_TRUE(hostname);
- EXPECT_EQ((*scenario).sanitized_, hostname->getValue());
+ // Set the hostname option.
+ ASSERT_NO_THROW(client.includeHostname((scenario).original_));
+
+ // Send the DHCPDISCOVER and make sure that the server responded.
+ ASSERT_NO_THROW(client.doDiscover());
+ resp = client.getContext().response_;
+ ASSERT_TRUE(resp);
+ ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
+
+ // Make sure the response hostname is what we expect.
+ hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME));
+ ASSERT_TRUE(hostname);
+ EXPECT_EQ((scenario).sanitized_, hostname->getValue());
}
}
}
std::vector<Scenario> scenarios = {
{
- "full FQDN, name unchanged",
- "One.123.example.com.",
- Option6ClientFqdn::FULL,
- "one.123.example.com."
+ "full FQDN, name unchanged",
+ "One.123.example.com.",
+ Option6ClientFqdn::FULL,
+ "one.123.example.com."
},
{
- "partial FQDN, name unchanged, but qualified",
- "One.123",
- Option6ClientFqdn::PARTIAL,
- "one.123.suffix.com."
+ "partial FQDN, name unchanged, but qualified",
+ "One.123",
+ Option6ClientFqdn::PARTIAL,
+ "one.123.suffix.com."
},
{
- "full FQDN, scrubbed",
- "O#n^e.123.ex&a*mple.com.",
- Option6ClientFqdn::FULL,
- "oxnxe.123.exxaxmple.com."
+ "full FQDN, scrubbed",
+ "O#n^e.123.ex&a*mple.com.",
+ Option6ClientFqdn::FULL,
+ "oxnxe.123.exxaxmple.com."
},
{
- "partial FQDN, scrubbed and qualified",
- "One.1+2|3",
- Option6ClientFqdn::PARTIAL,
- "one.1x2x3.suffix.com."
+ "partial FQDN, scrubbed and qualified",
+ "One.1+2|3",
+ Option6ClientFqdn::PARTIAL,
+ "one.1x2x3.suffix.com."
},
{
- "full FQDN with characters that get escaped",
- "O n e.123.exa(m)ple.com.",
- Option6ClientFqdn::FULL,
- "oxnxe.123.exaxmxple.com."
+ "full FQDN with characters that get escaped",
+ "O n e.123.exa(m)ple.com.",
+ Option6ClientFqdn::FULL,
+ "oxnxe.123.exaxmxple.com."
},
{
- "full FQDN with escape sequences",
- "O\032n\032e.123.example.com.",
- Option6ClientFqdn::FULL,
- "oxnxe.123.example.com."
+ "full FQDN with escape sequences",
+ "O\032n\032e.123.example.com.",
+ Option6ClientFqdn::FULL,
+ "oxnxe.123.example.com."
}
};
LabelSequence l(n);
EXPECT_EQ("a bc.$exa(m)ple.@org", l.toRawText(true));
EXPECT_EQ("a bc.$exa(m)ple.@org.", l.toRawText(false));
+
+ // toRawText is not supposed to do any sanity checks.
+ // Let's try with a very weird name.
+ Name n2("xtra\tchars\n.in.name");
+ LabelSequence l2(n2);
+ EXPECT_EQ("xtra\tchars\n.in.name.", l2.toRawText(false));
}
// The following are test data used in the getHash test below. Normally
///
/// The implementation uses C++11 regex IF the environemnt supports it
/// (tested in configure.ac). If not it falls back to C lib regcomp/regexec.
-/// Older compilers, such as pre Gnu 4.9.0, provided only experimental
+/// Older compilers, such as pre Gnu g++ 4.9.0, provided only experimental
/// implementations of regex which are recognized as buggy.
class StringSanitizer {
public:
/// Constructor
///
/// Compiles the given character set into a regular expression, and
- /// retains the given character replacement. Thereafter, the instance
+ /// retains the given character replacement. Thereafter, the instance
/// may be used to scrub an arbitrary number of strings.
///
/// @param char_set string containing a regular expression (POSIX
/// Returns a scrubbed copy of a given string
///
- /// Replaces all occurrances of characters described by the regular
- /// expression with the character replacement .
+ /// Replaces all occurrences of characters described by the regular
+ /// expression with the character replacement.
///
/// @param original the string to scrub
/// @throw Unexpected if an error occurs during scrubbing
isc::BadValue);
}
-/// @brief Fucntion used to test StringSantitizer
+/// @brief Function used to test StringSantitizer
/// @param original - string to sanitize
/// @param char_set - regular expression string describing invalid
/// characters
sanitizeStringTest("abc.123", "[b-c2]", "*",
"a**.1*3");
- // Inverted list of valid chars should work: (b,c,2 are invalid)
+ // Inverted list of valid chars should work: (b,c,2 are valid)
sanitizeStringTest("abc.123", "[^b-c2]", "*",
"*bc**2*");
sanitizeStringTest("%%A%%B%%C%%", "[^A-Za-z0-9_]", "x",
"xxAxxBxxCxx");
- // Removing than one non-matching in a row should work.
+ // Removing more than one non-matching in a row should work.
sanitizeStringTest("%%A%%B%%C%%", "[^A-Za-z0-9_]", "",
"ABC");