}
}
+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;
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
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
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
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
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