host2->getClientClasses6());
}
+DuidPtr
+GenericHostDataSourceTest::HWAddrToDuid(const HWAddrPtr& hwaddr) {
+ if (!hwaddr) {
+ return (DuidPtr());
+ }
+
+ return (DuidPtr(new DUID(hwaddr->hwaddr_)));
+}
+
+HWAddrPtr
+GenericHostDataSourceTest::DuidToHWAddr(const DuidPtr& duid) {
+ if (!duid) {
+ return (HWAddrPtr());
+ }
+
+ return (HWAddrPtr(new HWAddr(duid->getDuid(), HTYPE_ETHER)));
+}
+
void
GenericHostDataSourceTest::compareReservations6(IPv6ResrvRange /*a*/,
IPv6ResrvRange /*b*/) {
EXPECT_FALSE(hdsptr_->get4(subnet1, IOAddress("192.0.1.5")));
}
-void GenericHostDataSourceTest::testGetByHWaddr() {
+void GenericHostDataSourceTest::testGetByHWAddr() {
// Make sure we have a pointer to the host data source.
ASSERT_TRUE(hdsptr_);
compareHosts(host2, from_hds2);
}
+void GenericHostDataSourceTest::testHWAddrNotClientId() {
+ // Make sure we have a pointer to the host data source.
+ ASSERT_TRUE(hdsptr_);
+
+ // Create a host with HW address
+ HostPtr host = initializeHost4("192.0.2.1", true);
+ ASSERT_TRUE(host->getHWAddress());
+ ASSERT_FALSE(host->getDuid());
+
+ // Try to add both of the to the host data source.
+ ASSERT_NO_THROW(hdsptr_->add(host));
+
+ SubnetID subnet = host->getIPv4SubnetID();
+
+ DuidPtr duid = HWAddrToDuid(host->getHWAddress());
+
+ // Get the host by HW address (should succeed)
+ ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, host->getHWAddress(), DuidPtr());
+
+ // Get the host by DUID (should fail)
+ ConstHostPtr by_duid = hdsptr_->get4(subnet, HWAddrPtr(), duid);
+
+ // Now let's check if we got what we expected.
+ EXPECT_TRUE(by_hwaddr);
+ EXPECT_FALSE(by_duid);
+}
+
+void GenericHostDataSourceTest::testClientIdNotHWAddr() {
+ // Make sure we have a pointer to the host data source.
+ ASSERT_TRUE(hdsptr_);
+
+ // Create a host with client-id
+ HostPtr host = initializeHost4("192.0.2.1", false);
+ ASSERT_FALSE(host->getHWAddress());
+ ASSERT_TRUE(host->getDuid());
+
+ // Try to add both of the to the host data source.
+ ASSERT_NO_THROW(hdsptr_->add(host));
+
+ SubnetID subnet = host->getIPv4SubnetID();
+
+ HWAddrPtr hwaddr = DuidToHWAddr(host->getDuid());
+
+ // Get the host by DUID (should succeed)
+ ConstHostPtr by_duid = hdsptr_->get4(subnet, HWAddrPtr(), host->getDuid());
+
+ // Get the host by HW address (should fail)
+ ConstHostPtr by_hwaddr = hdsptr_->get4(subnet, hwaddr, DuidPtr());
+
+ // Now let's check if we got what we expected.
+ EXPECT_TRUE(by_duid);
+ EXPECT_FALSE(by_hwaddr);
+}
+
+
}; // namespace test
}; // namespace dhcp
}; // namespace isc
/// @brief Test that hosts can be retrieved by hardware address.
///
/// Uses gtest macros to report failures.
- void testGetByHWaddr();
+ void testGetByHWAddr();
/// @brief Test that hosts can be retrieved by client-id
///
/// Uses gtest macros to report failures.
void testGetByClientId();
+
+ /// @brief Test that clients with stored HW address can't be retrieved
+ /// by DUID with the same value.
+ ///
+ /// Uses gtest macros to report failures.
+ void testHWAddrNotClientId();
+
+ /// @brief Test that clients with stored DUID can't be retrieved
+ /// by HW address of the same value.
+ ///
+ /// Uses gtest macros to report failures.
+ void testClientIdNotHWAddr();
+
+ /// @brief Returns DUID with identical content as specified HW address
+ ///
+ /// This method does not have any sense in real life and is only useful
+ /// in testing corner cases in the database backends (e.g. whether the DB
+ /// is able to tell the difference between hwaddr and duid)
+ ///
+ /// @param hwaddr hardware address to be copied
+ /// @return duid with the same value as specified HW address
+ DuidPtr HWAddrToDuid(const HWAddrPtr& hwaddr);
+
+ /// @brief Returns HW address with identical content as specified DUID
+ ///
+ /// This method does not have any sense in real life and is only useful
+ /// in testing corner cases in the database backends (e.g. whether the DB
+ /// is able to tell the difference between hwaddr and duid)
+ ///
+ /// @param duid DUID to be copied
+ /// @return HW address with the same value as specified DUID
+ HWAddrPtr DuidToHWAddr(const DuidPtr& duid);
};
}; // namespace test
// Test verifies if a host reservation can be added and later retrieved by
// hardware address.
TEST_F(MySqlHostDataSourceTest, getByHWaddr) {
- testGetByHWaddr();
+ testGetByHWAddr();
}
// Test verifies if a host reservation can be added and later retrieved by
// Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1) {
+ testHWAddrNotClientId();
/// @todo: add host reservation with hardware address X, try to retrieve
/// host by client-identifier X, verify that the reservation is not returned.
}
// Test verifies if hardware address and client identifier are not confused.
TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2) {
+ testClientIdNotHWAddr();
/// @todo: add host reservation with client identifier X, try to retrieve host
/// by hardware address X, verify that the reservation is not returned.
}