Skip to content

Commit

Permalink
rec: Enable the ghost tests again, add a corresponding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Apr 9, 2018
1 parent 3046821 commit 97ab616
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
3 changes: 3 additions & 0 deletions build-scripts/travis.sh
Expand Up @@ -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 .."
Expand Down
40 changes: 40 additions & 0 deletions pdns/recursordist/test-recursorcache_cc.cc
Expand Up @@ -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;

Expand Down
28 changes: 14 additions & 14 deletions regression-tests.recursor/config.sh
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Empty file.
Empty file.

0 comments on commit 97ab616

Please sign in to comment.