From 00bc99c5a2c8412994dd67b0e01318abb2bde893 Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Tue, 3 Apr 2012 21:05:33 -0700 Subject: [PATCH] [1788] reject in-memory file types other than "text" for now. --- src/bin/auth/auth_config.cc | 10 +++++++++- src/bin/auth/tests/config_unittest.cc | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/bin/auth/auth_config.cc b/src/bin/auth/auth_config.cc index cbd4ba9003..af7ae0aed7 100644 --- a/src/bin/auth/auth_config.cc +++ b/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 diff --git a/src/bin/auth/tests/config_unittest.cc b/src/bin/auth/tests/config_unittest.cc index 226269817d..7b4a2250b9 100644 --- a/src/bin/auth/tests/config_unittest.cc +++ b/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) {