From: Thomas Markwalder Date: Thu, 23 Jun 2022 18:14:17 +0000 (-0400) Subject: [#2436] Rebased and added generic tests X-Git-Tag: Kea-2.2.0~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ef4a5f7c09e431ef3eca0e6f9e2fd78d0416c4f;p=thirdparty%2Fkea.git [#2436] Rebased and added generic tests src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.* Split GenericLeaseMgrTest::testLeaseLimits() into: GenericLeaseMgrTest::testLeaseLimits4() GenericLeaseMgrTest::testLeaseLimits6() src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc TEST_F(MemfileLeaseMgrTest, isJsonSupported4) TEST_F(MemfileLeaseMgrTest, isJsonSupported6) TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull4) TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull6) TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits4) TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits6) - new tests src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount4) TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_NA) TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_PD) - new tests --- diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 829d6d4ae6..6fe04723ae 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -3904,7 +3904,8 @@ GenericLeaseMgrTest::testLeaseStatsQueryAttribution6() { checkQueryAgainstRowSet(query, expected_rows); } -GenericLeaseMgrTest::testLeaseLimits() { +void +GenericLeaseMgrTest::testLeaseLimits4() { std::string text; ElementPtr user_context; @@ -3914,15 +3915,11 @@ GenericLeaseMgrTest::testLeaseLimits() { "client-classes": [ { "name": "foo", "address-limit": 0 } ] } } })"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0"); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); - EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0"); user_context = Element::fromJSON(R"({ "ISC": { "limits": { "subnet": { "id": 1, "address-limit": 0 } } } })"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0"); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); - EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0"); // -- A limit of 1 with no leases should allow a lease. -- @@ -3930,21 +3927,58 @@ GenericLeaseMgrTest::testLeaseLimits() { "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); EXPECT_EQ(text, ""); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); - EXPECT_EQ(text, ""); user_context = Element::fromJSON(R"({ "ISC": { "limits": { "subnet": { "id": 1, "address-limit": 1 } } } })"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); EXPECT_EQ(text, ""); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); - EXPECT_EQ(text, ""); // -- A limit of 1 with 1 current lease should deny further leases. -- makeLease4("192.0.1.1", 1, Lease::STATE_DEFAULT, Element::fromJSON( R"({ "ISC": { "client-classes": [ "foo" ] } })")); + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); + EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1"); + + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "subnet": { "id": 1, "address-limit": 1 } } } })"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); + EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1"); +} + +void +GenericLeaseMgrTest::testLeaseLimits6() { + std::string text; + ElementPtr user_context; + + // -- A limit of 0 always denies a lease. -- + + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "client-classes": [ { "name": "foo", "address-limit": 0 } ] } } })"); + EXPECT_EQ(text, "address limit 0 for client class \"foo\", current lease count 0"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); + + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "subnet": { "id": 1, "address-limit": 0 } } } })"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); + EXPECT_EQ(text, "address limit 0 for subnet ID 1, current lease count 0"); + + // -- A limit of 1 with no leases should allow a lease. -- + + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); + EXPECT_EQ(text, ""); + + user_context = Element::fromJSON(R"({ "ISC": { "limits": { + "subnet": { "id": 1, "address-limit": 1 } } } })"); + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); + EXPECT_EQ(text, ""); + + // -- A limit of 1 with 1 current lease should deny further leases. -- makeLease6(Lease::TYPE_NA, "2001:db8::", 0, 1, Lease::STATE_DEFAULT, Element::fromJSON( R"({ "ISC": { "client-classes": [ "foo" ] } })")); @@ -3953,8 +3987,6 @@ GenericLeaseMgrTest::testLeaseLimits() { user_context = Element::fromJSON(R"({ "ISC": { "limits": { "client-classes": [ { "name": "foo", "address-limit": 1 } ] } } })"); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); - EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); EXPECT_EQ(text, "address limit 1 for client class \"foo\", current lease count 1"); @@ -3965,8 +3997,6 @@ GenericLeaseMgrTest::testLeaseLimits() { user_context = Element::fromJSON(R"({ "ISC": { "limits": { "subnet": { "id": 1, "address-limit": 1 } } } })"); - ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(user_context)); - EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1"); ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(user_context)); EXPECT_EQ(text, "address limit 1 for subnet ID 1, current lease count 1"); diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h index 57f5ef5c5e..fc45b862dc 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h @@ -493,9 +493,6 @@ public: /// world this never happens. void testLeaseStatsQueryAttribution6(); - /// @brief Checks a few limit checking scenarios. - void testLeaseLimits(); - /// @brief Compares LeaseQueryStats content to expected set of rows /// /// @param qry - a started LeaseStatsQuery @@ -533,6 +530,12 @@ public: /// @param ltype type of lease, either Lease::TYPE_NA or Lease::TYPE_PD void testClassLeaseCount6(Lease::Type ltype); + /// @brief Checks a few v4 lease limit checking scenarios. + void testLeaseLimits4(); + + /// @brief Checks a few v6 lease limit checking scenarios. + void testLeaseLimits6(); + /// @brief String forms of IPv4 addresses std::vector straddress4_; diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index 30eca653d5..87d830dfd6 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -2583,6 +2583,22 @@ TEST_F(MemfileLeaseMgrTest, testHWAddr) { } } +// Verifies that isJsonSupported() returns true for Memfile. +TEST_F(MemfileLeaseMgrTest, isJsonSupported4) { + startBackend(V4); + bool json_supported; + ASSERT_NO_THROW_LOG(json_supported = LeaseMgrFactory::instance().isJsonSupported()); + ASSERT_TRUE(json_supported); +} + +// Verifies that isJsonSupported() returns true for Memfile. +TEST_F(MemfileLeaseMgrTest, isJsonSupported6) { + startBackend(V6); + bool json_supported; + ASSERT_NO_THROW_LOG(json_supported = LeaseMgrFactory::instance().isJsonSupported()); + ASSERT_TRUE(json_supported); +} + // Verifies that v4 class lease counts are correctly adjusted // when leases have class lists. TEST_F(MemfileLeaseMgrTest, classLeaseCount4) { @@ -2604,6 +2620,38 @@ TEST_F(MemfileLeaseMgrTest, classLeaseCount6_PD) { testClassLeaseCount6(Lease::TYPE_PD); } +// brief Checks that a null user context allows allocation. +// DISABLED_ until Memfile_LeaseMgr implements checkLimits4(). +TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull4) { + startBackend(V4); + std::string text; + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits4(nullptr)); + EXPECT_TRUE(text.empty()); +} + +// brief Checks that a null user context allows allocation. +// DISABLED_ until Memfile_LeaseMgr implements checkLimits6(). +TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimitsNull6) { + startBackend(V6); + std::string text; + ASSERT_NO_THROW_LOG(text = LeaseMgrFactory::instance().checkLimits6(nullptr)); + EXPECT_TRUE(text.empty()); +} + +// Checks a few V4 lease limit checking scenarios. +// Disabbled until Memfile_LeaseMgr implements checkLimits4() function. +TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits4) { + startBackend(V4); + testLeaseLimits4(); +} + +// Checks a few V4 lease limit checking scenarios. +// Disabbled until Memfile_LeaseMgr implements checkLimits4() function. +TEST_F(MemfileLeaseMgrTest, DISABLED_checkLimits6) { + startBackend(V6); + testLeaseLimits6(); +} + // Verifies that v4 class lease counts can be recounted. TEST_F(MemfileLeaseMgrTest, classLeaseRecount4) { startBackend(V4); @@ -2643,10 +2691,8 @@ TEST_F(MemfileLeaseMgrTest, classLeaseRecount4) { // Bake all the leases. for ( auto recipe : recipes ) { - Lease4Ptr lease = makeLease4(recipe.address_, 777, recipe.state_, false); ElementPtr ctx = makeContextWithClasses(recipe.classes_); - lease->setContext(makeContextWithClasses(recipe.classes_)); - ASSERT_NO_THROW_LOG(memfile_mgr->addLease(lease)); + ASSERT_TRUE(makeLease4(recipe.address_, 777, recipe.state_, ctx)); } // Verify counts are as expected. @@ -2724,10 +2770,8 @@ TEST_F(MemfileLeaseMgrTest, classLeaseRecount6) { // Bake all the leases. for ( auto recipe : recipes ) { - Lease6Ptr lease = makeLease6(recipe.ltype_, recipe.address_, recipe.prefix_len_, 777, recipe.state_, false); ElementPtr ctx = makeContextWithClasses(recipe.classes_); - lease->setContext(makeContextWithClasses(recipe.classes_)); - ASSERT_NO_THROW_LOG(memfile_mgr->addLease(lease)); + ASSERT_TRUE(makeLease6(recipe.ltype_, recipe.address_, recipe.prefix_len_, 777, recipe.state_, ctx)); } // Verify counts are as expected. diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index 5531143cb8..8677622688 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -1082,6 +1082,27 @@ TEST_F(MySqlLeaseMgrTest, isJsonSupported) { "enabled in the database." << std::endl; } +// Verifies that v4 class lease counts are correctly adjusted +// when leases have class lists. +// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount() +TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount4) { + testClassLeaseCount4(); +} + +// Verifies that v6 IA_NA class lease counts are correctly adjusted +// when leases have class lists. +// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount() +TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_NA) { + testClassLeaseCount6(Lease::TYPE_NA); +} + +// Verifies that v6 IA_PD class lease counts are correctly adjusted +// when leases have class lists. +// Disabled until MySqlLeaseMgr implements LeaseMgr::getClassLeaseCount() +TEST_F(MySqlLeaseMgrTest, DISABLED_classLeaseCount6_PD) { + testClassLeaseCount6(Lease::TYPE_PD); +} + /// @brief Checks that a null user context allows allocation. TEST_F(MySqlLeaseMgrTest, checkLimitsNull) { std::string text; @@ -1110,7 +1131,8 @@ TEST_F(MySqlLeaseMgrTest, checkLimits) { } // The rest of the checks are only for databases with JSON support. - testLeaseLimits(); + testLeaseLimits4(); + testLeaseLimits6(); } } // namespace