From: JINMEI Tatuya Date: Tue, 23 Oct 2012 06:22:26 +0000 (-0700) Subject: [2212] ported command test's loadZoneInvalidParams X-Git-Tag: trac2487_base~23^2~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=edcbc935eb6ddc4bb5fac1e76e8eac100e783e74;p=thirdparty%2Fkea.git [2212] ported command test's loadZoneInvalidParams --- diff --git a/src/bin/auth/datasrc_clients_mgr.h b/src/bin/auth/datasrc_clients_mgr.h index aef7f02a91..21572eebd3 100644 --- a/src/bin/auth/datasrc_clients_mgr.h +++ b/src/bin/auth/datasrc_clients_mgr.h @@ -475,6 +475,8 @@ void DataSrcClientsBuilderBase::doLoadZone( const isc::data::ConstElementPtr& arg) { + assert(arg); + // TODO: test bogus class and name const dns::RRClass rrclass(arg->get("class")->stringValue()); const dns::Name origin(arg->get("origin")->stringValue()); diff --git a/src/bin/auth/tests/datasrc_clients_builder_unittest.cc b/src/bin/auth/tests/datasrc_clients_builder_unittest.cc index df1ca8cae1..d8a2a3d482 100644 --- a/src/bin/auth/tests/datasrc_clients_builder_unittest.cc +++ b/src/bin/auth/tests/datasrc_clients_builder_unittest.cc @@ -379,7 +379,22 @@ TEST_F(DataSrcClientsBuilderTest, loadBrokenZone) { "/test1-broken.zone.in " TEST_DATA_BUILDDIR "/test1.zone.copied")); // there's an error in the new zone file. reload will be rejected. - const Command loadzone_cmd(LOADZONE, isc::data::Element::fromJSON( + const Command loadzone_cmd(LOADZONE, Element::fromJSON( + "{\"class\": \"IN\"," + " \"origin\": \"test1.example\"}")); + EXPECT_THROW(builder.handleCommand(loadzone_cmd), + TestDataSrcClientsBuilder::InternalCommandError); + zoneChecks(clients_map, rrclass); // zone shouldn't be replaced +} + +TEST_F(DataSrcClientsBuilderTest, loadUnreadableZone) { + configureZones(); + + // install the zone file as unreadable + ASSERT_EQ(0, std::system(INSTALL_PROG " -c -m 000 " TEST_DATA_DIR + "/test1.zone.in " + TEST_DATA_BUILDDIR "/test1.zone.copied")); + const Command loadzone_cmd(LOADZONE, Element::fromJSON( "{\"class\": \"IN\"," " \"origin\": \"test1.example\"}")); EXPECT_THROW(builder.handleCommand(loadzone_cmd), @@ -387,5 +402,61 @@ TEST_F(DataSrcClientsBuilderTest, loadBrokenZone) { zoneChecks(clients_map, rrclass); // zone shouldn't be replaced } +TEST_F(DataSrcClientsBuilderTest, loadZoneInvalidParams) { + configureZones(); + + // null arg: this causes assertion failure + EXPECT_DEATH_IF_SUPPORTED({ + builder.handleCommand(Command(LOADZONE, ElementPtr())); + }, ""); + + // zone class is bogus (note that this shouldn't happen except in tests) + EXPECT_THROW(builder.handleCommand( + Command(LOADZONE, + Element::fromJSON( + "{\"origin\": \"test1.example\"," + " \"class\": \"no_such_class\"}"))), + InvalidRRClass); + + // not a string + EXPECT_THROW(builder.handleCommand( + Command(LOADZONE, + Element::fromJSON( + "{\"origin\": \"test1.example\"," + " \"class\": 1}"))), + isc::data::TypeError); + + // class or origin is missing: result in assertion failure + EXPECT_DEATH_IF_SUPPORTED({ + builder.handleCommand( + Command(LOADZONE, + Element::fromJSON("{\"origin\": \"test1.example\"}"))); + }, ""); + EXPECT_DEATH_IF_SUPPORTED({ + builder.handleCommand(Command(LOADZONE, + Element::fromJSON( + "{\"class\": \"IN\"}"))); + }, ""); + + // zone doesn't exist in the data source + EXPECT_THROW( + builder.handleCommand( + Command(LOADZONE, + Element::fromJSON( + "{\"class\": \"IN\", \"origin\": \"xx\"}"))), + TestDataSrcClientsBuilder::InternalCommandError); + + // origin is bogus + EXPECT_THROW(builder.handleCommand( + Command(LOADZONE, + Element::fromJSON( + "{\"class\": \"IN\", \"origin\": \"...\"}"))), + EmptyLabel); + EXPECT_THROW(builder.handleCommand( + Command(LOADZONE, + Element::fromJSON( + "{\"origin\": 10, \"class\": 1}"))), + isc::data::TypeError); +} } // unnamed namespace