From: Remi Gacogne Date: Mon, 9 Apr 2018 12:36:31 +0000 (+0200) Subject: rec: Enable the ghost tests again, add a corresponding unit test X-Git-Tag: dnsdist-1.3.1~163^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=97ab616efd0c8387978360a9eebb3a83f23fffe5;p=thirdparty%2Fpdns.git rec: Enable the ghost tests again, add a corresponding unit test --- diff --git a/build-scripts/travis.sh b/build-scripts/travis.sh index 0ea8fba871..e27b07bc2a 100755 --- a/build-scripts/travis.sh +++ b/build-scripts/travis.sh @@ -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 .." diff --git a/pdns/recursordist/test-recursorcache_cc.cc b/pdns/recursordist/test-recursorcache_cc.cc index d69c07047e..873f068258 100644 --- a/pdns/recursordist/test-recursorcache_cc.cc +++ b/pdns/recursordist/test-recursorcache_cc.cc @@ -340,6 +340,46 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple) { } } +BOOST_AUTO_TEST_CASE(test_RecursorCacheGhost) { + MemRecursorCache MRC; + + std::vector records; + std::vector> authRecords; + std::vector> 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(ns1Content); + ns1.d_ttl = static_cast(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(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 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(ttd)); +} + BOOST_AUTO_TEST_CASE(test_RecursorCache_ExpungingExpiredEntries) { MemRecursorCache MRC; diff --git a/regression-tests.recursor/config.sh b/regression-tests.recursor/config.sh index 16d306d582..6d2dbc05ae 100755 --- a/regression-tests.recursor/config.sh +++ b/regression-tests.recursor/config.sh @@ -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 index e69de29bb2..0000000000 diff --git a/regression-tests.recursor/ghost-2/skip b/regression-tests.recursor/ghost-2/skip deleted file mode 100644 index e69de29bb2..0000000000