]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2832] add value checking for 'cache-type'
authorPaul Selkirk <pselkirk@isc.org>
Fri, 12 Apr 2013 01:27:25 +0000 (21:27 -0400)
committerPaul Selkirk <pselkirk@isc.org>
Fri, 12 Apr 2013 01:27:25 +0000 (21:27 -0400)
src/lib/datasrc/cache_config.cc
src/lib/datasrc/tests/cache_config_unittest.cc

index 9cfe3b1a7c3986876431b2a5ed38410f16671113..b1d583f233876d47e03504a5503a3e45c35723b8 100644 (file)
@@ -37,12 +37,16 @@ getEnabledFromConf(const Element& conf) {
 
 std::string
 getSegmentTypeFromConf(const Element& conf) {
-    // If cache-zones is not explicitly configured, use the default type.
+    // If cache-type is not explicitly configured, use the default type.
     // (Ideally we should retrieve the default from the spec).
     if (!conf.contains("cache-type")) {
         return ("local");
     }
-    return (conf.get("cache-type")->stringValue());
+    std::string cache_type = conf.get("cache-type")->stringValue();
+    if ((cache_type != "local") && (cache_type != "mapped")) {
+        isc_throw(CacheConfigError, "invalid cache-type");
+    }
+    return (cache_type);
 }
 }
 
index 8c266ec3b53d3988ed06a56078a13a2d66bd8b5f..cce2462bb0025626e6d750ba1cfbc8cfebe7a9c6 100644 (file)
@@ -238,6 +238,13 @@ TEST_F(CacheConfigTest, getSegmentType) {
                                                 " \"params\": {}}"));
     EXPECT_THROW(CacheConfig("MasterFiles", 0, *badconfig, true),
                  isc::data::TypeError);
+
+    // Bad value: should be rejected at construction time
+    ConstElementPtr badconfig2(Element::fromJSON("{\"cache-enable\": true,"
+                                                " \"cache-type\": \"bogus\","
+                                                " \"params\": {}}"));
+    EXPECT_THROW(CacheConfig("MasterFiles", 0, *badconfig2, true),
+                 isc::datasrc::internal::CacheConfigError);
 }
 
 }