]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#101,!202] Added unit tests for invalid globals
authorThomas Markwalder <tmark@isc.org>
Fri, 25 Jan 2019 15:54:57 +0000 (10:54 -0500)
committerThomas Markwalder <tmark@isc.org>
Fri, 25 Jan 2019 15:54:57 +0000 (10:54 -0500)
src/bin/dhcp4/tests/config_backend_unittest.cc

index 1688d5d62e5d8d56a1efd9369d5c17e00c5a48d4..2e7f674aaea30d31c8d2921fb066c8dd312f6e98 100644 (file)
@@ -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.