]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5704] Added subnet-id = 0 unit tests to host data sources
authorThomas Markwalder <tmark@isc.org>
Thu, 2 Aug 2018 19:43:56 +0000 (15:43 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 2 Aug 2018 19:43:56 +0000 (15:43 -0400)
    Added tests to verify backends support storing and fetching
    reservations with either v4 or v6 subnet-id values of 0.

src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

index 17362bdbcb7367ae20b2665e31e876e62e05915b..6e70c7b7d25508b97035235224102f91420955a5 100644 (file)
@@ -663,4 +663,30 @@ TEST_F(CqlHostDataSourceTest, testMultipleHosts6) {
     testMultipleHosts6();
 }
 
+// Verifies that IPv4 host reservation with options can have a value of zero
+// dhcp4_subnet id
+TEST_F(CqlHostDataSourceTest, zeroSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a value of zero
+// dhcp6_subnet id
+TEST_F(CqlHostDataSourceTest, zeroSubnetId6) {
+    testMaxSubnetId6();
+}
+
+// Verifies that IPv4 host reservation with options can have a max value
+// for  dhcp4_subnet id
+TEST_F(CqlHostDataSourceTest, maxSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a max value
+// for  dhcp6_subnet id
+TEST_F(CqlHostDataSourceTest, maxSubnetId6) {
+    testMaxSubnetId6();
+}
+
+
+
 }  // namespace
index 92ceff5dcce570127c2fd33a8652e1c8ab67fc83..e82c7d45885f2c40ad259ab0889f9aeb043ab1e5 100644 (file)
@@ -285,6 +285,18 @@ TEST_F(MySqlHostDataSourceTest, basic4HWAddr) {
     testBasic4(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservation with options can have a value of zero
+// dhcp4_subnet id
+TEST_F(MySqlHostDataSourceTest, zeroSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a value of zero
+// dhcp6_subnet id
+TEST_F(MySqlHostDataSourceTest, zeroSubnetId6) {
+    testMaxSubnetId6();
+}
+
 // Verifies that IPv4 host reservation with options can have a max value
 // for  dhcp4_subnet id
 TEST_F(MySqlHostDataSourceTest, maxSubnetId4) {
index bcb7570a1487fc3c93639e5bb5f6ded593340443..aecd7afdd9da9b5af83d65321bfe7ae3281a5651 100644 (file)
@@ -270,6 +270,18 @@ TEST_F(PgSqlHostDataSourceTest, basic4HWAddr) {
     testBasic4(Host::IDENT_HWADDR);
 }
 
+// Verifies that IPv4 host reservation with options can have a value of zero
+// dhcp4_subnet id
+TEST_F(PgSqlHostDataSourceTest, zeroSubnetId4) {
+    testMaxSubnetId4();
+}
+
+// Verifies that IPv6 host reservation with options can have a value of zero
+// dhcp6_subnet id
+TEST_F(PgSqlHostDataSourceTest, zeroSubnetId6) {
+    testMaxSubnetId6();
+}
+
 // Verifies that IPv4 host reservation with options can have a max value
 // for  dhcp4_subnet id
 TEST_F(PgSqlHostDataSourceTest, maxSubnetId4) {
index 0ff489e052fa551fa01b44ca97e18efb099480f9..d20c5c99247c74b7293cbbf9ce36fa9e45575076 100644 (file)
@@ -259,6 +259,68 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) {
     HostDataSourceUtils::compareHosts(host, from_hds);
 }
 
+void
+GenericHostDataSourceTest::testZeroSubnetId4() {
+    std::vector<uint8_t> ident;
+
+    ident = HostDataSourceUtils::generateIdentifier();
+    SubnetID subnet_id4 = 0;
+    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
+                          subnet_id4, 0, IOAddress("0.0.0.0")));
+
+    ASSERT_NO_THROW(addTestOptions(host, true, DHCP4_ONLY));
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // get4(subnet_id, identifier_type, identifier, identifier_size)
+    ConstHostPtr host_by_id = hdsptr_->get4(subnet_id4,
+                                            host->getIdentifierType(),
+                                            &host->getIdentifier()[0],
+                                            host->getIdentifier().size());
+
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
+
+    // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+    EXPECT_TRUE(hdsptr_->del4(subnet_id4, Host::IDENT_DUID, &ident[0],
+                              ident.size()));
+
+    host_by_id = hdsptr_->get4(subnet_id4, host->getIdentifierType(),
+                               &host->getIdentifier()[0],
+                               host->getIdentifier().size());
+
+    EXPECT_FALSE(host_by_id);
+}
+
+void GenericHostDataSourceTest::testZeroSubnetId6() {
+    std::vector<uint8_t> ident;
+
+    ident = HostDataSourceUtils::generateIdentifier();
+    SubnetID subnet_id6 = 0;
+    HostPtr host(new Host(&ident[0], ident.size(), Host::IDENT_DUID,
+                          0, subnet_id6, IOAddress("0.0.0.0")));
+
+    ASSERT_NO_THROW(addTestOptions(host, true, DHCP6_ONLY));
+    ASSERT_NO_THROW(hdsptr_->add(host));
+
+    // get6(subnet_id, identifier_type, identifier, identifier_size)
+    ConstHostPtr host_by_id = hdsptr_->get6(subnet_id6,
+                                            host->getIdentifierType(),
+                                            &host->getIdentifier()[0],
+                                            host->getIdentifier().size());
+
+    ASSERT_NO_FATAL_FAILURE(HostDataSourceUtils::compareHosts(host, host_by_id));
+
+    // Now try to delete it: del6(subnet6-id, identifier-type, identifier)
+    EXPECT_TRUE(hdsptr_->del6(subnet_id6, Host::IDENT_DUID, &ident[0],
+                              ident.size()));
+
+    host_by_id = hdsptr_->get4(subnet_id6, host->getIdentifierType(),
+                               &host->getIdentifier()[0],
+                               host->getIdentifier().size());
+
+    EXPECT_FALSE(host_by_id);
+}
+
+
 void
 GenericHostDataSourceTest::testMaxSubnetId4() {
     std::vector<uint8_t> ident;
index 250943f5f1d5b9b0114a0ada75f0d73f9bd12e47..fdc0c0d8113b4af0811ee659e198acf3989319b5 100644 (file)
@@ -312,6 +312,19 @@ public:
     /// @param id Identifier type.
     void testBasic4(const Host::IdentifierType& id);
 
+    /// @brief Test that Verifies that an IPv4 host reservation with
+    /// options can have 0 for dhcp4_subnet id. 0 denotes global
+    /// reservation.
+    ///
+    /// Uses gtest macros to report failures.
+    void testZeroSubnetId4();
+
+    /// @brief Test that Verifies that an IPv6 host reservation with
+    /// options can have 0 for dhcp6_subnet id. 0 denotes global
+    /// reservation.
+    ///
+    /// Uses gtest macros to report failures.
+    void testZeroSubnetId6();
 
     /// @brief Test that Verifies that an IPv4 host reservation with
     /// options can have a max value for dhcp4_subnet id