From: Tomek Mrugalski Date: Thu, 6 Mar 2014 10:14:26 +0000 (+0000) Subject: [3359] Basic lease4 test moved to common lease test suite. X-Git-Tag: kea-eng-20140313~17^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44267f77cf3490f3a79014acf39be61027a372f4;p=thirdparty%2Fkea.git [3359] Basic lease4 test moved to common lease test suite. --- diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 81b7bebfb7..7113b75d29 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -108,4 +108,17 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) { testGetLease4ClientIdHWAddrSubnetId(); } +/// @brief Basic Lease4 Checks +/// +/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id), +/// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id. +/// (client-id is optional and may not be present) +TEST_F(MemfileLeaseMgrTest, DISABLED_lease4NullClientId) { + + /// @todo Test is disabled, because memfile does not support disk storage, so + /// all leases are lost after reopen() + testLease4NullClientId(); +} + + }; // end of anonymous namespace diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index ca3c09f0c5..621bbedd29 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -330,81 +330,14 @@ TEST_F(MySqlLeaseMgrTest, testAddGetDelete6) { testAddGetDelete6(false); } + /// @brief Basic Lease4 Checks /// /// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id), /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id. /// (client-id is optional and may not be present) TEST_F(MySqlLeaseMgrTest, lease4NullClientId) { - // Get the leases to be used for the test. - vector leases = createLeases4(); - - // Let's clear client-id pointers - leases[1]->client_id_ = ClientIdPtr(); - leases[2]->client_id_ = ClientIdPtr(); - leases[3]->client_id_ = ClientIdPtr(); - - // Start the tests. Add three leases to the database, read them back and - // check they are what we think they are. - EXPECT_TRUE(lmptr_->addLease(leases[1])); - EXPECT_TRUE(lmptr_->addLease(leases[2])); - EXPECT_TRUE(lmptr_->addLease(leases[3])); - lmptr_->commit(); - - // Reopen the database to ensure that they actually got stored. - reopen(); - - Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[1], l_returned); - - l_returned = lmptr_->getLease4(ioaddress4_[2]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[2], l_returned); - - l_returned = lmptr_->getLease4(ioaddress4_[3]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[3], l_returned); - - // Check that we can't add a second lease with the same address - EXPECT_FALSE(lmptr_->addLease(leases[1])); - - // Check that we can get the lease by HWAddr - HWAddr tmp(leases[2]->hwaddr_, HTYPE_ETHER); - Lease4Collection returned = lmptr_->getLease4(tmp); - ASSERT_EQ(1, returned.size()); - detailCompareLease(leases[2], *returned.begin()); - - l_returned = lmptr_->getLease4(tmp, leases[2]->subnet_id_); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[2], l_returned); - - - // Check that we can update the lease - // Modify some fields in lease 1 (not the address) and update it. - ++leases[1]->subnet_id_; - leases[1]->valid_lft_ *= 2; - lmptr_->updateLease4(leases[1]); - - // ... and check that the lease is indeed updated - l_returned = lmptr_->getLease4(ioaddress4_[1]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[1], l_returned); - - - - // Delete a lease, check that it's gone, and that we can't delete it - // a second time. - EXPECT_TRUE(lmptr_->deleteLease(ioaddress4_[1])); - l_returned = lmptr_->getLease4(ioaddress4_[1]); - EXPECT_FALSE(l_returned); - EXPECT_FALSE(lmptr_->deleteLease(ioaddress4_[1])); - - // Check that the second address is still there. - l_returned = lmptr_->getLease4(ioaddress4_[2]); - ASSERT_TRUE(l_returned); - detailCompareLease(leases[2], l_returned); - + testLease4NullClientId(); } /// @brief Verify that too long hostname for Lease4 is not accepted. diff --git a/src/lib/dhcpsrv/tests/test_utils.cc b/src/lib/dhcpsrv/tests/test_utils.cc index cf7a61fa53..06d10fcbd4 100644 --- a/src/lib/dhcpsrv/tests/test_utils.cc +++ b/src/lib/dhcpsrv/tests/test_utils.cc @@ -525,6 +525,75 @@ GenericLeaseMgrTest::testGetLease4NullClientId() { ASSERT_EQ(1, returned.size()); } +void +GenericLeaseMgrTest::testLease4NullClientId() { + // Get the leases to be used for the test. + vector leases = createLeases4(); + + // Let's clear client-id pointers + leases[1]->client_id_ = ClientIdPtr(); + leases[2]->client_id_ = ClientIdPtr(); + leases[3]->client_id_ = ClientIdPtr(); + + // Start the tests. Add three leases to the database, read them back and + // check they are what we think they are. + EXPECT_TRUE(lmptr_->addLease(leases[1])); + EXPECT_TRUE(lmptr_->addLease(leases[2])); + EXPECT_TRUE(lmptr_->addLease(leases[3])); + lmptr_->commit(); + + // Reopen the database to ensure that they actually got stored. + reopen(); + + Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[1], l_returned); + + l_returned = lmptr_->getLease4(ioaddress4_[2]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[2], l_returned); + + l_returned = lmptr_->getLease4(ioaddress4_[3]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[3], l_returned); + + // Check that we can't add a second lease with the same address + EXPECT_FALSE(lmptr_->addLease(leases[1])); + + // Check that we can get the lease by HWAddr + HWAddr tmp(leases[2]->hwaddr_, HTYPE_ETHER); + Lease4Collection returned = lmptr_->getLease4(tmp); + ASSERT_EQ(1, returned.size()); + detailCompareLease(leases[2], *returned.begin()); + + l_returned = lmptr_->getLease4(tmp, leases[2]->subnet_id_); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[2], l_returned); + + // Check that we can update the lease + // Modify some fields in lease 1 (not the address) and update it. + ++leases[1]->subnet_id_; + leases[1]->valid_lft_ *= 2; + lmptr_->updateLease4(leases[1]); + + // ... and check that the lease is indeed updated + l_returned = lmptr_->getLease4(ioaddress4_[1]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[1], l_returned); + + // Delete a lease, check that it's gone, and that we can't delete it + // a second time. + EXPECT_TRUE(lmptr_->deleteLease(ioaddress4_[1])); + l_returned = lmptr_->getLease4(ioaddress4_[1]); + EXPECT_FALSE(l_returned); + EXPECT_FALSE(lmptr_->deleteLease(ioaddress4_[1])); + + // Check that the second address is still there. + l_returned = lmptr_->getLease4(ioaddress4_[2]); + ASSERT_TRUE(l_returned); + detailCompareLease(leases[2], l_returned); +} + void GenericLeaseMgrTest::testGetLease4HWAddr() { // Let's initialize two different leases 4 and just add the first ... diff --git a/src/lib/dhcpsrv/tests/test_utils.h b/src/lib/dhcpsrv/tests/test_utils.h index 9d93a2f710..d159c3251a 100644 --- a/src/lib/dhcpsrv/tests/test_utils.h +++ b/src/lib/dhcpsrv/tests/test_utils.h @@ -127,6 +127,15 @@ public: /// @brief Test lease retrieval using client id, HW address and subnet id. void testGetLease4ClientIdHWAddrSubnetId(); + /// @brief Basic Lease4 Checks + /// + /// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id), + /// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id. + /// (client-id is optional and may not be present) + /// + /// @todo: check if it does overlap with @ref testGetLease4NullClientId() + void testLease4NullClientId(); + /// @brief Test that IPv6 lease can be added, retrieved and deleted. /// /// This method checks basic IPv6 lease operations. There's check_t1_t2