|
@@ -244,206 +244,6 @@ newZoneChecks(AuthSrv& server) {
|
|
|
find(Name("ns.test2.example"), RRType::AAAA())->code);
|
|
|
}
|
|
|
|
|
|
-TEST_F(AuthCommandTest, loadZone) {
|
|
|
- configureZones(server_);
|
|
|
-
|
|
|
- ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR
|
|
|
- "/test1-new.zone.in "
|
|
|
- TEST_DATA_BUILDDIR "/test1.zone.copied"));
|
|
|
- ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR
|
|
|
- "/test2-new.zone.in "
|
|
|
- TEST_DATA_BUILDDIR "/test2.zone.copied"));
|
|
|
-
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\"}"));
|
|
|
- checkAnswer(0);
|
|
|
- newZoneChecks(server_);
|
|
|
-}
|
|
|
-
|
|
|
-TEST_F(AuthCommandTest,
|
|
|
-#ifdef USE_STATIC_LINK
|
|
|
- DISABLED_loadZoneSQLite3
|
|
|
-#else
|
|
|
- loadZoneSQLite3
|
|
|
-#endif
|
|
|
- )
|
|
|
-{
|
|
|
- // 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);
|
|
|
- // This describes the data source in the configuration
|
|
|
- const ConstElementPtr config(Element::fromJSON("{"
|
|
|
- "\"IN\": [{"
|
|
|
- " \"type\": \"sqlite3\","
|
|
|
- " \"params\": {\"database_file\": \"" + test_db + "\"},"
|
|
|
- " \"cache-enable\": true,"
|
|
|
- " \"cache-zones\": [\"example.org\"]"
|
|
|
- "}]}"));
|
|
|
- installDataSrcClientLists(server_, configureDataSource(config));
|
|
|
-
|
|
|
- {
|
|
|
- DataSrcClientsMgr::Holder holder(server_.getDataSrcClientsMgr());
|
|
|
-
|
|
|
- // Check that the A record at www.example.org does not exist
|
|
|
- EXPECT_EQ(ZoneFinder::NXDOMAIN,
|
|
|
- holder.findClientList(RRClass::IN())->
|
|
|
- find(Name("example.org")).finder_->
|
|
|
- find(Name("www.example.org"), RRType::A())->code);
|
|
|
-
|
|
|
- // Add the record to the underlying sqlite database, by loading
|
|
|
- // it as a separate datasource, and updating it
|
|
|
- ConstElementPtr sql_cfg = Element::fromJSON("{ \"type\": \"sqlite3\","
|
|
|
- "\"database_file\": \""
|
|
|
- + test_db + "\"}");
|
|
|
- DataSourceClientContainer sql_ds("sqlite3", sql_cfg);
|
|
|
- ZoneUpdaterPtr sql_updater =
|
|
|
- sql_ds.getInstance().getUpdater(Name("example.org"), false);
|
|
|
- RRsetPtr rrset(new RRset(Name("www.example.org."), RRClass::IN(),
|
|
|
- RRType::A(), RRTTL(60)));
|
|
|
- rrset->addRdata(rdata::createRdata(rrset->getType(),
|
|
|
- rrset->getClass(),
|
|
|
- "192.0.2.1"));
|
|
|
- sql_updater->addRRset(*rrset);
|
|
|
- sql_updater->commit();
|
|
|
-
|
|
|
- EXPECT_EQ(ZoneFinder::NXDOMAIN,
|
|
|
- holder.findClientList(RRClass::IN())->
|
|
|
- find(Name("example.org")).finder_->
|
|
|
- find(Name("www.example.org"), RRType::A())->code);
|
|
|
- }
|
|
|
-
|
|
|
- // Now send the command to reload it
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"example.org\"}"));
|
|
|
- checkAnswer(0, "Successful load");
|
|
|
-
|
|
|
- {
|
|
|
- DataSrcClientsMgr::Holder holder(server_.getDataSrcClientsMgr());
|
|
|
- // And now it should be present too.
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS,
|
|
|
- holder.findClientList(RRClass::IN())->
|
|
|
- find(Name("example.org")).finder_->
|
|
|
- find(Name("www.example.org"), RRType::A())->code);
|
|
|
- }
|
|
|
-
|
|
|
- // Some error cases. First, the zone has no configuration. (note .com here)
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON("{\"origin\": \"example.com\"}"));
|
|
|
- checkAnswer(1, "example.com");
|
|
|
-
|
|
|
- {
|
|
|
- DataSrcClientsMgr::Holder holder(server_.getDataSrcClientsMgr());
|
|
|
- // The previous zone is not hurt in any way
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS,
|
|
|
- holder.findClientList(RRClass::IN())->
|
|
|
- find(Name("example.org")).finder_->
|
|
|
- find(Name("example.org"), RRType::SOA())->code);
|
|
|
- }
|
|
|
-
|
|
|
- const ConstElementPtr config2(Element::fromJSON("{"
|
|
|
- "\"IN\": [{"
|
|
|
- " \"type\": \"sqlite3\","
|
|
|
- " \"params\": {\"database_file\": \"" + bad_db + "\"},"
|
|
|
- " \"cache-enable\": true,"
|
|
|
- " \"cache-zones\": [\"example.com\"]"
|
|
|
- "}]}"));
|
|
|
- EXPECT_THROW(configureDataSource(config2),
|
|
|
- ConfigurableClientList::ConfigurationError);
|
|
|
-
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON("{\"origin\": \"example.com\"}"));
|
|
|
- checkAnswer(1, "Unreadable");
|
|
|
-
|
|
|
- DataSrcClientsMgr::Holder holder(server_.getDataSrcClientsMgr());
|
|
|
- // The previous zone is not hurt in any way
|
|
|
- EXPECT_EQ(ZoneFinder::SUCCESS,
|
|
|
- holder.findClientList(RRClass::IN())->
|
|
|
- find(Name("example.org")).finder_->
|
|
|
- find(Name("example.org"), RRType::SOA())->code);
|
|
|
-}
|
|
|
-
|
|
|
-TEST_F(AuthCommandTest, loadBrokenZone) {
|
|
|
- configureZones(server_);
|
|
|
-
|
|
|
- ASSERT_EQ(0, system(INSTALL_PROG " -c " TEST_DATA_DIR
|
|
|
- "/test1-broken.zone.in "
|
|
|
- TEST_DATA_BUILDDIR "/test1.zone.copied"));
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\"}"));
|
|
|
- checkAnswer(1);
|
|
|
- zoneChecks(server_); // zone shouldn't be replaced
|
|
|
-}
|
|
|
-
|
|
|
-TEST_F(AuthCommandTest, loadUnreadableZone) {
|
|
|
- configureZones(server_);
|
|
|
-
|
|
|
- // install the zone file as unreadable
|
|
|
- ASSERT_EQ(0, system(INSTALL_PROG " -c -m 000 " TEST_DATA_DIR
|
|
|
- "/test1.zone.in "
|
|
|
- TEST_DATA_BUILDDIR "/test1.zone.copied"));
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\"}"));
|
|
|
- checkAnswer(1);
|
|
|
- zoneChecks(server_); // zone shouldn't be replaced
|
|
|
-}
|
|
|
-
|
|
|
-TEST_F(AuthCommandTest, loadZoneWithoutDataSrc) {
|
|
|
- // try to execute load command without configuring the zone beforehand.
|
|
|
- // it should fail.
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\"}"));
|
|
|
- checkAnswer(1);
|
|
|
-}
|
|
|
-
|
|
|
-TEST_F(AuthCommandTest, loadZoneInvalidParams) {
|
|
|
- configureZones(server_);
|
|
|
-
|
|
|
- // null arg
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone", ElementPtr());
|
|
|
- checkAnswer(1, "Null arg");
|
|
|
-
|
|
|
- // zone class is bogus
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\","
|
|
|
- " \"class\": \"no_such_class\"}"));
|
|
|
- checkAnswer(1, "No such class");
|
|
|
-
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"test1.example\","
|
|
|
- " \"class\": 1}"));
|
|
|
- checkAnswer(1, "Integral class");
|
|
|
-
|
|
|
-
|
|
|
- // origin is missing
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON("{}"));
|
|
|
- checkAnswer(1, "Missing origin");
|
|
|
-
|
|
|
- // zone doesn't exist in the data source
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON("{\"origin\": \"xx\"}"));
|
|
|
- checkAnswer(1, "No such zone");
|
|
|
-
|
|
|
- // origin is bogus
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON(
|
|
|
- "{\"origin\": \"...\"}"));
|
|
|
- checkAnswer(1, "Wrong name");
|
|
|
-
|
|
|
- result_ = execAuthServerCommand(server_, "loadzone",
|
|
|
- Element::fromJSON("{\"origin\": 10}"));
|
|
|
- checkAnswer(1, "Integral name");
|
|
|
-}
|
|
|
-
|
|
|
TEST_F(AuthCommandTest, getStats) {
|
|
|
result_ = execAuthServerCommand(server_, "getstats", ConstElementPtr());
|
|
|
parseAnswer(rcode_, result_);
|