]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Convert generic format while parsing zone files for ZoneToCache.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 27 Jun 2022 09:07:45 +0000 (11:07 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 27 Jun 2022 09:07:45 +0000 (11:07 +0200)
Fixes #11724

pdns/recursordist/rec-zonetocache.cc
pdns/recursordist/test-rec-zonetocache.cc

index ace86864642b12940a7216a806385c6b9ad36ebd..8f6e924e37e26ccf14ccce66ff3f76cecd66f146 100644 (file)
@@ -215,7 +215,7 @@ static std::vector<std::string> getURL(const RecZoneToCache::Config& config)
 pdns::ZoneMD::Result ZoneData::processLines(const vector<string>& lines, const RecZoneToCache::Config& config, pdns::ZoneMD& zonemd)
 {
   DNSResourceRecord drr;
-  ZoneParserTNG zpt(lines, d_zone);
+  ZoneParserTNG zpt(lines, d_zone, true);
   zpt.setMaxGenerateSteps(1);
   zpt.setMaxIncludes(0);
 
index ffec8883bbdd8505ed778930d3d152bb1835e960..48e3bf43cef66a544f248827ab4cd8b57736d0b4 100644 (file)
@@ -57,6 +57,7 @@ const std::string badZONEMD = ".      86400   IN      ZONEMD  2021080900 1 1 0ad404980c735405
 const std::string zoneWithBadZONEMD = zone + badZONEMD;
 const std::string zoneWithGoodZONEMD = zone + goodZONEMD;
 
+
 static void zonemdTest(const std::string& lines, pdns::ZoneMD::Config mode, pdns::ZoneMD::Config dnssec, size_t expectedCacheSize)
 {
   char temp[] = "/tmp/ztcXXXXXXXXXX";
@@ -81,6 +82,7 @@ static void zonemdTest(const std::string& lines, pdns::ZoneMD::Config mode, pdns
   RecZoneToCache::ZoneToCache(config, state);
   unlink(temp);
 
+  g_recCache->doDump(2);
   BOOST_CHECK_EQUAL(g_recCache->size(), expectedCacheSize);
 
   if (expectedCacheSize > 0) {
@@ -116,4 +118,62 @@ BOOST_AUTO_TEST_CASE(test_zonetocache)
   zonemdTest(zoneWithBadZONEMD, pdns::ZoneMD::Config::Require, pdns::ZoneMD::Config::Ignore, 0U);
   zonemdTest(zoneWithBadZONEMD, pdns::ZoneMD::Config::Ignore, pdns::ZoneMD::Config::Require, 0U);
 }
+
+// Example from https://github.com/verisign/zonemd-test-cases/blob/master/zones/20-generic-zonemd/example.zone
+const std::string genericTest =
+"example.      86400   IN      NS      ns.example.\n"
+"example.      86400   IN      SOA     ns.example. admin.example. 2018031900 1800 900 604800 86400\n"
+  "example.    86400   IN      TYPE63  \\# 54 7848b91c01018ee54f64ce0d57fd70e1a4811a9ca9e849e2e50cb598edf3ba9c2a58625335c1f966835f0d4338d9f78f557227d63bf6\n"
+  "ns.example. 3600    IN      A       127.0.0.1\n";
+
+const std::string genericBadTest =
+"example.      86400   IN      NS      ns.example.\n"
+"example.      86400   IN      SOA     ns.example. admin.example. 2018031900 1800 900 604800 86400\n"
+  "example.    86400   IN      TYPE63  \\# 54 8848b91c01018ee54f64ce0d57fd70e1a4811a9ca9e849e2e50cb598edf3ba9c2a58625335c1f966835f0d4338d9f78f557227d63bf6\n"
+  "ns.example. 3600    IN      A       127.0.0.1\n";
+
+static void zonemdGenericTest(const std::string& lines, pdns::ZoneMD::Config mode, pdns::ZoneMD::Config dnssec, size_t expectedCacheSize)
+{
+  char temp[] = "/tmp/ztcXXXXXXXXXX";
+  int fd = mkstemp(temp);
+  BOOST_REQUIRE(fd > 0);
+  FILE* fp = fdopen(fd, "w");
+  BOOST_REQUIRE(fp != nullptr);
+  size_t written = fwrite(lines.data(), 1, lines.length(), fp);
+  BOOST_REQUIRE(written == lines.length());
+  BOOST_REQUIRE(fclose(fp) == 0);
+
+  RecZoneToCache::Config config{"example.", "file", {temp}, ComboAddress(), TSIGTriplet()};
+  config.d_refreshPeriod = 0;
+  config.d_retryOnError = 0;
+  config.d_zonemd = mode;
+  config.d_dnssec = dnssec;
+
+  // Start with a new, empty cache
+  g_recCache = std::make_unique<MemRecursorCache>();
+  BOOST_CHECK_EQUAL(g_recCache->size(), 0U);
+  RecZoneToCache::State state;
+  RecZoneToCache::ZoneToCache(config, state);
+  unlink(temp);
+
+  BOOST_CHECK_EQUAL(g_recCache->size(), expectedCacheSize);
+
+  if (expectedCacheSize > 0) {
+    std::vector<DNSRecord> retrieved;
+    time_t now = time(nullptr);
+    ComboAddress who;
+    BOOST_CHECK_GT(g_recCache->get(now, DNSName("example."), QType::SOA, true, &retrieved, who), 0);
+    BOOST_CHECK_GT(g_recCache->get(now, DNSName("example."), QType::NS, true, &retrieved, who), 0);
+    BOOST_CHECK_GT(g_recCache->get(now, DNSName("example."), QType::ZONEMD, true, &retrieved, who), 0);
+    BOOST_CHECK_GT(g_recCache->get(now, DNSName("ns.example."), QType::A, true, &retrieved, who), 0);
+  }
+}
+
+
+BOOST_AUTO_TEST_CASE(test_zonetocachegeneric)
+{
+  zonemdGenericTest(genericTest, pdns::ZoneMD::Config::Require, pdns::ZoneMD::Config::Ignore, 4U);
+  zonemdGenericTest(genericBadTest, pdns::ZoneMD::Config::Require, pdns::ZoneMD::Config::Ignore, 0U);
+}
+
 BOOST_AUTO_TEST_SUITE_END()