Commit 32466ab3 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[5680] Changes after review

parent ae906a53
......@@ -54,7 +54,9 @@
"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"
}
},
......
......@@ -56,7 +56,9 @@
"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"
}
},
......
......@@ -1742,22 +1742,22 @@ TEST_F(NameDhcpv4SrvTest, sanitizeHost) {
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());
}
}
}
......
......@@ -1239,40 +1239,40 @@ TEST(D2ClientMgr, sanitizeFqdnV6) {
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."
}
};
......
......@@ -638,6 +638,12 @@ TEST_F(LabelSequenceTest, toRawText) {
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
......
......@@ -263,7 +263,7 @@ class StringSanitizerImpl;
///
/// 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:
......@@ -271,7 +271,7 @@ 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
......@@ -291,8 +291,8 @@ public:
/// 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
......
......@@ -463,7 +463,7 @@ TEST(StringUtilTest, decodeFormattedHexString) {
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
......@@ -507,7 +507,7 @@ TEST(StringUtilTest, stringSanitizer) {
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*");
......@@ -527,7 +527,7 @@ TEST(StringUtilTest, stringSanitizer) {
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");
......
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