From: Marcin Siodelski Date: Mon, 21 Oct 2013 16:08:47 +0000 (+0200) Subject: [3200] Test that NAK lacks requested options. X-Git-Tag: bind10-1.2.0beta1-release~102^2~62^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5baa1aeb9435170663bcce936e53fbac6d55eef8;p=thirdparty%2Fkea.git [3200] Test that NAK lacks requested options. --- diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index fca75bf05e..5423a21383 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -118,7 +118,7 @@ a lease. It is up to the client to choose one server out of othe advertised and continue allocation with that server. This is a normal behavior and indicates successful operation. -% DHCP4_LEASE_ADVERT_FAIL failed to advertise a lease for client client-id %1, hwaddr %2 +% DHCP4_LEASE_ADVERT_FAIL failed to advertise a lease for client client-id %1, hwaddr %2, yiaddr %3 This message indicates that the server has failed to offer a lease to the specified client after receiving a DISCOVER message from it. There are many possible reasons for such a failure. @@ -128,7 +128,7 @@ This debug message indicates that the server successfully granted a lease in response to client's REQUEST message. This is a normal behavior and indicates successful operation. -% DHCP4_LEASE_ALLOC_FAIL failed to grant a lease for client-id %1, hwaddr %2 +% DHCP4_LEASE_ALLOC_FAIL failed to grant a lease for client-id %1, hwaddr %2, yiaddr %3 This message indicates that the server failed to grant a lease to the specified client after receiving a REQUEST message from it. There are many possible reasons for such a failure. Additional messages will indicate the diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.cc b/src/bin/dhcp4/tests/dhcp4_test_utils.cc index 12571aeb27..81416b6dcf 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.cc +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -156,6 +157,20 @@ void Dhcpv4SrvTest::optionsCheck(const Pkt4Ptr& pkt) { << " expected not to be present"; } +void Dhcpv4SrvTest::noOptionsCheck(const Pkt4Ptr& pkt) { + // Check that certain options are not returned in the packet. + // This is the case, when client didn't ask for them or when + // NAK was returned by the server. + EXPECT_FALSE(pkt->getOption(DHO_DOMAIN_NAME)) + << "domain-name present in the response"; + EXPECT_FALSE(pkt->getOption(DHO_DOMAIN_NAME_SERVERS)) + << "dns-servers present in the response"; + EXPECT_FALSE(pkt->getOption(DHO_LOG_SERVERS)) + << "log-servers present in the response"; + EXPECT_FALSE(pkt->getOption(DHO_COOKIE_SERVERS)) + << "cookie-servers present in the response"; +} + OptionPtr Dhcpv4SrvTest::generateClientId(size_t size /*= 4*/) { OptionBuffer clnt_id(size); @@ -412,6 +427,36 @@ void Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) { // Check that the requested options are returned. optionsCheck(rsp); + + // The following part of the test will test that the NAK is sent when + // there is no address pool configured. In the same time, we expect + // that the requested options are not included in NAK message, but that + // they are only included when yiaddr is set to non-zero value. + ASSERT_NO_THROW(subnet_->delPools(Lease::TYPE_V4)); + + // There has been a lease allocated for the particular client. So, + // even though we deleted the subnet, the client would get the + // existing lease (not a NAK). Therefore, we have to change the chaddr + // in the packet so as the existing lease is not returned. + req->setHWAddr(1, 6, std::vector(2, 6)); + ASSERT_TRUE(createPacketFromBuffer(req, received)); + ASSERT_TRUE(received->getOption(DHO_DHCP_PARAMETER_REQUEST_LIST)); + + if (msg_type == DHCPDISCOVER) { + ASSERT_NO_THROW(rsp = srv->processDiscover(received)); + // Should return non-NULL packet. + ASSERT_TRUE(rsp); + } else { + ASSERT_NO_THROW(rsp = srv->processRequest(received)); + // Should return non-NULL packet. + ASSERT_TRUE(rsp); + } + // We should get the NAK packet with yiaddr set to 0. + EXPECT_EQ(DHCPNAK, rsp->getType()); + ASSERT_EQ("0.0.0.0", rsp->getYiaddr().toText()); + + // Make sure that none of the requested options is returned in NAK. + noOptionsCheck(rsp); } /// @brief This function cleans up after the test. diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index 2dcaf56fcf..97eaaff106 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -114,6 +114,11 @@ public: /// @param pkt packet to be checked. void optionsCheck(const Pkt4Ptr& pkt); + /// @brief Check that certain options are not present. + /// + /// @param pkt A packet to be checked. + void noOptionsCheck(const Pkt4Ptr& pkt); + /// @brief generates client-id option /// /// Generate client-id option of specified length