Browse Source

[1788] reject in-memory file types other than "text" for now.

JINMEI Tatuya 13 years ago
parent
commit
00bc99c5a2
2 changed files with 24 additions and 3 deletions
  1. 9 1
      src/bin/auth/auth_config.cc
  2. 15 2
      src/bin/auth/tests/config_unittest.cc

+ 9 - 1
src/bin/auth/auth_config.cc

@@ -163,7 +163,15 @@ MemoryDatasourceConfig::build(ConstElementPtr config_value) {
         const string file_txt = file ? file->stringValue() : "";
         if (file_txt.empty()) {
             isc_throw(AuthConfigError, "Missing zone file for zone: "
-                      << origin->str());
+                      << origin_txt);
+        }
+        // XXX: we need to hardcode the default, see above.
+        ConstElementPtr filetype = zone_config->get("filetype");
+        const string filetype_txt = filetype ? filetype->stringValue() :
+            "text";
+        if (filetype_txt != "text") {
+            isc_throw(AuthConfigError, "Invalid filetype for zone "
+                      << origin_txt << ": " << filetype_txt);
         }
 
         // Note: we don't want to have such small try-catch blocks for each

+ 15 - 2
src/bin/auth/tests/config_unittest.cc

@@ -201,13 +201,26 @@ TEST_F(MemoryDatasrcConfigTest, addOneZone) {
         RRType::A())->code);
 }
 
-TEST_F(MemoryDatasrcConfigTest, addOneSQLite3Zone) {
+TEST_F(MemoryDatasrcConfigTest, addOneWithFiletype) {
+    // Until #1792 is completed, only "text" filetype is allowed.
+    EXPECT_THROW(parser->build(
+                     Element::fromJSON(
+                         "[{\"type\": \"memory\","
+                         "  \"zones\": [{\"origin\": \"example.com\","
+                         "               \"file\": \""
+                         TEST_DATA_DIR "/example.zone\","
+                         "               \"filetype\": \"sqlite3\"}]}]")),
+                 AuthConfigError);
+
+    // Explicitly specifying "text" is okay.
     parser->build(Element::fromJSON(
                       "[{\"type\": \"memory\","
                       "  \"zones\": [{\"origin\": \"example.com\","
                       "               \"file\": \""
                       TEST_DATA_DIR "/example.zone\","
-                      "               \"filetype\": \"sqlite3\"}]}]"));
+                      "               \"filetype\": \"text\"}]}]"));
+    parser->commit();
+    EXPECT_EQ(1, server.getInMemoryClient(rrclass)->getZoneCount());
 }
 
 TEST_F(MemoryDatasrcConfigTest, addMultiZones) {