Commit 071231c9 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3569] Unit-tests implemented.

parent a3a40b9c
......@@ -39,6 +39,7 @@
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/utils.h>
#include <dhcpsrv/host_mgr.h>
#include <gtest/gtest.h>
#include <stats/stats_mgr.h>
#include <boost/scoped_ptr.hpp>
......@@ -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
......@@ -2634,4 +2659,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
......@@ -34,6 +34,7 @@
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/utils.h>
#include <util/buffer.h>
#include <util/range_utilities.h>
......@@ -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"));
......@@ -2707,9 +2734,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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment