]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add/modify test so the timestamps involved pass the 2038 high cliff.
authorOtto <otto.moerbeek@open-xchange.com>
Mon, 25 Jan 2021 10:00:53 +0000 (11:00 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Mon, 25 Jan 2021 10:06:55 +0000 (11:06 +0100)
Recursor cache one is currently failing, a few functions return
int32_t instead of time_t.

pdns/recursordist/test-recursorcache_cc.cc
pdns/test-recpacketcache_cc.cc

index 54fe97a14d6efd3825f562fb6d9d9745e13c54a5..2f25b084509ad92ea9b96d6cbe6322317a7a3ab8 100644 (file)
@@ -19,7 +19,7 @@ BOOST_AUTO_TEST_CASE(test_RecursorCacheSimple)
   std::vector<std::shared_ptr<DNSRecord>> authRecords;
   std::vector<std::shared_ptr<RRSIGRecordContent>> signatures;
   const DNSName authZone(".");
-  time_t now = time(nullptr);
+  time_t now = INT_MAX - 15;
 
   time_t ttd = now + 30;
   DNSName power("powerdns.com.");
index fce6fcc823a91d78e50ed440bf588bfca7deb282..7285ae07e100af8ad3f267fefbd1343ef206528d 100644 (file)
@@ -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<uint8_t> 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