2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-02 15:05:16 +00:00

[5680] Changes after review

This commit is contained in:
Tomek Mrugalski
2018-07-27 13:52:14 +02:00
parent ae906a531e
commit 32466ab3d4
7 changed files with 56 additions and 46 deletions

View File

@@ -54,7 +54,9 @@
"override-client-update" : true, "override-client-update" : true,
"replace-client-name" : "when-present", "replace-client-name" : "when-present",
"generated-prefix" : "test.prefix", "generated-prefix" : "test.prefix",
"qualifying-suffix" : "test.suffix." "qualifying-suffix" : "test.suffix.",
"hostname-char-set": "[^A-Za-z0-9.-]",
"hostname-char-replacement": "x"
} }
}, },

View File

@@ -56,7 +56,9 @@
"override-client-update" : true, "override-client-update" : true,
"replace-client-name" : "when-present", "replace-client-name" : "when-present",
"generated-prefix" : "test.prefix", "generated-prefix" : "test.prefix",
"qualifying-suffix" : "test.suffix." "qualifying-suffix" : "test.suffix.",
"hostname-char-set": "[^A-Za-z0-9.-]",
"hostname-char-replacement": "x"
} }
}, },

View File

@@ -1742,11 +1742,11 @@ TEST_F(NameDhcpv4SrvTest, sanitizeHost) {
Pkt4Ptr resp; Pkt4Ptr resp;
OptionStringPtr hostname; OptionStringPtr hostname;
for (auto scenario = scenarios.begin(); scenario != scenarios.end(); ++scenario) { for (auto scenario : scenarios) {
SCOPED_TRACE((*scenario).description_); SCOPED_TRACE((scenario).description_);
{ {
// Set the hostname option. // Set the hostname option.
ASSERT_NO_THROW(client.includeHostname((*scenario).original_)); ASSERT_NO_THROW(client.includeHostname((scenario).original_));
// Send the DHCPDISCOVER and make sure that the server responded. // Send the DHCPDISCOVER and make sure that the server responded.
ASSERT_NO_THROW(client.doDiscover()); ASSERT_NO_THROW(client.doDiscover());
@@ -1757,7 +1757,7 @@ TEST_F(NameDhcpv4SrvTest, sanitizeHost) {
// Make sure the response hostname is what we expect. // Make sure the response hostname is what we expect.
hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME)); hostname = boost::dynamic_pointer_cast<OptionString>(resp->getOption(DHO_HOST_NAME));
ASSERT_TRUE(hostname); ASSERT_TRUE(hostname);
EXPECT_EQ((*scenario).sanitized_, hostname->getValue()); EXPECT_EQ((scenario).sanitized_, hostname->getValue());
} }
} }
} }

View File

@@ -638,6 +638,12 @@ TEST_F(LabelSequenceTest, toRawText) {
LabelSequence l(n); LabelSequence l(n);
EXPECT_EQ("a bc.$exa(m)ple.@org", l.toRawText(true)); EXPECT_EQ("a bc.$exa(m)ple.@org", l.toRawText(true));
EXPECT_EQ("a bc.$exa(m)ple.@org.", l.toRawText(false)); 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 following are test data used in the getHash test below. Normally

View File

@@ -263,7 +263,7 @@ class StringSanitizerImpl;
/// ///
/// The implementation uses C++11 regex IF the environemnt supports it /// 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. /// (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. /// implementations of regex which are recognized as buggy.
class StringSanitizer { class StringSanitizer {
public: public:
@@ -291,7 +291,7 @@ public:
/// Returns a scrubbed copy of a given string /// Returns a scrubbed copy of a given string
/// ///
/// Replaces all occurrances of characters described by the regular /// Replaces all occurrences of characters described by the regular
/// expression with the character replacement. /// expression with the character replacement.
/// ///
/// @param original the string to scrub /// @param original the string to scrub

View File

@@ -463,7 +463,7 @@ TEST(StringUtilTest, decodeFormattedHexString) {
isc::BadValue); isc::BadValue);
} }
/// @brief Fucntion used to test StringSantitizer /// @brief Function used to test StringSantitizer
/// @param original - string to sanitize /// @param original - string to sanitize
/// @param char_set - regular expression string describing invalid /// @param char_set - regular expression string describing invalid
/// characters /// characters
@@ -507,7 +507,7 @@ TEST(StringUtilTest, stringSanitizer) {
sanitizeStringTest("abc.123", "[b-c2]", "*", sanitizeStringTest("abc.123", "[b-c2]", "*",
"a**.1*3"); "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]", "*", sanitizeStringTest("abc.123", "[^b-c2]", "*",
"*bc**2*"); "*bc**2*");
@@ -527,7 +527,7 @@ TEST(StringUtilTest, stringSanitizer) {
sanitizeStringTest("%%A%%B%%C%%", "[^A-Za-z0-9_]", "x", sanitizeStringTest("%%A%%B%%C%%", "[^A-Za-z0-9_]", "x",
"xxAxxBxxCxx"); "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_]", "", sanitizeStringTest("%%A%%B%%C%%", "[^A-Za-z0-9_]", "",
"ABC"); "ABC");