From be91de0247539ad99d526b79946ceadb13e2f79d Mon Sep 17 00:00:00 2001 From: Tomek Mrugalski Date: Fri, 6 Feb 2015 18:44:39 +0100 Subject: [PATCH] [3677] Two unit-tests fixed. --- src/bin/dhcp6/tests/dhcp6_client.cc | 5 +-- src/bin/dhcp6/tests/dhcp6_client.h | 6 ++++ src/bin/dhcp6/tests/rebind_unittest.cc | 48 +++++++++++++++++++++----- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/bin/dhcp6/tests/dhcp6_client.cc b/src/bin/dhcp6/tests/dhcp6_client.cc index 01dfc57c73..73720695a9 100644 --- a/src/bin/dhcp6/tests/dhcp6_client.cc +++ b/src/bin/dhcp6/tests/dhcp6_client.cc @@ -88,7 +88,8 @@ Dhcp6Client::applyRcvdConfiguration(const Pkt6Ptr& reply) { case D6O_IAADDR: { Option6IAAddrPtr iaaddr = boost::dynamic_pointer_cast< - Option6IAAddr>(ia->getOption(D6O_IAADDR)); + Option6IAAddr>(ia_opt); + if (!iaaddr) { // There is no address. This IA option may simply // contain a status code, so let's just reset the @@ -113,7 +114,7 @@ Dhcp6Client::applyRcvdConfiguration(const Pkt6Ptr& reply) { case D6O_IAPREFIX: { Option6IAPrefixPtr iaprefix = boost::dynamic_pointer_cast< - Option6IAPrefix>(ia->getOption(D6O_IAPREFIX)); + Option6IAPrefix>(ia_opt); if (!iaprefix) { // There is no prefix. This IA option may simply // contain a status code, so let's just reset the diff --git a/src/bin/dhcp6/tests/dhcp6_client.h b/src/bin/dhcp6/tests/dhcp6_client.h index 8332df50ca..6bade76fdb 100644 --- a/src/bin/dhcp6/tests/dhcp6_client.h +++ b/src/bin/dhcp6/tests/dhcp6_client.h @@ -406,6 +406,12 @@ public: oro_.push_back(option_code); } + /// @brief returns client-id + /// @return client-id + DuidPtr getDuid() { + return (duid_); + } + private: /// @brief Applies the new leases for the client. diff --git a/src/bin/dhcp6/tests/rebind_unittest.cc b/src/bin/dhcp6/tests/rebind_unittest.cc index 3a7df87579..09a24bd7a8 100644 --- a/src/bin/dhcp6/tests/rebind_unittest.cc +++ b/src/bin/dhcp6/tests/rebind_unittest.cc @@ -474,13 +474,31 @@ TEST_F(RebindTest, relayedClientChangingAddress) { << "The server discarded the Rebind message, while it should have" " sent a response indicating that the client should stop using the" " lease, by setting lifetime values to 0."; - // Get the client's lease. - ASSERT_EQ(1, client.getLeaseNum()); - Lease6 lease_client2 = client.getLease(0); + // Get the client's leases. He should get two addresses: + // the first one for the bogus 3000::100 address with 0 lifetimes. + // the second one with the actual lease with non-zero lifetimes. + ASSERT_EQ(2, client.getLeaseNum()); + + // Let's check the first one + Lease6 lease_client1 = client.getLease(0); + Lease6 lease_client2 = client.getLease(1); + + if (lease_client1.addr_.toText() != "3000::100") { + lease_client1 = client.getLease(1); + lease_client2 = client.getLease(0); + } + // The lifetimes should be set to 0, as an explicit notification to the // client to stop using invalid prefix. - EXPECT_EQ(0, lease_client2.valid_lft_); - EXPECT_EQ(0, lease_client2.preferred_lft_); + EXPECT_EQ(0, lease_client1.valid_lft_); + EXPECT_EQ(0, lease_client1.preferred_lft_); + + // Let's check the second lease + // The lifetimes should be set to 0, as an explicit notification to the + // client to stop using invalid prefix. + EXPECT_NE(0, lease_client2.valid_lft_); + EXPECT_NE(0, lease_client2.preferred_lft_); + // Check that server still has the same lease. Lease6Ptr lease_server = checkLease(lease_client); EXPECT_TRUE(lease_server); @@ -610,12 +628,24 @@ TEST_F(RebindTest, directClientPDChangingPrefix) { " sent a response indicating that the client should stop using the" " lease, by setting lifetime values to 0."; // Get the client's lease. - ASSERT_EQ(1, client.getLeaseNum()); - Lease6 lease_client2 = client.getLease(0); + ASSERT_EQ(2, client.getLeaseNum()); + + // Client should get two entries. One with the invalid address he requested + // with zeroed lifetimes and a second one with the actual prefix he has + // with non-zero lifetimes. + Lease6 lease_client1 = client.getLease(0); + Lease6 lease_client2 = client.getLease(1); + // The lifetimes should be set to 0, as an explicit notification to the // client to stop using invalid prefix. - EXPECT_EQ(0, lease_client2.valid_lft_); - EXPECT_EQ(0, lease_client2.preferred_lft_); + EXPECT_EQ(0, lease_client1.valid_lft_); + EXPECT_EQ(0, lease_client1.preferred_lft_); + + // The lifetimes should be set to 0, as an explicit notification to the + // client to stop using invalid prefix. + EXPECT_NE(0, lease_client2.valid_lft_); + EXPECT_NE(0, lease_client2.preferred_lft_); + // Check that server still has the same lease. Lease6Ptr lease_server = checkLease(lease_client); ASSERT_TRUE(lease_server); -- 2.47.3