]> granicus.if.org Git - pdns/commitdiff
rec: Enable the ghost tests again, add a corresponding unit test
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 Apr 2018 12:36:31 +0000 (14:36 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 9 Apr 2018 12:36:31 +0000 (14:36 +0200)
build-scripts/travis.sh
pdns/recursordist/test-recursorcache_cc.cc
regression-tests.recursor/config.sh
regression-tests.recursor/ghost-1/skip [deleted file]
regression-tests.recursor/ghost-2/skip [deleted file]

index 0ea8fba8710c06b18c704b8f7461f31545f9e233..e27b07bc2a1e24d62080e4c109502f15787ab45c 100755 (executable)
@@ -327,12 +327,15 @@ install_auth() {
 
 install_recursor() {
   # recursor test requirements / setup
+  # lua-posix is required for the ghost tests
+  # (used by the prequery script in the auth)
   run "sudo apt-get -qq --no-install-recommends install \
     authbind \
     daemontools \
     jq \
     libfaketime \
     libsnmp-dev \
+    lua-posix \
     moreutils \
     snmpd"
   run "cd .."
index d69c07047e9941c84b9e03eda10dd92953862197..873f0682583ebe981da5a998247ce156368fa9b3 100644 (file)
@@ -340,6 +340,46 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple) {
   }
 }
 
+BOOST_AUTO_TEST_CASE(test_RecursorCacheGhost) {
+  MemRecursorCache MRC;
+
+  std::vector<DNSRecord> records;
+  std::vector<std::shared_ptr<DNSRecord>> authRecords;
+  std::vector<std::shared_ptr<RRSIGRecordContent>> signatures;
+  time_t now = time(nullptr);
+
+  BOOST_CHECK_EQUAL(MRC.size(), 0);
+
+  /* insert NS coming from a delegation */
+  time_t ttd = now + 30;
+  DNSName ghost("ghost.powerdns.com.");
+  DNSRecord ns1;
+  std::string ns1Content("ns1.ghost.powerdns.com.");
+  ns1.d_name = ghost;
+  ns1.d_type = QType::NS;
+  ns1.d_class = QClass::IN;
+  ns1.d_content = std::make_shared<NSRecordContent>(ns1Content);
+  ns1.d_ttl = static_cast<uint32_t>(ttd);
+  ns1.d_place = DNSResourceRecord::ANSWER;
+  records.push_back(ns1);
+  MRC.replace(now, ns1.d_name, QType(ns1.d_type), records, signatures, authRecords, true, boost::none);
+  BOOST_CHECK_EQUAL(MRC.size(), 1);
+
+  /* try to raise the TTL, simulating the delegated authoritative server
+     raising the TTL so the zone stays alive */
+  records.clear();
+  ns1.d_ttl = static_cast<uint32_t>(ttd + 3600);
+  records.push_back(ns1);
+  MRC.replace(now, ns1.d_name, QType(ns1.d_type), records, signatures, authRecords, true, boost::none);
+  BOOST_CHECK_EQUAL(MRC.size(), 1);
+
+  /* the TTL should not have been raisd */
+  std::vector<DNSRecord> retrieved;
+  BOOST_CHECK_EQUAL(MRC.get(now, ghost, QType(QType::NS), false, &retrieved, ComboAddress("192.0.2.2"), nullptr), (ttd-now));
+  BOOST_REQUIRE_EQUAL(retrieved.size(), 1);
+  BOOST_CHECK_EQUAL(retrieved.at(0).d_ttl, static_cast<uint32_t>(ttd));
+}
+
 BOOST_AUTO_TEST_CASE(test_RecursorCache_ExpungingExpiredEntries) {
   MemRecursorCache MRC;
 
index 16d306d582208c6686afffd8cc3e0b5ba2503bba..6d2dbc05aec9ae2ba9ba85d5d30f578a64243db7 100755 (executable)
@@ -224,12 +224,12 @@ if not newDN then
 end
 function prequery ( dnspacket )
     qname, qtype = dnspacket:getQuestion()
-    if qtype == pdns.A and qname == newDN("www.marvin.example.net.")
+    if qtype == pdns.A and qname == "www.marvin.example.net."
     then
         dnspacket:setRcode(pdns.NXDOMAIN)
         ret = {}
-        ret[1] = {qname=qname, qtype=pdns.CNAME, content="android.marvin.example.net", place=1}
-        ret[2] = {qname=newDN("marvin.example.net"), qtype=pdns.SOA, content="$SOA", place=2}
+        ret[1] = newDR(newDN(qname), "CNAME", 3600, "android.marvin.example.net", 1)
+        ret[2] = newDR(newDN("marvin.example.net"), "SOA", 3600, "$SOA", 2)
         dnspacket:addRecords(ret)
         return true
     end
@@ -254,12 +254,12 @@ if not newDN then
 end
 function prequery ( dnspacket )
     qname, qtype = dnspacket:getQuestion()
-    if qtype == pdns.A and qname == newDN("www.trillian.example.net.")
+    if qtype == pdns.A and qname == "www.trillian.example.net."
     then
         dnspacket:setRcode(pdns.NXDOMAIN)
         ret = {}
-        ret[1] = {qname=qname, qtype=pdns.CNAME, content="www2.arthur.example.net", place=1}
-        ret[2] = {qname=newDN(""), qtype=pdns.SOA, content="$SOA", place=2}
+        ret[1] = newDR(newDN(qname), "CNAME", 3600, "www2.arthur.example.net", 1)
+        ret[2] = newDR(newDN(""), "SOA", 3600, "$SOA", 2)
         dnspacket:addRecords(ret)
         return true
     end
@@ -294,7 +294,7 @@ function prequery ( dnspacket )
     then
         dnspacket:setRcode(pdns.NXDOMAIN)
         ret = {}
-        ret[1] = {qname=newDN("ghost.example.net"), qtype=pdns.SOA, content="$SOA", place=2}
+        ret[1] = newDR(newDN("ghost.example.net"), "SOA", 3600, "$SOA", 2)
         dnspacket:addRecords(ret)
         return true
     end
@@ -327,11 +327,11 @@ function prequery ( dnspacket )
         dnspacket:setRcode(pdns.NOERROR)
         ret = {}
         -- www.1.ghost.example.net. 20  IN  A   192.0.2.7
-        ret[1] = {qname=qname, qtype=pdns.A, content="192.0.2.7", ttl=20, place=1}
+        ret[1] = newDR(newDN(qname), "A", 20, "192.0.2.7", 1)
         -- 1.ghost.example.net. 20  IN  NS  ns.1.ghost.example.net.
-        ret[2] = {qname=newDN("1.ghost.example.net"), qtype=pdns.NS, content="ns"..i..".1.ghost.example.net", ttl=20, place=2}
-        -- ns.1.ghost.example.net.  20  IN  A   10.0.3.18
-        ret[3] = {qname=newDN("ns")..i..".1.ghost.example.net", qtype=pdns.A, content="10.0.3.18", ttl=20, place=3}
+        ret[2] = newDR(newDN("1.ghost.example.net"), "NS", 20, "ns"..i..".1.ghost.example.net", 2)
+        -- ns.1.ghost.example.net.  20  IN  A   $PREFIX.18
+        ret[3] = newDR(newDN("ns"..i..".1.ghost.example.net"), "A", 20, "$PREFIX.18", 3)
         dnspacket:addRecords(ret)
         return true
     end
@@ -359,9 +359,9 @@ function prequery ( dnspacket )
     then
         dnspacket:setRcode(pdns.NOERROR)
         ret = {}
-        ret[1] = {qname=qname, qtype=pdns.A, content="192.0.2.8", ttl=20, place=1}
-        ret[2] = {qname=newDN("2.ghost.example.net"), qtype=pdns.NS, content="ns.2.ghost.example.net", ttl=20, place=2}
-        ret[3] = {qname=newDN("ns.2.ghost.example.net"), qtype=pdns.A, content="10.0.3.19", ttl=20, place=3}
+        ret[1] = newDR(newDN(qname), "A", 20, "192.0.2.8", 1)
+        ret[2] = newDR(newDN("2.ghost.example.net"), "NS", 20, "ns.2.ghost.example.net", 2)
+        ret[3] = newDR(newDN("ns.2.ghost.example.net"), "A", 20, "$PREFIX.19", 3)
         dnspacket:addRecords(ret)
         return true
     end
diff --git a/regression-tests.recursor/ghost-1/skip b/regression-tests.recursor/ghost-1/skip
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/regression-tests.recursor/ghost-2/skip b/regression-tests.recursor/ghost-2/skip
deleted file mode 100644 (file)
index e69de29..0000000