Commit 4deb49cf authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

[1793] More tests

Checking various error modes, like unreadable database, wrong or missing
configuration.
parent f00dd21c
...@@ -264,6 +264,7 @@ TEST_F(AuthCommandTest, ...@@ -264,6 +264,7 @@ TEST_F(AuthCommandTest,
{ {
// Prepare the database first // Prepare the database first
const string test_db = TEST_DATA_BUILDDIR "/auth_test.sqlite3.copied"; 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"); stringstream ss("example.org. 3600 IN SOA . . 0 0 0 0 0\n");
createSQLite3DB(RRClass::IN(), Name("example.org"), test_db.c_str(), ss); createSQLite3DB(RRClass::IN(), Name("example.org"), test_db.c_str(), ss);
...@@ -276,18 +277,19 @@ TEST_F(AuthCommandTest, ...@@ -276,18 +277,19 @@ TEST_F(AuthCommandTest,
ModuleCCSession moduleSession(SPEC_FILE, session, NULL, NULL, false, ModuleCCSession moduleSession(SPEC_FILE, session, NULL, NULL, false,
false); false);
// This describes the data source in the configuration // This describes the data source in the configuration
ElementPtr map(Element::fromJSON("{\"datasources\": [" const ElementPtr
" {" map(Element::fromJSON("{\"datasources\": ["
" \"type\": \"memory\"," " {"
" \"zones\": [" " \"type\": \"memory\","
" {" " \"zones\": ["
" \"origin\": \"example.org\"," " {"
" \"file\": \"" + test_db + "\"," " \"origin\": \"example.org\","
" \"filetype\": \"sqlite3\"" " \"file\": \"" + test_db + "\","
" }" " \"filetype\": \"sqlite3\""
" ]" " }"
" }" " ]"
"]}")); " }"
"]}"));
moduleSession.setLocalConfig(map); moduleSession.setLocalConfig(map);
server_.setConfigSession(&moduleSession); server_.setConfigSession(&moduleSession);
...@@ -309,6 +311,65 @@ TEST_F(AuthCommandTest, ...@@ -309,6 +311,65 @@ TEST_F(AuthCommandTest,
EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())-> EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())->
findZone(Name("example.org")).zone_finder-> findZone(Name("example.org")).zone_finder->
find(Name("example.org"), RRType::SOA())->code); 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) { TEST_F(AuthCommandTest, loadBrokenZone) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment