},
{
"qualified host name with nuls",
- std::string("four-ok-host\000.other.org",23),
+ std::string("four-ok-host\000.other.org", 23),
"four-ok-host.other.org"
}
};
}
}
+// Verifies that when the FQDN option is scrubbed empty it is logged
+// and ignored.
+TEST_F(NameDhcpv4SrvTest, hostnameScrubbedEmpty) {
+ Dhcp4Client client(srv_, Dhcp4Client::SELECTING);
+
+ // Configure DHCP server.
+ configure(CONFIGS[2], *client.getServer());
+
+ // Set the hostname option.
+ ASSERT_NO_THROW(client.includeHostname("___"));
+
+ // Send the DHCPDISCOVER and make sure that the server responded.
+ ASSERT_NO_THROW(client.doDiscover());
+ auto resp = client.getContext().response_;
+ ASSERT_TRUE(resp);
+ ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
+
+ // Should have logged that it was scrubbed empty.
+ std::string log = "DHCP4_CLIENT_HOSTNAME_SCRUBBED_EMPTY"
+ " [hwtype=1 67:c6:69:73:51:ff], cid=[no info], tid=0x0:"
+ " sanitiziing client's Hostname option '___'"
+ " yielded an empty string";
+ EXPECT_EQ(1, countFile(log));
+
+ // Hostname should not be in the response.
+ ASSERT_FALSE(resp->getOption(DHO_HOST_NAME));
+}
+
+// Verifies that when the FQDN option is scrubbed empty it is logged
+// and ignored.
+TEST_F(NameDhcpv4SrvTest, fqdnScrubbedEmpty) {
+ Dhcp4Client client(srv_, Dhcp4Client::SELECTING);
+
+ // Configure DHCP server.
+ configure(CONFIGS[2], *client.getServer());
+
+ // Include the Client FQDN option.
+ ASSERT_NO_THROW(client.includeFQDN(Option4ClientFqdn::FLAG_S | Option4ClientFqdn::FLAG_E,
+ "___", Option4ClientFqdn::PARTIAL));
+
+ // Send the DHCPDISCOVER and make sure that the server responded.
+ ASSERT_NO_THROW(client.doDiscover());
+ auto resp = client.getContext().response_;
+ ASSERT_TRUE(resp);
+ ASSERT_EQ(DHCPOFFER, static_cast<int>(resp->getType()));
+
+ // Should have logged that it was scrubbed empty.
+ std::string log = "DHCP4_CLIENT_FQDN_SCRUBBED_EMPTY"
+ " [hwtype=1 67:c6:69:73:51:ff], cid=[no info], tid=0x0:"
+ " sanitiziing client's FQDN option '___'"
+ " yielded an empty string";
+ EXPECT_EQ(1, countFile(log));
+
+ // Hostname should not be in the response.
+ ASSERT_FALSE(resp->getOption(DHO_FQDN));
+}
+
+
} // end of anonymous namespace
#include <dhcp/option6_client_fqdn.h>
#include <dhcpsrv/d2_client_mgr.h>
#include <testutils/test_to_element.h>
+#include <testutils/gtest_utils.h>
#include <exceptions/exceptions.h>
#include <util/str.h>
}
}
+/// @brief Tests adjustDomainName template method with Option4ClientFqdn
+/// when sanitizing scrubs input name empty.
+TEST_F(D2ClientMgrParamsTest, adjustDomainNameV4ScrubbedEmpty) {
+ D2ClientMgr mgr;
+
+ // Create enabled configuration
+ subnet_->setDdnsSendUpdates(false);
+ subnet_->setDdnsQualifyingSuffix("suffix.com");
+ subnet_->setHostnameCharSet("[^A-Za-z0-9.-]");
+ subnet_->setHostnameCharReplacement("");
+
+ Option4ClientFqdn request(0, Option4ClientFqdn::RCODE_CLIENT(),
+ "___", Option4ClientFqdn::FULL);
+
+ Option4ClientFqdn response(request);
+ ASSERT_THROW_MSG(mgr.adjustDomainName<Option4ClientFqdn>(request, response, *ddns_params_),
+ FQDNScrubbedEmpty, "___.");
+}
+
+/// @brief Tests adjustDomainName template method with Option4ClientFqdn
+/// when sanitizing scrubs input name empty.
+TEST_F(D2ClientMgrParamsTest, adjustDomainNameV6ScrubbedEmpty) {
+ D2ClientMgr mgr;
+
+ // Create enabled configuration
+ subnet_->setDdnsSendUpdates(false);
+ subnet_->setDdnsQualifyingSuffix("suffix.com");
+ subnet_->setHostnameCharSet("[^A-Za-z0-9.-]");
+ subnet_->setHostnameCharReplacement("");
+
+ Option6ClientFqdn request(0, "___", Option6ClientFqdn::FULL);
+
+ Option6ClientFqdn response(request);
+ ASSERT_THROW_MSG(mgr.adjustDomainName<Option6ClientFqdn>(request, response, *ddns_params_),
+ FQDNScrubbedEmpty, "___.");
+}
+
+
+
} // end of anonymous namespace