From: Thomas Markwalder Date: Thu, 19 Jul 2018 20:06:29 +0000 (-0400) Subject: [5680] Added unit tests to verify kea-dhcp6 santizes FQDN values X-Git-Tag: ha_phase2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcd08902ca15a0d2461b5659288e5797e344350c;p=thirdparty%2Fkea.git [5680] Added unit tests to verify kea-dhcp6 santizes FQDN values modified: src/bin/dhcp6/tests/fqdn_unittest.cc --- diff --git a/src/bin/dhcp6/tests/fqdn_unittest.cc b/src/bin/dhcp6/tests/fqdn_unittest.cc index 17b8da438a..4ed958c38a 100644 --- a/src/bin/dhcp6/tests/fqdn_unittest.cc +++ b/src/bin/dhcp6/tests/fqdn_unittest.cc @@ -129,7 +129,7 @@ public: ((mask & REPLACE_CLIENT_NAME) ? D2ClientConfig::RCM_WHEN_PRESENT : D2ClientConfig::RCM_NEVER), - "myhost", "example.com", "", ""))); + "myhost", "example.com", "[^A-Za-z0-9-]", "x"))); ASSERT_NO_THROW(CfgMgr::instance().setD2ClientConfig(cfg)); ASSERT_NO_THROW(srv_->startD2()); } @@ -1517,4 +1517,33 @@ TEST_F(FqdnDhcpv6SrvTest, replaceClientNameModeTest) { CLIENT_NAME_PRESENT, NAME_NOT_REPLACED); } + +// Verifies that setting hostname-char-set sanitizes FQDN option +// values received from clients. +TEST_F(FqdnDhcpv6SrvTest, sanitizeFqdn) { + // Verify a full FQDN with no invalid chars is left alone + testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, + "myhost.example.com", + Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_S, + "myhost.example.com.", false); + + // Verify that a partial FQDN with no invalid chars is left alone + testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, + "myhost", + Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, + "myhost.example.com.", false); + + // Verify that a full FQDN with invalid chars is cleaned. + testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, + "m%y*host.example.com", + Option6ClientFqdn::FULL, Option6ClientFqdn::FLAG_S, + "mxyxhost.example.com.", false); + + // Verify that a partial FQDN with invalid chars is cleaned. + testFqdn(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S, + "m%y*host", + Option6ClientFqdn::PARTIAL, Option6ClientFqdn::FLAG_S, + "mxyxhost.example.com.", false); +} + } // end of anonymous namespace