Browse Source

[3677] Two unit-tests fixed.

Tomek Mrugalski 10 years ago
parent
commit
be91de0247

+ 3 - 2
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

+ 6 - 0
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.

+ 39 - 9
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);