Browse Source

[1807] return NSEC data on other ENT cases

Jelte Jansen 13 years ago
parent
commit
7468970f43
2 changed files with 39 additions and 18 deletions
  1. 4 2
      src/lib/datasrc/memory_datasrc.cc
  2. 35 16
      src/lib/datasrc/tests/memory_datasrc_unittest.cc

+ 4 - 2
src/lib/datasrc/memory_datasrc.cc

@@ -219,7 +219,6 @@ public:
                         RBTreeNodeChain<Domain>& node_path,
                         ZoneFinder::FindOptions options) const;
 
-private:
     // A helper method for NSEC-signed zones.  It searches the zone for
     // the "closest" NSEC corresponding to the search context stored in
     // node_path (it should contain sufficient information to identify the
@@ -1309,7 +1308,10 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl {
         if (node->isEmpty()) {
             LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DOMAIN_EMPTY).
                 arg(name);
-            return (createFindResult(NXRRSET, ConstRBNodeRRsetPtr(), rename));
+            return (createFindResult(NXRRSET,
+                                     zone_data_->getClosestNSEC(node_path,
+                                                                options),
+                                     rename));
         }
 
         Domain::const_iterator found;

+ 35 - 16
src/lib/datasrc/tests/memory_datasrc_unittest.cc

@@ -385,6 +385,9 @@ protected:
                           ZoneFinder::RESULT_DEFAULT);
     void emptyWildcardCheck(ZoneFinder::FindResultFlags expected_flags =
                             ZoneFinder::RESULT_DEFAULT);
+    void findNSECENTCheck(const Name& ent_name,
+                          ZoneFinder::FindResultFlags expected_flags =
+                          ZoneFinder::RESULT_DEFAULT);
 
 public:
     InMemoryZoneFinderTest() :
@@ -443,10 +446,6 @@ public:
              &rr_nsec3_},
             {"example.org. 300 IN NSEC cname.example.org. A NS NSEC",
              &rr_nsec_},
-            {"www.ent.example.org. 300 IN A 192.0.2.1",
-             &rr_ent_},
-            {"example.org. 300 IN NSEC www.ent.example.org. A NS NSEC",
-             &rr_ent_nsec_},
             {NULL, NULL}
         };
 
@@ -512,8 +511,6 @@ public:
     RRsetPtr rr_not_wild_another_;
     RRsetPtr rr_nsec3_;
     RRsetPtr rr_nsec_;
-    RRsetPtr rr_ent_;
-    RRsetPtr rr_ent_nsec_;
 
     // A faked NSEC3 hash calculator for convenience.
     // Tests that need to use the faked hashed values should call
@@ -1045,29 +1042,44 @@ TEST_F(InMemoryZoneFinderTest, findNSECSigned) {
     findCheck(ZoneFinder::RESULT_NSEC_SIGNED);
 }
 
-TEST_F(InMemoryZoneFinderTest,findNSECEmptyNonterminal) {
-    zone_finder_.add(rr_ent_);
-    const Name ent_name = Name("ent.example.org");
+// Generalized test for Empty Nonterminal (ENT) cases with NSEC
+void
+InMemoryZoneFinderTest::findNSECENTCheck(const Name& ent_name,
+    ZoneFinder::FindResultFlags expected_flags)
+{
+    EXPECT_EQ(SUCCESS, zone_finder_.add(rr_emptywild_));
 
     // Sanity check: Should result in NXRRSET
     findTest(ent_name, RRType::A(), ZoneFinder::NXRRSET, true,
-             ConstRRsetPtr());
+             ConstRRsetPtr(), expected_flags);
     // Sanity check: No NSEC added yet
     findTest(ent_name, RRType::A(), ZoneFinder::NXRRSET, true,
-             ConstRRsetPtr(), ZoneFinder::RESULT_DEFAULT,
+             ConstRRsetPtr(), expected_flags,
              NULL, ZoneFinder::FIND_DNSSEC);
 
-    zone_finder_.add(rr_ent_nsec_);
+    zone_finder_.add(rr_nsec_);
     // Should result in NXRRSET, and RESULT_NSEC_SIGNED
     findTest(ent_name, RRType::A(), ZoneFinder::NXRRSET, true,
-             ConstRRsetPtr(), ZoneFinder::RESULT_NSEC_SIGNED);
+             ConstRRsetPtr(),
+             expected_flags | ZoneFinder::RESULT_NSEC_SIGNED);
 
     // And check for the NSEC if DNSSEC_OK
     findTest(ent_name, RRType::A(), ZoneFinder::NXRRSET, true,
-             rr_ent_nsec_, ZoneFinder::RESULT_NSEC_SIGNED,
+             rr_nsec_, expected_flags | ZoneFinder::RESULT_NSEC_SIGNED,
              NULL, ZoneFinder::FIND_DNSSEC);
 }
 
+TEST_F(InMemoryZoneFinderTest,findNSECEmptyNonterminal) {
+    // Non-wildcard case
+    findNSECENTCheck(Name("foo.example.org"));
+}
+
+TEST_F(InMemoryZoneFinderTest,findNSECEmptyNonterminalWildcard) {
+    // Wildcard case
+    findNSECENTCheck(Name("bar.foo.example.org"), ZoneFinder::RESULT_WILDCARD);
+}
+
+
 void
 InMemoryZoneFinderTest::emptyNodeCheck(
     ZoneFinder::FindResultFlags expected_flags)
@@ -1272,8 +1284,15 @@ InMemoryZoneFinderTest::wildcardCheck(
     // be in the wildcard (so check the wildcard isn't matched at the parent)
     {
         SCOPED_TRACE("Search at parent");
-        findTest(Name("wild.example.org"), RRType::A(), ZoneFinder::NXRRSET,
-                 true, ConstRRsetPtr(), expected_flags, NULL, find_options);
+        if ((expected_flags & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
+            findTest(Name("wild.example.org"), RRType::A(),
+                     ZoneFinder::NXRRSET, true, rr_nsec_, expected_flags,
+                     NULL, find_options);
+        } else {
+            findTest(Name("wild.example.org"), RRType::A(),
+                     ZoneFinder::NXRRSET, true, ConstRRsetPtr(),
+                     expected_flags, NULL, find_options);
+        }
     }
 
     // Search the original name of wildcard