From: Thomas Markwalder Date: Thu, 2 Aug 2018 19:43:56 +0000 (-0400) Subject: [5704] Added subnet-id = 0 unit tests to host data sources X-Git-Tag: gitlab29-base~62^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=649392e43ee5f0255db83ff9367d934c69398a12;p=thirdparty%2Fkea.git [5704] Added subnet-id = 0 unit tests to host data sources Added tests to verify backends support storing and fetching reservations with either v4 or v6 subnet-id values of 0. --- diff --git a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc index 17362bdbcb..6e70c7b7d2 100644 --- a/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/cql_host_data_source_unittest.cc @@ -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 diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index 92ceff5dcc..e82c7d4588 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -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) { diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index bcb7570a14..aecd7afdd9 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -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) { diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index 0ff489e052..d20c5c9924 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -259,6 +259,68 @@ GenericHostDataSourceTest::testBasic4(const Host::IdentifierType& id) { HostDataSourceUtils::compareHosts(host, from_hds); } +void +GenericHostDataSourceTest::testZeroSubnetId4() { + std::vector 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 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 ident; diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h index 250943f5f1..fdc0c0d811 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h @@ -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