|
@@ -19,6 +19,7 @@
|
|
|
#include <auth/auth_srv.h>
|
|
|
#include <auth/auth_config.h>
|
|
|
#include <auth/command.h>
|
|
|
+#include <auth/datasrc_configurator.h>
|
|
|
|
|
|
#include <dns/name.h>
|
|
|
#include <dns/rrclass.h>
|
|
@@ -69,7 +70,9 @@ protected:
|
|
|
{
|
|
|
server_.setStatisticsSession(&statistics_session_);
|
|
|
}
|
|
|
- void checkAnswer(const int expected_code) {
|
|
|
+ void checkAnswer(const int expected_code, const char* name = "") {
|
|
|
+ SCOPED_TRACE(name);
|
|
|
+
|
|
|
parseAnswer(rcode_, result_);
|
|
|
EXPECT_EQ(expected_code, rcode_) << result_->str();
|
|
|
}
|
|
@@ -177,29 +180,24 @@ TEST_F(AuthCommandTest, shutdownIncorrectPID) {
|
|
|
EXPECT_EQ(0, rcode_);
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-TODO: This needs to be rewritten
|
|
|
-Also, reenable everywhere
|
|
|
// A helper function commonly used for the "loadzone" command tests.
|
|
|
// It configures the server with a memory data source containing two
|
|
|
// zones, and checks the zones are correctly loaded.
|
|
|
void
|
|
|
zoneChecks(AuthSrv& server) {
|
|
|
- EXPECT_TRUE(server.getInMemoryClient(RRClass::IN()));
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test1.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test1.example")).finder_->
|
|
|
find(Name("ns.test1.example"), RRType::A())->code);
|
|
|
- EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test1.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test1.example")).finder_->
|
|
|
find(Name("ns.test1.example"), RRType::AAAA())->code);
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test2.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test2.example")).finder_->
|
|
|
find(Name("ns.test2.example"), RRType::A())->code);
|
|
|
- EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test2.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test2.example")).finder_->
|
|
|
find(Name("ns.test2.example"), RRType::AAAA())->code);
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
void
|
|
|
configureZones(AuthSrv& server) {
|
|
@@ -207,51 +205,44 @@ configureZones(AuthSrv& server) {
|
|
|
TEST_DATA_BUILDDIR "/test1.zone.copied"));
|
|
|
ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR "/test2.zone.in "
|
|
|
TEST_DATA_BUILDDIR "/test2.zone.copied"));
|
|
|
- configureAuthServer(server, Element::fromJSON(
|
|
|
- "{\"datasources\": "
|
|
|
- " [{\"type\": \"memory\","
|
|
|
- " \"zones\": "
|
|
|
- "[{\"origin\": \"test1.example\","
|
|
|
- " \"file\": \""
|
|
|
- TEST_DATA_BUILDDIR "/test1.zone.copied\"},"
|
|
|
- " {\"origin\": \"test2.example\","
|
|
|
- " \"file\": \""
|
|
|
- TEST_DATA_BUILDDIR "/test2.zone.copied\"}"
|
|
|
- "]}]}"));
|
|
|
- //TODO: zoneChecks(server);
|
|
|
+
|
|
|
+ const ConstElementPtr config(Element::fromJSON("{"
|
|
|
+ "\"IN\": [{"
|
|
|
+ " \"type\": \"MasterFiles\","
|
|
|
+ " \"params\": {"
|
|
|
+ " \"test1.example\": \"" +
|
|
|
+ string(TEST_DATA_BUILDDIR "/test1.zone.copied") + "\","
|
|
|
+ " \"test2.example\": \"" +
|
|
|
+ string(TEST_DATA_BUILDDIR "/test2.zone.copied") + "\""
|
|
|
+ " },"
|
|
|
+ " \"cache-enable\": true"
|
|
|
+ "}]}"));
|
|
|
+
|
|
|
+ DataSourceConfigurator::testReconfigure(&server, config);
|
|
|
+
|
|
|
+ zoneChecks(server);
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
-TODO: This needs to be rewritten and re-enabled
|
|
|
void
|
|
|
newZoneChecks(AuthSrv& server) {
|
|
|
- EXPECT_TRUE(server.getInMemoryClient(RRClass::IN()));
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test1.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test1.example")).finder_->
|
|
|
find(Name("ns.test1.example"), RRType::A())->code);
|
|
|
// now test1.example should have ns/AAAA
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test1.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test1.example")).finder_->
|
|
|
find(Name("ns.test1.example"), RRType::AAAA())->code);
|
|
|
|
|
|
// test2.example shouldn't change
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test2.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test2.example")).finder_->
|
|
|
find(Name("ns.test2.example"), RRType::A())->code);
|
|
|
- EXPECT_EQ(ZoneFinder::NXRRSET, server.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("ns.test2.example")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::NXRRSET, server.getClientList(RRClass::IN())->
|
|
|
+ find(Name("ns.test2.example")).finder_->
|
|
|
find(Name("ns.test2.example"), RRType::AAAA())->code);
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
-TEST_F(AuthCommandTest,
|
|
|
-#ifdef USE_STATIC_LINK
|
|
|
- DISABLED_loadZone
|
|
|
-#else
|
|
|
- DISABLED_loadZone // Needs #2046
|
|
|
-#endif
|
|
|
- )
|
|
|
-{
|
|
|
+TEST_F(AuthCommandTest, loadZone) {
|
|
|
configureZones(server_);
|
|
|
|
|
|
ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR
|
|
@@ -265,62 +256,36 @@ TEST_F(AuthCommandTest,
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"test1.example\"}"));
|
|
|
checkAnswer(0);
|
|
|
- //TODO: newZoneChecks(server_);
|
|
|
+ newZoneChecks(server_);
|
|
|
}
|
|
|
|
|
|
TEST_F(AuthCommandTest,
|
|
|
#ifdef USE_STATIC_LINK
|
|
|
DISABLED_loadZoneSQLite3
|
|
|
#else
|
|
|
- DISABLED_loadZoneSQLite3 // Needs #2044
|
|
|
+ loadZoneSQLite3
|
|
|
#endif
|
|
|
)
|
|
|
{
|
|
|
- const char* const SPEC_FILE = AUTH_OBJ_DIR "/auth.spec";
|
|
|
-
|
|
|
// 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);
|
|
|
-
|
|
|
- // Then store a config of the zone to the auth server
|
|
|
- // This omits many config options of the auth server, but these are
|
|
|
- // not read now.
|
|
|
- isc::testutils::MockSession session;
|
|
|
- // The session should not take care of anything or start anything, we
|
|
|
- // need it only to hold the config we're going to put into it.
|
|
|
- ModuleCCSession module_session(SPEC_FILE, session, NULL, NULL, false,
|
|
|
- false);
|
|
|
// This describes the data source in the configuration
|
|
|
- const ElementPtr
|
|
|
- map(Element::fromJSON("{\"datasources\": ["
|
|
|
- " {"
|
|
|
- " \"type\": \"memory\","
|
|
|
- " \"zones\": ["
|
|
|
- " {"
|
|
|
- " \"origin\": \"example.org\","
|
|
|
- " \"file\": \"" + test_db + "\","
|
|
|
- " \"filetype\": \"sqlite3\""
|
|
|
- " }"
|
|
|
- " ]"
|
|
|
- " }"
|
|
|
- "],"
|
|
|
- " \"database_file\": \"" + test_db + "\""
|
|
|
- "}"));
|
|
|
- module_session.setLocalConfig(map);
|
|
|
- server_.setConfigSession(&module_session);
|
|
|
-
|
|
|
- server_.updateConfig(map);
|
|
|
-
|
|
|
-#if 0
|
|
|
- FIXME: This needs to be done slightly differently
|
|
|
+ const ConstElementPtr config(Element::fromJSON("{"
|
|
|
+ "\"IN\": [{"
|
|
|
+ " \"type\": \"sqlite3\","
|
|
|
+ " \"params\": {\"database_file\": \"" + test_db + "\"},"
|
|
|
+ " \"cache-enable\": true,"
|
|
|
+ " \"cache-zones\": [\"example.org\"]"
|
|
|
+ "}]}"));
|
|
|
+ DataSourceConfigurator::testReconfigure(&server_, config);
|
|
|
+
|
|
|
// Check that the A record at www.example.org does not exist
|
|
|
- ASSERT_TRUE(server_.hasInMemoryClient());
|
|
|
- EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("example.org")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getClientList(RRClass::IN())->
|
|
|
+ find(Name("example.org")).finder_->
|
|
|
find(Name("www.example.org"), RRType::A())->code);
|
|
|
-#endif
|
|
|
|
|
|
// Add the record to the underlying sqlite database, by loading
|
|
|
// it as a separate datasource, and updating it
|
|
@@ -338,107 +303,52 @@ TEST_F(AuthCommandTest,
|
|
|
sql_updater->addRRset(*rrset);
|
|
|
sql_updater->commit();
|
|
|
|
|
|
-#if 0
|
|
|
- TODO:
|
|
|
- // This new record is in the database now, but should not be in the
|
|
|
- // memory-datasource yet, so check again
|
|
|
- EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("example.org")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::NXDOMAIN, server_.getClientList(RRClass::IN())->
|
|
|
+ find(Name("example.org")).finder_->
|
|
|
find(Name("www.example.org"), RRType::A())->code);
|
|
|
-#endif
|
|
|
|
|
|
// Now send the command to reload it
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"example.org\"}"));
|
|
|
- checkAnswer(0);
|
|
|
+ checkAnswer(0, "Successfull load");
|
|
|
|
|
|
-#if 0
|
|
|
// And now it should be present too.
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("example.org")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
|
|
|
+ find(Name("example.org")).finder_->
|
|
|
find(Name("www.example.org"), RRType::A())->code);
|
|
|
-#endif
|
|
|
|
|
|
// Some error cases. First, the zone has no configuration. (note .com here)
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON("{\"origin\": \"example.com\"}"));
|
|
|
- checkAnswer(1);
|
|
|
-#if 0
|
|
|
- FIXME
|
|
|
+ checkAnswer(1, "example.com");
|
|
|
+
|
|
|
// The previous zone is not hurt in any way
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("example.org")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
|
|
|
+ find(Name("example.org")).finder_->
|
|
|
find(Name("example.org"), RRType::SOA())->code);
|
|
|
-#endif
|
|
|
|
|
|
- module_session.setLocalConfig(Element::fromJSON("{\"datasources\": []}"));
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"example.org\"}"));
|
|
|
- checkAnswer(1);
|
|
|
+ const ConstElementPtr config2(Element::fromJSON("{"
|
|
|
+ "\"IN\": [{"
|
|
|
+ " \"type\": \"sqlite3\","
|
|
|
+ " \"params\": {\"database_file\": \"" + bad_db + "\"},"
|
|
|
+ " \"cache-enable\": true,"
|
|
|
+ " \"cache-zones\": [\"example.com\"]"
|
|
|
+ "}]}"));
|
|
|
+ EXPECT_THROW(DataSourceConfigurator::testReconfigure(&server_, config2),
|
|
|
+ ConfigurableClientList::ConfigurationError);
|
|
|
|
|
|
-#if 0
|
|
|
- FIXME
|
|
|
- // 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);
|
|
|
-#endif
|
|
|
- // 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\""
|
|
|
- " }"
|
|
|
- " ]"
|
|
|
- " }"
|
|
|
- "]}"));
|
|
|
- module_session.setLocalConfig(mapBad);
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON("{\"origin\": \"example.com\"}"));
|
|
|
- checkAnswer(1);
|
|
|
-#if 0
|
|
|
- FIXME
|
|
|
- // 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);
|
|
|
-#endif
|
|
|
+ checkAnswer(1, "Unreadable");
|
|
|
|
|
|
- // Broken configuration (not valid against the spec)
|
|
|
- const ElementPtr
|
|
|
- broken(Element::fromJSON("{\"datasources\": ["
|
|
|
- " {"
|
|
|
- " \"type\": \"memory\","
|
|
|
- " \"zones\": [[]]"
|
|
|
- " }"
|
|
|
- "]}"));
|
|
|
- module_session.setLocalConfig(broken);
|
|
|
- checkAnswer(1);
|
|
|
-#if 0
|
|
|
- FIXME
|
|
|
// The previous zone is not hurt in any way
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS, server_.getInMemoryClient(RRClass::IN())->
|
|
|
- findZone(Name("example.org")).zone_finder->
|
|
|
+ EXPECT_EQ(ZoneFinder::SUCCESS, server_.getClientList(RRClass::IN())->
|
|
|
+ find(Name("example.org")).finder_->
|
|
|
find(Name("example.org"), RRType::SOA())->code);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
-TEST_F(AuthCommandTest,
|
|
|
-#ifdef USE_STATIC_LINK
|
|
|
- DISABLED_loadBrokenZone
|
|
|
-#else
|
|
|
- DISABLED_loadBrokenZone // Needs #2046
|
|
|
-#endif
|
|
|
- )
|
|
|
-{
|
|
|
+TEST_F(AuthCommandTest, loadBrokenZone) {
|
|
|
configureZones(server_);
|
|
|
|
|
|
ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR
|
|
@@ -448,17 +358,10 @@ TEST_F(AuthCommandTest,
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"test1.example\"}"));
|
|
|
checkAnswer(1);
|
|
|
- //zoneChecks(server_); // zone shouldn't be replaced
|
|
|
+ zoneChecks(server_); // zone shouldn't be replaced
|
|
|
}
|
|
|
|
|
|
-TEST_F(AuthCommandTest,
|
|
|
-#ifdef USE_STATIC_LINK
|
|
|
- DISABLED_loadUnreadableZone
|
|
|
-#else
|
|
|
- DISABLED_loadUnreadableZone // Needs #2046
|
|
|
-#endif
|
|
|
- )
|
|
|
-{
|
|
|
+TEST_F(AuthCommandTest, loadUnreadableZone) {
|
|
|
configureZones(server_);
|
|
|
|
|
|
// install the zone file as unreadable
|
|
@@ -469,7 +372,7 @@ TEST_F(AuthCommandTest,
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"test1.example\"}"));
|
|
|
checkAnswer(1);
|
|
|
- //zoneChecks(server_); // zone shouldn't be replaced
|
|
|
+ zoneChecks(server_); // zone shouldn't be replaced
|
|
|
}
|
|
|
|
|
|
TEST_F(AuthCommandTest, loadZoneWithoutDataSrc) {
|
|
@@ -481,72 +384,45 @@ TEST_F(AuthCommandTest, loadZoneWithoutDataSrc) {
|
|
|
checkAnswer(1);
|
|
|
}
|
|
|
|
|
|
-TEST_F(AuthCommandTest,
|
|
|
-#ifdef USE_STATIC_LINK
|
|
|
- DISABLED_loadZoneInvalidParams
|
|
|
-#else
|
|
|
- DISABLED_loadZoneInvalidParams // Needs #2046
|
|
|
-#endif
|
|
|
- )
|
|
|
-{
|
|
|
+TEST_F(AuthCommandTest, loadZoneInvalidParams) {
|
|
|
configureZones(server_);
|
|
|
|
|
|
// null arg
|
|
|
result_ = execAuthServerCommand(server_, "loadzone", ElementPtr());
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "Null arg");
|
|
|
|
|
|
// zone class is bogus
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"test1.example\","
|
|
|
" \"class\": \"no_such_class\"}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "No such class");
|
|
|
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"test1.example\","
|
|
|
" \"class\": 1}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "Integral class");
|
|
|
|
|
|
- // unsupported zone class
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\","
|
|
|
- " \"class\": \"CH\"}"));
|
|
|
- checkAnswer(1);
|
|
|
-
|
|
|
- // unsupported data source class
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\","
|
|
|
- " \"datasrc\": \"not supported\"}"));
|
|
|
- checkAnswer(1);
|
|
|
-
|
|
|
- // data source is bogus
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\","
|
|
|
- " \"datasrc\": 0}"));
|
|
|
- checkAnswer(1);
|
|
|
|
|
|
// origin is missing
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON("{}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "Missing origin");
|
|
|
|
|
|
// zone doesn't exist in the data source
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON("{\"origin\": \"xx\"}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "No such zone");
|
|
|
|
|
|
// origin is bogus
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON(
|
|
|
"{\"origin\": \"...\"}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "Wrong name");
|
|
|
|
|
|
result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
Element::fromJSON("{\"origin\": 10}"));
|
|
|
- checkAnswer(1);
|
|
|
+ checkAnswer(1, "Integral name");
|
|
|
}
|
|
|
}
|