From: Francis Dupont Date: Mon, 28 Nov 2016 16:13:33 +0000 (+0100) Subject: [5014_phase2] Added recursive include unit test X-Git-Tag: trac5036_base2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07f4340e307fe730524bbf2cdb78b4805e09eacd;p=thirdparty%2Fkea.git [5014_phase2] Added recursive include unit test --- diff --git a/src/bin/dhcp6/tests/kea_controller_unittest.cc b/src/bin/dhcp6/tests/kea_controller_unittest.cc index 57fe2bb40d..68a3f07c93 100644 --- a/src/bin/dhcp6/tests/kea_controller_unittest.cc +++ b/src/bin/dhcp6/tests/kea_controller_unittest.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -370,6 +371,46 @@ TEST_F(JSONFileBackendTest, include) { EXPECT_EQ(Lease::TYPE_NA, pools1.at(0)->getType()); } +// This test checks if recursive include of a file is detected +TEST_F(JSONFileBackendTest, recursiveInclude) { + + string config_recursive_include = "{ \"Dhcp6\": {" + "\"interfaces-config\": {" + " \"interfaces\": [ ]" + "}," + "\"preferred-lifetime\": 3000," + "\"rebind-timer\": 2000, " + "\"renew-timer\": 1000, \n" + "\"subnet6\": [ { " + " \"pools\": [ { \"pool\": \"2001:db8:1::/80\" } ]," + " \"subnet\": \"2001:db8:1::/64\" " + " } ]," + "\"valid-lifetime\": 4000 }" + "}"; + string include = "\"eth\", "; + string msg = "configuration error using file '" + string(TEST_FILE) + + "': Too many nested include."; + + writeFile(TEST_FILE, config_recursive_include); + writeFile(TEST_INCLUDE, include); + + + // Now initialize the server + boost::scoped_ptr srv; + ASSERT_NO_THROW( + srv.reset(new ControlledDhcpv6Srv(0)) + ); + + // And configure it using config + try { + srv->init(TEST_FILE); + FAIL() << "Expected Dhcp6ParseError but nothing was raised"; + } + catch (const Exception& ex) { + EXPECT_EQ(msg, ex.what()); + } +} + // This test checks if configuration can be read from a JSON file. // This test checks if configuration detects failure when trying: // - empty file