]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2436] Rebased and added generic tests
authorThomas Markwalder <tmark@isc.org>
Thu, 23 Jun 2022 18:14:17 +0000 (14:14 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 29 Jun 2022 11:07:48 +0000 (07:07 -0400)
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

src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc

index 829d6d4ae654a0b1558838e7dd3122ceacb988b8..6fe04723ae9f6028e79ae1ab9a859943e904a739 100644 (file)
@@ -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");
 
index 57f5ef5c5e31a5ea0a887721c4c6a0bc62a8620d..fc45b862dcd5a48c7453ca613fa91562185128bc 100644 (file)
@@ -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<std::string> straddress4_;
 
index 30eca653d5a41e077d14959ef6c08f83380c3e97..87d830dfd6cd8979d8a54acc2c6b8e6e38f08f57 100644 (file)
@@ -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.
index 5531143cb8610d81f35fd12ad9884e54e366ecdb..8677622688cacbdd8f48bb5f899d270c9604f42c 100644 (file)
@@ -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