123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #include <cassert>
- #include <cstdlib>
- #include <string>
- #include <stdexcept>
- #include <boost/bind.hpp>
- #include <gtest/gtest.h>
- #include <dns/name.h>
- #include <dns/rrclass.h>
- #include <dns/rrtype.h>
- #include <cc/data.h>
- #include <config/ccsession.h>
- #include <datasrc/memory_datasrc.h>
- #include <auth/auth_srv.h>
- #include <auth/config.h>
- #include <auth/command.h>
- #include <asiolink/asiolink.h>
- #include <testutils/mockups.h>
- using namespace std;
- using namespace isc::dns;
- using namespace isc::data;
- using namespace isc::datasrc;
- using namespace isc::config;
- namespace {
- class AuthConmmandTest : public ::testing::Test {
- protected:
- AuthConmmandTest() : server(false, xfrout), rcode(-1) {
- server.setStatisticsSession(&statistics_session);
- }
- void checkAnswer(const int expected_code) {
- parseAnswer(rcode, result);
- EXPECT_EQ(expected_code, rcode);
- }
- MockSession statistics_session;
- MockXfroutClient xfrout;
- AuthSrv server;
- AuthSrv::ConstMemoryDataSrcPtr memory_datasrc;
- ConstElementPtr result;
- int rcode;
- public:
- void stopServer();
- };
- TEST_F(AuthConmmandTest, unknownCommand) {
- result = execAuthServerCommand(server, "no_such_command",
- ConstElementPtr());
- parseAnswer(rcode, result);
- EXPECT_EQ(1, rcode);
- }
- TEST_F(AuthConmmandTest, DISABLED_unexpectedException) {
-
-
-
- EXPECT_THROW(execAuthServerCommand(server, "_throw_exception",
- ConstElementPtr()),
- runtime_error);
- }
- TEST_F(AuthConmmandTest, sendStatistics) {
- result = execAuthServerCommand(server, "sendstats", ConstElementPtr());
-
-
- EXPECT_EQ("Stats", statistics_session.getMessageDest());
- checkAnswer(0);
- }
- void
- AuthConmmandTest::stopServer() {
- result = execAuthServerCommand(server, "shutdown", ConstElementPtr());
- parseAnswer(rcode, result);
- assert(rcode == 0);
- }
- TEST_F(AuthConmmandTest, shutdown) {
- asiolink::IntervalTimer itimer(server.getIOService());
- itimer.setup(boost::bind(&AuthConmmandTest::stopServer, this), 1);
- server.getIOService().run();
- EXPECT_EQ(0, rcode);
- }
- void
- zoneChecks(AuthSrv& server) {
- EXPECT_TRUE(server.getMemoryDataSrc(RRClass::IN()));
- EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test1.example")).zone->
- find(Name("ns.test1.example"), RRType::A()).code);
- EXPECT_EQ(Zone::NXRRSET, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test1.example")).zone->
- find(Name("ns.test1.example"), RRType::AAAA()).code);
- EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test2.example")).zone->
- find(Name("ns.test2.example"), RRType::A()).code);
- EXPECT_EQ(Zone::NXRRSET, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test2.example")).zone->
- find(Name("ns.test2.example"), RRType::AAAA()).code);
- }
- void
- configureZones(AuthSrv& server) {
- ASSERT_EQ(0, system(INSTALL_PROG " " TEST_DATA_DIR "/test1.zone.in "
- TEST_DATA_BUILDDIR "/test1.zone.copied"));
- ASSERT_EQ(0, system(INSTALL_PROG " " 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\"}"
- "]}]}"));
- zoneChecks(server);
- }
- void
- newZoneChecks(AuthSrv& server) {
- EXPECT_TRUE(server.getMemoryDataSrc(RRClass::IN()));
- EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test1.example")).zone->
- find(Name("ns.test1.example"), RRType::A()).code);
-
- EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test1.example")).zone->
- find(Name("ns.test1.example"), RRType::AAAA()).code);
-
- EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test2.example")).zone->
- find(Name("ns.test2.example"), RRType::A()).code);
- EXPECT_EQ(Zone::NXRRSET, server.getMemoryDataSrc(RRClass::IN())->
- findZone(Name("ns.test2.example")).zone->
- find(Name("ns.test2.example"), RRType::AAAA()).code);
- }
- TEST_F(AuthConmmandTest, loadZone) {
- configureZones(server);
- ASSERT_EQ(0, system(INSTALL_PROG " " TEST_DATA_DIR
- "/test1-new.zone.in "
- TEST_DATA_BUILDDIR "/test1.zone.copied"));
- ASSERT_EQ(0, system(INSTALL_PROG " " 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(AuthConmmandTest, loadBrokenZone) {
- configureZones(server);
- ASSERT_EQ(0, system(INSTALL_PROG " " 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);
- }
- TEST_F(AuthConmmandTest, loadUnreadableZone) {
- configureZones(server);
-
- ASSERT_EQ(0, system(INSTALL_PROG " -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);
- }
- TEST_F(AuthConmmandTest, loadZoneWithoutDataSrc) {
-
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\"}"));
- checkAnswer(1);
- }
- TEST_F(AuthConmmandTest, loadSqlite3DataSrc) {
-
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"datasrc\": \"sqlite3\"}"));
- checkAnswer(0);
- }
- TEST_F(AuthConmmandTest, loadZoneInvalidParams) {
- configureZones(server);
-
- result = execAuthServerCommand(server, "loadzone", ElementPtr());
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"class\": \"no_such_class\"}"));
- checkAnswer(1);
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"class\": 1}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"class\": \"CH\"}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"datasrc\": \"not supported\"}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"test1.example\","
- " \"datasrc\": 0}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON("{}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON("{\"origin\": \"xx\"}"));
- checkAnswer(1);
-
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON(
- "{\"origin\": \"...\"}"));
- checkAnswer(1);
- result = execAuthServerCommand(server, "loadzone",
- Element::fromJSON("{\"origin\": 10}"));
- checkAnswer(1);
- }
- }
|