]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add serve-stale test case for GL #3950
authorMatthijs Mekking <matthijs@isc.org>
Mon, 1 May 2023 12:46:29 +0000 (14:46 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Tue, 30 May 2023 13:32:24 +0000 (15:32 +0200)
Add a test case where when priming the cache with a slow authoritative
resolver, the stale-answer-client-timeout option should not return
a delegation to the client (it should wait until an applicable answer
is found, if no entry is found in the cache).

(cherry picked from commit c3d4fd34493501140ba1bd72afba4922ba55530a)

bin/tests/system/serve-stale/ans2/ans.pl
bin/tests/system/serve-stale/ns1/root.db
bin/tests/system/serve-stale/ns3/named2.conf.in
bin/tests/system/serve-stale/tests.sh

index 28c3c9316f4ebdc68f5e750daacacf580113bf73..3fdc1fc9aac56b0431cee2e6ee0f6b2146ce705f 100644 (file)
@@ -49,6 +49,16 @@ my $udpsock = IO::Socket::INET->new(LocalAddr => "$localaddr",
 my $SOA = "example 300 IN SOA . . 0 0 0 0 300";
 my $NS = "example 300 IN NS ns.example";
 my $A = "ns.example 300 IN A $localaddr";
+
+#
+# Slow delegation
+#
+my $slowSOA = "slow 300 IN SOA . . 0 0 0 0 300";
+my $slowNS = "slow 300 IN NS ns.slow";
+my $slowA = "ns.slow 300 IN A $localaddr";
+my $slowTXT = "data.slow 2 IN TXT \"A slow text record with a 2 second ttl\"";
+my $slownegSOA = "slow 2 IN SOA . . 0 0 0 0 300";
+
 #
 # Records to be TTL stretched
 #
@@ -218,6 +228,44 @@ sub reply_handler {
            push @auth, $rr;
        }
        $rcode = "NOERROR";
+    } elsif ($qname eq "ns.slow" ) {
+       if ($qtype eq "A") {
+           my $rr = new Net::DNS::RR($slowA);
+           push @ans, $rr;
+       } else {
+           my $rr = new Net::DNS::RR($slowSOA);
+           push @auth, $rr;
+       }
+       $rcode = "NOERROR";
+    } elsif ($qname eq "slow") {
+       if ($qtype eq "NS") {
+           my $rr = new Net::DNS::RR($slowNS);
+           push @auth, $rr;
+           $rr = new Net::DNS::RR($slowA);
+           push @add, $rr;
+       } elsif ($qtype eq "SOA") {
+           my $rr = new Net::DNS::RR($slowSOA);
+           push @ans, $rr;
+       } else {
+           my $rr = new Net::DNS::RR($slowSOA);
+           push @auth, $rr;
+       }
+       $rcode = "NOERROR";
+    } elsif ($qname eq "data.slow") {
+       if ($slow_response) {
+                print "  Sleeping 3 seconds\n";
+               sleep(3);
+               # only one time
+               $slow_response = 0;
+       }
+       if ($qtype eq "TXT") {
+           my $rr = new Net::DNS::RR($slowTXT);
+           push @ans, $rr;
+       } else {
+           my $rr = new Net::DNS::RR($slownegSOA);
+           push @auth, $rr;
+       }
+       $rcode = "NOERROR";
     } else {
         my $rr = new Net::DNS::RR($SOA);
        push @auth, $rr;
index b6b73675fdfd3af6774ae03a0295f33cf2b18e95..aef8e31c7aa753849a081cf0f9dcd20ee94f434d 100644 (file)
@@ -14,3 +14,5 @@
 ns.nil.                300     A       10.53.0.1
 example.       300     NS      ns.example.
 ns.example.    300     A       10.53.0.2
+slow.          300     NS      ns.slow.
+ns.slow.       300     A       10.53.0.2
index a8d3255edf11aea7aec3a8c9f5c14451372f04fc..a2b1d5ace57a433e354cc21ac0bc5e798f85afb7 100644 (file)
@@ -42,10 +42,10 @@ options {
        recursive-clients 10; # CVE-2022-3924
        max-stale-ttl 3600;
        resolver-query-timeout 10;
+       qname-minimization disabled;
 };
 
 zone "." {
-       type secondary;
-       primaries { 10.53.0.1; };
-       file "root.bk";
+       type hint;
+       file "root.db";
 };
index 3e7ba5f14b695620b1f49623418bc4b79b1a3a49..104ae051adf78e95159e38d1f7661581bfdbec13 100755 (executable)
@@ -1638,6 +1638,24 @@ grep "ANSWER: 0," dig.out.test$n > /dev/null || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
+n=$((n+1))
+echo_i "delay responses from authoritative server ($n)"
+ret=0
+$DIG -p ${PORT} @10.53.0.2 txt slowdown  > dig.out.test$n
+grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
+grep "TXT.\"1\"" dig.out.test$n > /dev/null || ret=1
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=$((status+ret))
+
+n=$((n+1))
+echo_i "prime cache data.slow TXT (stale-answer-client-timeout) ($n)"
+ret=0
+$DIG -p ${PORT} @10.53.0.3 data.slow TXT > dig.out.test$n
+grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=$((status+ret))
+
 n=$((n+1))
 echo_i "disable responses from authoritative server ($n)"
 ret=0
@@ -1652,10 +1670,11 @@ sleep 2
 
 nextpart ns3/named.run > /dev/null
 
-echo_i "sending queries for tests $((n+1))-$((n+2))..."
+echo_i "sending queries for tests $((n+1))-$((n+3))..."
 t1=`$PERL -e 'print time()'`
 $DIG -p ${PORT} +tries=1 +timeout=10  @10.53.0.3 data.example TXT > dig.out.test$((n+1)) &
 $DIG -p ${PORT} +tries=1 +timeout=10  @10.53.0.3 nodata.example TXT > dig.out.test$((n+2))
+$DIG -p ${PORT} +tries=1 +timeout=10  @10.53.0.3 data.slow TXT > dig.out.test$((n+3)) &
 wait
 t2=`$PERL -e 'print time()'`
 
@@ -1684,6 +1703,15 @@ grep "example\..*3.*IN.*SOA" dig.out.test$n > /dev/null || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
+n=$((n+1))
+echo_i "check stale data.slow TXT comes from cache (stale-answer-client-timeout 1.8) ($n)"
+ret=0
+grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+grep "ANSWER: 1," dig.out.test$n > /dev/null || ret=1
+grep "data\.slow\..*3.*IN.*TXT.*A slow text record with a 2 second ttl" dig.out.test$n > /dev/null || ret=1
+if [ $ret != 0 ]; then echo_i "failed"; fi
+status=$((status+ret))
+
 # Now query for RRset not in cache. The first query should time out, but once
 # we enable the authoritative server, the second query should be able to get a
 # response.