From: Tomek Mrugalski Date: Thu, 26 Nov 2015 14:14:35 +0000 (+0100) Subject: [3569] Unit-tests implemented. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1804dbb1f41d8c7ebafcc8aaeb7425637fc7046e;p=thirdparty%2Fkea.git [3569] Unit-tests implemented. --- diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc index 184075e0ef..062025026f 100644 --- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,31 @@ const char* CONFIGS[] = { " \"valid-lifetime\": 4000," " \"interface\": \"eth0\" " " } ]," - "\"valid-lifetime\": 4000 }" + "\"valid-lifetime\": 4000 }", + + // Configuration 1: + // - 1 subnet: 192.0.2.0/24 + // - MySQL Host Data Source configured + "{ \"interfaces-config\": {" + " \"interfaces\": [ \"*\" ]" + "}," + "\"hosts-database\": {" + " \"type\": \"mysql\"," + " \"name\": \"keatest\"," + " \"user\": \"keatest\"," + " \"password\": \"keatest\"" + "}," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"subnet4\": [ { " + " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," + " \"subnet\": \"192.0.2.0/24\", " + " \"rebind-timer\": 2000, " + " \"renew-timer\": 1000, " + " \"valid-lifetime\": 4000," + " \"interface\": \"eth0\" " + " } ]," + "\"valid-lifetime\": 4000 }" }; // This test verifies that the destination address of the response @@ -2227,4 +2252,23 @@ TEST_F(Dhcpv4SrvTest, statisticsUnknownRcvd) { EXPECT_EQ(1, drop_stat->getInteger().first); } +#ifdef HAVE_MYSQL +// Checks if the v4 server can be configured to use MySQL HostDataSource. +TEST_F(Dhcpv4SrvTest, hostDataSourceMySQL) { + IfaceMgrTestConfig test_config(true); + IfaceMgr::instance().openSockets4(); + + NakedDhcpv4Srv srv(0); + + EXPECT_NO_THROW(configure(CONFIGS[1])); + + HostDataSourcePtr hds; + hds = HostMgr::instance().getHostDataSource(); + + /// @todo: Uncomment this once #3682 is merged. + /// EXPECT_TRUE(hds); +} + +#endif + }; // end of anonymous namespace diff --git a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc index a5d1c1519c..73a77df60c 100644 --- a/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/dhcp6_srv_unittest.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,53 @@ using namespace std; namespace { +const char* CONFIGS[] = { + // Configuration 0: + // - used in advertiseOptions + "{ \"interfaces-config\": {" + " \"interfaces\": [ \"*\" ]" + "}," + "\"preferred-lifetime\": 3000," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"subnet6\": [ { " + " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ]," + " \"subnet\": \"2001:db8:1::/48\", " + " \"interface\": \"eth0\", " + " \"option-data\": [ {" + " \"name\": \"dns-servers\"," + " \"data\": \"2001:db8:1234:FFFF::1, 2001:db8:1234:FFFF::2\"" + " }," + " {" + " \"name\": \"subscriber-id\"," + " \"data\": \"1234\"," + " \"csv-format\": False" + " } ]" + " } ]," + "\"valid-lifetime\": 4000 }", + + // Configuration 1: + // - a single subnet + // - MySQL host data source + "{ \"interfaces-config\": {" + " \"interfaces\": [ \"*\" ]" + "}," + "\"hosts-database\": {" + " \"type\": \"mysql\"," + " \"name\": \"keatest\"," + " \"user\": \"keatest\"," + " \"password\": \"keatest\"" + "}," + "\"preferred-lifetime\": 3000," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, " + "\"subnet6\": [ { " + " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ]," + " \"subnet\": \"2001:db8:1::/48\" " + " } ]," + "\"valid-lifetime\": 4000 }" +}; + // This test verifies that incoming SOLICIT can be handled properly when // there are no subnets configured. // @@ -288,28 +336,7 @@ TEST_F(Dhcpv6SrvTest, advertiseOptions) { IfaceMgrTestConfig test_config(true); ConstElementPtr x; - string config = "{ \"interfaces-config\": {" - " \"interfaces\": [ \"*\" ]" - "}," - "\"preferred-lifetime\": 3000," - "\"rebind-timer\": 2000, " - "\"renew-timer\": 1000, " - "\"subnet6\": [ { " - " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ]," - " \"subnet\": \"2001:db8:1::/48\", " - " \"interface\": \"eth0\", " - " \"option-data\": [ {" - " \"name\": \"dns-servers\"," - " \"data\": \"2001:db8:1234:FFFF::1, 2001:db8:1234:FFFF::2\"" - " }," - " {" - " \"name\": \"subscriber-id\"," - " \"data\": \"1234\"," - " \"csv-format\": False" - " } ]" - " } ]," - "\"valid-lifetime\": 4000 }"; - ASSERT_NO_THROW(configure(config)); + ASSERT_NO_THROW(configure(CONFIGS[0])); Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234)); sol->setRemoteAddr(IOAddress("fe80::abcd")); @@ -2430,9 +2457,23 @@ TEST_F(Dhcpv6SrvTest, receiveParseFailedStat) { EXPECT_EQ(1, recv_drop->getInteger().first); } - /// @todo: Add more negative tests for processX(), e.g. extend sanityCheck() test /// to call processX() methods. +#ifdef HAVE_MYSQL +// Checks if the v6 server can be configured to use MySQL HostDataSource. +TEST_F(Dhcpv6SrvTest, hostDataSourceMySQL) { + + Dhcp6Client client; + + EXPECT_NO_THROW(configure(CONFIGS[1], *client.getServer())); + + HostDataSourcePtr hds; + hds = HostMgr::instance().getHostDataSource(); + + /// @todo: Uncomment this once #3682 is merged. + /// EXPECT_TRUE(hds); +} +#endif } // end of anonymous namespace