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";
+ std::string log = "DHCP4_CLIENT_HOSTNAME_SCRUBBED_EMPTY";
EXPECT_EQ(1, countFile(log));
// Hostname should not be in the response.
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";
+ std::string log = "DHCP4_CLIENT_FQDN_SCRUBBED_EMPTY";
EXPECT_EQ(1, countFile(log));
// Hostname should not be in the response.
}
}
+// Verify an FQDN with all invalid chars is ignored.
+TEST_F(FqdnDhcpv6SrvTest, fqdnScrubbedEmpty) {
+ // Create the query.
+ Pkt6Ptr question = generateMessage(DHCPV6_SOLICIT, Option6ClientFqdn::FLAG_S,
+ "___" , Option6ClientFqdn::FULL, true);
+ ASSERT_TRUE(getClientFqdnOption(question));
+ subnet_->setHostnameCharReplacement("");
+
+ // Create the response with an "assigned" lease.
+ // Set the selected subnet so ddns params get returned correctly.
+ AllocEngine::ClientContext6 ctx;
+ ctx.subnet_ = subnet_;
+ Pkt6Ptr answer = generateMessageWithIds(DHCPV6_ADVERTISE);
+ addIA(1234, IOAddress("2001:db8:1::1"), answer, ctx);
+
+ // Process the client's FQDN.
+ ASSERT_NO_THROW(srv_->processClientFqdn(question, answer, ctx));
+
+ // Should not have an FQDN option in the answer.
+ EXPECT_FALSE(answer->getOption(D6O_CLIENT_FQDN));
+ countFile("DHCP6_CLIENT_FQDN_SCRUBBED_EMPTY");
+}
+
} // end of anonymous namespace
std::ostringstream gen_name;
gen_name << partial_name;
std::string suffix = ddns_params.getQualifyingSuffix();
- if (!suffix.empty() && partial_name.back() != '.') {
+ if ((!suffix.empty()) && (!partial_name.empty())
+ && (partial_name.back() != '.')) {
bool suffix_present = true;
std::string str = gen_name.str();
auto suffix_rit = suffix.rbegin();
qualified_name = mgr.qualifyName(partial_name, *ddns_params_, do_not_dot);
EXPECT_EQ("somehost.suffix.com", qualified_name);
+ // Verify that an empty name does not crash.
+ partial_name = "";
+ qualified_name = mgr.qualifyName(partial_name, *ddns_params_, do_not_dot);
+ EXPECT_EQ("", qualified_name);
+
// Verify that an empty suffix and false flag, does not change the name
subnet_->setDdnsQualifyingSuffix("");
partial_name = "somehost";
// suffix is blank and trailing dot is false
qualified_name = mgr.qualifyName("somehost.", *ddns_params_, do_not_dot);
EXPECT_EQ("somehost", qualified_name);
+
+ // Verify that an empty name and an empty suffix does not crash.
+ partial_name = "";
+ qualified_name = mgr.qualifyName(partial_name, *ddns_params_, do_not_dot);
+ EXPECT_EQ("", qualified_name);
}
/// @brief Tests the qualifyName method's ability to avoid duplicating