From: Thomas Markwalder Date: Fri, 25 Jan 2019 15:54:57 +0000 (-0500) Subject: [#101,!202] Added unit tests for invalid globals X-Git-Tag: 429-Updated-StampedValue-to-support-reals_base~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b74893bb077c3b764ba8555d3cb068dfbe99d4b1;p=thirdparty%2Fkea.git [#101,!202] Added unit tests for invalid globals --- diff --git a/src/bin/dhcp4/tests/config_backend_unittest.cc b/src/bin/dhcp4/tests/config_backend_unittest.cc index 1688d5d62e..2e7f674aae 100644 --- a/src/bin/dhcp4/tests/config_backend_unittest.cc +++ b/src/bin/dhcp4/tests/config_backend_unittest.cc @@ -207,6 +207,67 @@ public: TestConfigBackendDHCPv4Ptr db2_; ///< Second configuration backend instance }; +// This test verifies that an implicit global whose data value +// does not match the expected type is detected. +TEST_F(Dhcp4CBTest, implicitGlobalWrongType) { + string base_config = + "{ \n" + " \"config-control\": { \n" + " \"config-databases\": [ { \n" + " \"type\": \"memfile\", \n" + " \"host\": \"db1\" \n" + " },{ \n" + " \"type\": \"memfile\", \n" + " \"host\": \"db2\" \n" + " } \n" + " ] \n" + " } \n" + "} \n"; + + extractConfig(base_config); + + // Make some globals: + // @todo StampedValue is going to be extended to hold type. + StampedValuePtr badGlobal(new StampedValue("valid-lifetime", "not an int")); + db1_->createUpdateGlobalParameter4(ServerSelector::ALL(), badGlobal); + + // Should fail to merge with an error. + configure(base_config, CONTROL_RESULT_ERROR, + "StampedValue::toElement: integer value expected for:" + " valid-lifetime, value is: not an int"); +} + +// This test verifies that unknown externally configured +// globals is detected. +TEST_F(Dhcp4CBTest, unknownGlobal) { + string base_config = + "{ \n" + " \"config-control\": { \n" + " \"config-databases\": [ { \n" + " \"type\": \"memfile\", \n" + " \"host\": \"db1\" \n" + " },{ \n" + " \"type\": \"memfile\", \n" + " \"host\": \"db2\" \n" + " } \n" + " ] \n" + " } \n" + "} \n"; + + extractConfig(base_config); + + // Make some globals: + // @todo StampedValue is going to be extended to hold type. + StampedValuePtr badGlobal(new StampedValue("bogus-global", "some value")); + db1_->createUpdateGlobalParameter4(ServerSelector::ALL(), badGlobal); + + // Should fail to merge with an error. + configure(base_config, CONTROL_RESULT_ERROR, + "Config backend supplied unsupported global:" + " bogus-global = some value"); +} + + // This test verifies that externally configured globals are // merged correctly into staging configuration. // @todo enable test when SrvConfig can merge globals.