From: Michal 'vorner' Vaner Date: Tue, 17 Apr 2012 11:36:34 +0000 (+0200) Subject: [1793] More tests X-Git-Tag: trac2351_base~226^2~116^2~23^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4deb49cf84c399a0ca1a84fef1cd0dee4ca4d5d5;p=thirdparty%2Fkea.git [1793] More tests Checking various error modes, like unreadable database, wrong or missing configuration. --- diff --git a/src/bin/auth/tests/command_unittest.cc b/src/bin/auth/tests/command_unittest.cc index 5e6be956ed..52f60b324e 100644 --- a/src/bin/auth/tests/command_unittest.cc +++ b/src/bin/auth/tests/command_unittest.cc @@ -264,6 +264,7 @@ TEST_F(AuthCommandTest, { // Prepare the database first const string test_db = TEST_DATA_BUILDDIR "/auth_test.sqlite3.copied"; + const string bad_db = TEST_DATA_BUILDDIR "/does-not-exist.sqlite3"; stringstream ss("example.org. 3600 IN SOA . . 0 0 0 0 0\n"); createSQLite3DB(RRClass::IN(), Name("example.org"), test_db.c_str(), ss); @@ -276,18 +277,19 @@ TEST_F(AuthCommandTest, ModuleCCSession moduleSession(SPEC_FILE, session, NULL, NULL, false, false); // This describes the data source in the configuration - ElementPtr map(Element::fromJSON("{\"datasources\": [" - " {" - " \"type\": \"memory\"," - " \"zones\": [" - " {" - " \"origin\": \"example.org\"," - " \"file\": \"" + test_db + "\"," - " \"filetype\": \"sqlite3\"" - " }" - " ]" - " }" - "]}")); + const ElementPtr + map(Element::fromJSON("{\"datasources\": [" + " {" + " \"type\": \"memory\"," + " \"zones\": [" + " {" + " \"origin\": \"example.org\"," + " \"file\": \"" + test_db + "\"," + " \"filetype\": \"sqlite3\"" + " }" + " ]" + " }" + "]}")); moduleSession.setLocalConfig(map); server_.setConfigSession(&moduleSession); @@ -309,6 +311,65 @@ TEST_F(AuthCommandTest, EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> findZone(Name("example.org")).zone_finder-> find(Name("example.org"), RRType::SOA())->code); + + // Some error cases. First, the zone has no configuration. + dsrc->addZone(ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(), + Name("example.com")))); + result_ = execAuthServerCommand(server_, "loadzone", + Element::fromJSON("{\"origin\": \"example.com\"}")); + checkAnswer(1); + + EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> + findZone(Name("example.org")).zone_finder-> + find(Name("example.org"), RRType::SOA())->code); + + moduleSession.setLocalConfig(Element::fromJSON("{\"datasources\": []}")); + result_ = execAuthServerCommand(server_, "loadzone", + Element::fromJSON("{\"origin\": \"example.org\"}")); + checkAnswer(1); + + // The previous zone is not hurt in any way + EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> + findZone(Name("example.org")).zone_finder-> + find(Name("example.org"), RRType::SOA())->code); + // Configure an unreadable zone. Should fail, but leave the original zone + // data there + const ElementPtr + mapBad(Element::fromJSON("{\"datasources\": [" + " {" + " \"type\": \"memory\"," + " \"zones\": [" + " {" + " \"origin\": \"example.org\"," + " \"file\": \"" + bad_db + "\"," + " \"filetype\": \"sqlite3\"" + " }" + " ]" + " }" + "]}")); + moduleSession.setLocalConfig(mapBad); + result_ = execAuthServerCommand(server_, "loadzone", + Element::fromJSON("{\"origin\": \"example.com\"}")); + checkAnswer(1); + // The previous zone is not hurt in any way + EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> + findZone(Name("example.org")).zone_finder-> + find(Name("example.org"), RRType::SOA())->code); + + // Broken configuration (not valid against the spec) + const ElementPtr + broken(Element::fromJSON("{\"datasources\": [" + " {" + " \"type\": \"memory\"," + " \"zones\": [[]]" + " }" + "]}")); + moduleSession.setLocalConfig(broken); + checkAnswer(1); + // The previous zone is not hurt in any way + EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> + findZone(Name("example.org")).zone_finder-> + find(Name("example.org"), RRType::SOA())->code); } TEST_F(AuthCommandTest, loadBrokenZone) {