From: Thomas Markwalder Date: Fri, 8 May 2015 13:40:09 +0000 (-0400) Subject: [3779] Added additional tests per review X-Git-Tag: trac3824_base~6^2~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=e87dc1e7c7a8ce6b8de7910d9c0457847f828c69;p=thirdparty%2Fkea.git [3779] Added additional tests per review fqdn_unittest.cc TEST_F(NameDhcpv4SrvTest, emptyFqdn) - now also verifies that the lease is added to the database following a REQUEST and that when it is retrieved from the database its hostname matches the generated FQDN. --- diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index ac0522f639..8ff3812f1b 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -1331,9 +1331,13 @@ TEST_F(NameDhcpv4SrvTest, hostnameReservation) { } // Test verifies that the server properly generates a FQDN when the client -// FQDN name is blank, whether or not DDNS updates are enabled. +// FQDN name is blank, whether or not DDNS updates are enabled. It also +// verifies that the lease is only in the database following a REQUEST and +// that the lesae contains the generated FQDN. TEST_F(NameDhcpv4SrvTest, emptyFqdn) { Dhcp4Client client(Dhcp4Client::SELECTING); + isc::asiolink::IOAddress expectedAddress("10.0.0.10"); + std::string expectedFqdn("myhost-10-0-0-10.fake-suffix.isc.org."); // Load a configuration with DDNS updates disabled configure(CONFIGS[2], *client.getServer()); @@ -1357,11 +1361,15 @@ TEST_F(NameDhcpv4SrvTest, emptyFqdn) { Option4ClientFqdnPtr fqdn; fqdn = boost::dynamic_pointer_cast(resp->getOption(DHO_FQDN)); ASSERT_TRUE(fqdn); - EXPECT_EQ("myhost-10-0-0-10.fake-suffix.isc.org.", fqdn->getDomainName()); + EXPECT_EQ(expectedFqdn, fqdn->getDomainName()); checkFqdnFlags(resp, (Option4ClientFqdn::FLAG_N | Option4ClientFqdn::FLAG_E | Option4ClientFqdn::FLAG_O)); + // Make sure the lease is NOT in the database. + Lease4Ptr lease = LeaseMgrFactory::instance().getLease4(IOAddress(expectedAddress)); + ASSERT_FALSE(lease); + // Now test with updates enabled configure(CONFIGS[3], *client.getServer()); ASSERT_TRUE(CfgMgr::instance().ddnsEnabled()); @@ -1379,10 +1387,35 @@ TEST_F(NameDhcpv4SrvTest, emptyFqdn) { // correct for updates enabled. fqdn = boost::dynamic_pointer_cast(resp->getOption(DHO_FQDN)); ASSERT_TRUE(fqdn); - EXPECT_EQ("myhost-10-0-0-10.fake-suffix.isc.org.", fqdn->getDomainName()); + EXPECT_EQ(expectedFqdn, fqdn->getDomainName()); checkFqdnFlags(resp, (Option4ClientFqdn::FLAG_E | Option4ClientFqdn::FLAG_S)); + // Make sure the lease is NOT in the database. + lease = LeaseMgrFactory::instance().getLease4(IOAddress(expectedAddress)); + ASSERT_FALSE(lease); + + // Do a DORA and verify that the lease exists and the name is correct. + ASSERT_NO_THROW(client.doDORA()); + + // Make sure that the server responded. + resp = client.getContext().response_; + ASSERT_TRUE(resp); + ASSERT_EQ(DHCPACK, static_cast(resp->getType())); + + // Make sure the response FQDN has the generated name and FQDN flags are + // correct for updates enabled. + fqdn = boost::dynamic_pointer_cast(resp->getOption(DHO_FQDN)); + ASSERT_TRUE(fqdn); + EXPECT_EQ(expectedFqdn, fqdn->getDomainName()); + checkFqdnFlags(resp, (Option4ClientFqdn::FLAG_E | + Option4ClientFqdn::FLAG_S)); + + // Make sure the lease is in the database and hostname is correct. + lease = LeaseMgrFactory::instance().getLease4(IOAddress(expectedAddress)); + ASSERT_TRUE(lease); + EXPECT_EQ(expectedFqdn, lease->hostname_); + } } // end of anonymous namespace