From: Otto Date: Mon, 25 Jan 2021 10:00:53 +0000 (+0100) Subject: Add/modify test so the timestamps involved pass the 2038 high cliff. X-Git-Tag: dnsdist-1.6.0-alpha1~9^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df8cdcb32c54fa5ae90fe280891a03ea422cfe8a;p=thirdparty%2Fpdns.git Add/modify test so the timestamps involved pass the 2038 high cliff. Recursor cache one is currently failing, a few functions return int32_t instead of time_t. --- diff --git a/pdns/recursordist/test-recursorcache_cc.cc b/pdns/recursordist/test-recursorcache_cc.cc index 54fe97a14d..2f25b08450 100644 --- a/pdns/recursordist/test-recursorcache_cc.cc +++ b/pdns/recursordist/test-recursorcache_cc.cc @@ -19,7 +19,7 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple) std::vector> authRecords; std::vector> signatures; const DNSName authZone("."); - time_t now = time(nullptr); + time_t now = INT_MAX - 15; time_t ttd = now + 30; DNSName power("powerdns.com."); diff --git a/pdns/test-recpacketcache_cc.cc b/pdns/test-recpacketcache_cc.cc index fce6fcc823..7285ae07e1 100644 --- a/pdns/test-recpacketcache_cc.cc +++ b/pdns/test-recpacketcache_cc.cc @@ -84,6 +84,83 @@ BOOST_AUTO_TEST_CASE(test_recPacketCacheSimple) { BOOST_CHECK_EQUAL(rpc.size(), 0U); } +BOOST_AUTO_TEST_CASE(test_recPacketCacheSimplePost2038) { + RecursorPacketCache rpc; + string fpacket; + unsigned int tag=0; + uint32_t age=0; + uint32_t qhash=0; + uint32_t ttd=3600; + BOOST_CHECK_EQUAL(rpc.size(), 0U); + + ::arg().set("rng")="auto"; + ::arg().set("entropy-source")="/dev/urandom"; + + DNSName qname("www.powerdns.com"); + vector packet; + DNSPacketWriter pw(packet, qname, QType::A); + pw.getHeader()->rd=true; + pw.getHeader()->qr=false; + pw.getHeader()->id=dns_random_uint16(); + string qpacket((const char*)&packet[0], packet.size()); + pw.startRecord(qname, QType::A, ttd); + + time_t future = INT_MAX - 1800; // with ttd of 3600, we pass the cliff + + BOOST_CHECK_EQUAL(rpc.getResponsePacket(tag, qpacket, future, &fpacket, &age, &qhash), false); + BOOST_CHECK_EQUAL(rpc.getResponsePacket(tag, qpacket, qname, QType::A, QClass::IN, future, &fpacket, &age, &qhash), false); + + ARecordContent ar("127.0.0.1"); + ar.toPacket(pw); + pw.commit(); + string rpacket((const char*)&packet[0], packet.size()); + + rpc.insertResponsePacket(tag, qhash, string(qpacket), qname, QType::A, QClass::IN, string(rpacket), future, ttd, vState::Indeterminate, boost::none); + BOOST_CHECK_EQUAL(rpc.size(), 1U); + rpc.doPruneTo(0); + BOOST_CHECK_EQUAL(rpc.size(), 0U); + rpc.insertResponsePacket(tag, qhash, string(qpacket), qname, QType::A, QClass::IN, string(rpacket), future, ttd, vState::Indeterminate, boost::none); + BOOST_CHECK_EQUAL(rpc.size(), 1U); + + rpc.doWipePacketCache(qname); + BOOST_CHECK_EQUAL(rpc.size(), 0U); + + rpc.insertResponsePacket(tag, qhash, string(qpacket), qname, QType::A, QClass::IN, string(rpacket), future, ttd, vState::Indeterminate, boost::none); + BOOST_CHECK_EQUAL(rpc.size(), 1U); + uint32_t qhash2 = 0; + bool found = rpc.getResponsePacket(tag, qpacket, future, &fpacket, &age, &qhash2); + BOOST_CHECK_EQUAL(found, true); + BOOST_CHECK_EQUAL(qhash, qhash2); + BOOST_CHECK_EQUAL(fpacket, rpacket); + found = rpc.getResponsePacket(tag, qpacket, qname, QType::A, QClass::IN, future, &fpacket, &age, &qhash2); + BOOST_CHECK_EQUAL(found, true); + BOOST_CHECK_EQUAL(qhash, qhash2); + BOOST_CHECK_EQUAL(fpacket, rpacket); + + found = rpc.getResponsePacket(tag, qpacket, future + 3601, &fpacket, &age, &qhash2); + BOOST_CHECK_EQUAL(found, false); + found = rpc.getResponsePacket(tag, qpacket, qname, QType::A, QClass::IN, future + 3601, &fpacket, &age, &qhash2); + BOOST_CHECK_EQUAL(found, false); + + + packet.clear(); + qname+=DNSName("co.uk"); + DNSPacketWriter pw2(packet, qname, QType::A); + + pw2.getHeader()->rd=true; + pw2.getHeader()->qr=false; + pw2.getHeader()->id=dns_random_uint16(); + qpacket.assign((const char*)&packet[0], packet.size()); + + found = rpc.getResponsePacket(tag, qpacket, future, &fpacket, &age, &qhash); + BOOST_CHECK_EQUAL(found, false); + found = rpc.getResponsePacket(tag, qpacket, qname, QType::A, QClass::IN, future, &fpacket, &age, &qhash); + BOOST_CHECK_EQUAL(found, false); + + rpc.doWipePacketCache(DNSName("com"), 0xffff, true); + BOOST_CHECK_EQUAL(rpc.size(), 0U); +} + BOOST_AUTO_TEST_CASE(test_recPacketCache_Tags) { /* Insert a response with tag1, the exact same query with a different tag should lead to a miss. Inserting a different response with the second tag