]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
A few unit tests
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 1 Feb 2023 14:45:05 +0000 (15:45 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 10 Feb 2023 13:55:19 +0000 (14:55 +0100)
pdns/recursordist/aggressive_nsec.cc
pdns/recursordist/aggressive_nsec.hh
pdns/recursordist/test-aggressive_nsec_cc.cc

index 61cd873bb9de2f0625eeda8a90d980234c6c6803..fbd338a3f3e45a0af6dd342a0bca4f1f55479e05 100644 (file)
@@ -256,10 +256,9 @@ static size_t computeCommonPrefix(const string& one, const string& two)
 
 // If the NSEC3 hashes have a long common prefix, they deny only a small subset of all possible hashes
 // So don't take the trouble to store those.
-static bool isSmallCoveringNSEC3(const DNSName& owner, const std::shared_ptr<NSEC3RecordContent>& nsec)
+bool AggressiveNSECCache::isSmallCoveringNSEC3(const DNSName& owner, const std::string& nextHash)
 {
   std::string ownerHash(fromBase32Hex(owner.getRawLabel(0)));
-  const std::string& nextHash = nsec->d_nexthash;
   auto commonPrefix = computeCommonPrefix(ownerHash, nextHash);
   return commonPrefix > AggressiveNSECCache::s_maxNSEC3CommonPrefix;
 }
@@ -314,7 +313,7 @@ void AggressiveNSECCache::insertNSEC(const DNSName& zone, const DNSName& owner,
         return;
       }
 
-      if (isSmallCoveringNSEC3(owner, content)) {
+      if (isSmallCoveringNSEC3(owner, content->d_nexthash)) {
         /* not accepting small covering answers since they only deny a small subset */
         return;
       }
index 64b23ea3a4e961f4928ac074a874683c9315c228..b2b48083f93a4eee0b490ca3c0613c3f8517372f 100644 (file)
@@ -78,6 +78,9 @@ public:
     return d_nsec3WildcardHits;
   }
 
+  // exported for unit test purposes
+  static bool isSmallCoveringNSEC3(const DNSName& owner, const std::string& nextHash);
+
   void prune(time_t now);
   size_t dumpToFile(std::unique_ptr<FILE, int (*)(FILE*)>& fp, const struct timeval& now);
 
index 7e0058efca6c215db30dee1c51b7009f5f8a9a6e..2968450daef2e8f93dd6b084830832a60a933647 100644 (file)
@@ -6,6 +6,26 @@
 
 BOOST_AUTO_TEST_SUITE(aggressive_nsec_cc)
 
+BOOST_AUTO_TEST_CASE(test_small_coverering_nsec3)
+{
+  AggressiveNSECCache::s_maxNSEC3CommonPrefix = 1;
+
+  const std::tuple<string, string, uint8_t, bool> table[] = {
+    { "gujhshp2lhmnpoo9qde4blg4gq3hgl99", "gujhshp2lhmnpoo9qde4blg4gq3hgl9a", 157, true},
+    { "gujhshp2lhmnpoo9qde4blg4gq3hgl99", "gujhshp2lhmnpoo9qde4blg4gq3hgl9a", 158, false},
+    { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "vujhshp2lhmnpoo9qde4blg4gq3hgl9a", 0, false},
+    { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "7ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, true},
+    { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "7ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 2, false},
+    { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "fujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, false},
+    { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "8ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, false},
+  };
+
+  for (const auto& [owner, next, boundary, result]: table) {
+    AggressiveNSECCache::s_maxNSEC3CommonPrefix = boundary;
+    BOOST_CHECK_EQUAL(AggressiveNSECCache::isSmallCoveringNSEC3(DNSName(owner), fromBase32Hex(next)), result);
+  }
+}
+
 BOOST_AUTO_TEST_CASE(test_aggressive_nsec_nxdomain)
 {
   std::unique_ptr<SyncRes> sr;