]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2212] ported command test's loadZoneInvalidParams
authorJINMEI Tatuya <jinmei@isc.org>
Tue, 23 Oct 2012 06:22:26 +0000 (23:22 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Thu, 25 Oct 2012 22:02:56 +0000 (15:02 -0700)
src/bin/auth/datasrc_clients_mgr.h
src/bin/auth/tests/datasrc_clients_builder_unittest.cc

index aef7f02a910e3321b100800b5cebd9cf971b3963..21572eebd3bac0cb1b8a39a1d998635857e85aa1 100644 (file)
@@ -475,6 +475,8 @@ void
 DataSrcClientsBuilderBase<MutexType, CondVarType>::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());
index df1ca8cae1a499f906b35623793d66d84be04f79..d8a2a3d482517db07d0bed28c1cdd0d9b63ee5ed 100644 (file)
@@ -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