[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
# use .tpkg.var.test for in test variable passing
[ -f .tpkg.var.test ] && source .tpkg.var.test
-# We need kill_pid for the serve-expired-client-timeout test
. ../common.sh
PRE="../.."
fi
}
+# Convenient function to kill current Unbound and bring up one with an alternate configuration.
+bring_up_alternate_configuration () {
+ conf_file=$1
+ kill_pid $UNBOUND_PID # kill current Unbound
+ echo ""
+ cat unbound.log
+ echo ""
+ $PRE/unbound -d -c $conf_file >unbound.log 2>&1 &
+ UNBOUND_PID=$!
+ echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
+ wait_unbound_up unbound.log
+}
+
# Convenient function to exit the test.
end () {
echo "> cat logfiles"
end 1
fi
-echo
-echo "[ Check initial stats based on first query. ]"
+
+teststep "Check initial stats based on first query."
check_stats "\
total.num.queries=1
total.num.cachemiss=1
infra.cache.count=1
num.answer.rcode.NOERROR=1"
-echo
-echo "[ Check stat reset. ]"
+
+teststep "Check stat reset."
check_stats "\
msg.cache.count=1
rrset.cache.count=1
infra.cache.count=1"
-echo
-echo "[ Enable serve-expired and check. ]"
+teststep "Enable serve-expired and check."
set_ub_option serve-expired yes
sleep 2 # make sure the TTL has expired.
echo "> dig 1ttl.example.com."
infra.cache.count=1"
-echo
-echo "[ Enable serve-expired-client-timeout and check. ]"
+teststep "Enable serve-expired-client-timeout and check."
set_ub_option serve-expired-client-timeout 1
echo "> dig servfail.expired."
dig @127.0.0.1 -p $UNBOUND_PORT servfail.expired. | tee outfile
set_ub_option serve-expired no
-echo
-echo "[ Check REFUSED; try without RD flag. ]"
+teststep "Check REFUSED; try without RD flag."
echo "> dig somethingelse.example.com."
dig @127.0.0.1 -p $UNBOUND_PORT +nordflag somethingelse.example.com. | tee outfile
echo "> check answer"
infra.cache.count=2"
-echo
-echo "[ Check the AD flag. ]"
+teststep "Check the AD flag."
echo "> dig www.example.com."
dig @127.0.0.1 -p $UNBOUND_PORT +noadflag www.example.com. | tee outfile
echo "> check answer"
rrset.cache.count=3
infra.cache.count=2"
-echo
-echo "[ Check local zone. ]"
+
+teststep "Check local zone."
echo "> dig www.local.zone."
dig @127.0.0.1 -p $UNBOUND_PORT www.local.zone. | tee outfile
echo "> check answer"
infra.cache.count=2"
-echo
-echo "[ Check NXDOMAIN (with local data). ]"
+teststep "Check NXDOMAIN (with local data)."
echo "> dig mail.local.zone."
dig @127.0.0.1 -p $UNBOUND_PORT mail.local.zone. | tee outfile
echo "> check answer"
infra.cache.count=2"
-echo
-echo "[ Check CHAOS. ]"
+teststep "Check CHAOS."
echo "> dig id.server. ch txt"
dig @127.0.0.1 -p $UNBOUND_PORT id.server. ch txt | tee outfile
echo "> check answer"
infra.cache.count=2"
+###
+#
+# Bring the discard-timeout, wait-limit configured Unbound up
+#
+bring_up_alternate_configuration ub_discard_wait_limit.conf
+#
+###
+
+
+teststep "Check discard-timeout and wait-limit"
+echo "> dig www.slow"
+dig @127.0.0.1 -p $UNBOUND_PORT +retry=2 +timeout=1 www.slow. | tee outfile
+echo "> check answer"
+if grep "no servers could be reached" outfile; then
+ echo "OK"
+else
+ end 1
+fi
+check_stats "\
+infra.cache.count=1
+msg.cache.count=1
+num.query.class.IN=3
+num.query.edns.present=3
+num.query.flags.AD=3
+num.query.flags.RD=3
+num.query.opcode.QUERY=3
+num.query.type.A=3
+num.query.udpout=1
+total.num.cachemiss=3
+total.num.queries=3
+total.num.queries_discard_timeout=2
+total.num.queries_wait_limit=1"
+
+
+###
+#
# Bring the downstream DNS Cookies configured Unbound up
-kill_pid $UNBOUND_PID # kill current Unbound
-echo ""
-cat unbound.log
-echo ""
-$PRE/unbound -d -c ub_downstream_cookies.conf >unbound.log 2>&1 &
-UNBOUND_PID=$!
-echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
-wait_unbound_up unbound.log
-
-echo
-echo "[ Get a DNS Cookie. ]"
+#
+bring_up_alternate_configuration ub_downstream_cookies.conf
+#
+###
+
+
+teststep "Get a DNS Cookie."
echo "> dig www.local.zone +tcp $nocookie +ednsopt=10:0102030405060708"
dig @127.0.0.1 -p $UNBOUND_PORT +tcp $nocookie +ednsopt=10:0102030405060708 +retry=0 +time=1 www.local.zone. | tee outfile
echo "> check answer"
num.query.tcp=1
num.answer.rcode.NOERROR=1"
-echo
-echo "[ Present the valid DNS Cookie. ]"
+
+teststep "Present the valid DNS Cookie."
echo "> dig www.local.zone $nocookie +ednsopt=10:valid_cookie"
dig @127.0.0.1 -p $UNBOUND_PORT $nocookie +ednsopt=10:$valid_cookie +retry=0 +time=1 www.local.zone. | tee outfile
echo "> check answer"
num.query.edns.present=1
num.answer.rcode.NOERROR=1"
-echo
-echo "[ Present an invalid DNS Cookie. ]"
+
+teststep "Present an invalid DNS Cookie."
echo "> dig www.local.zone $nocookie +ednsopt=10:invalid_cookie"
dig @127.0.0.1 -p $UNBOUND_PORT $nocookie +ednsopt=10:$invalid_cookie +retry=0 +time=1 www.local.zone. | tee outfile
echo "> check answer"
total.num.cachehits=1
num.answer.rcode.YXRRSET=1"
-echo
-echo "[ Present no DNS Cookie. ]"
+
+teststep "Present no DNS Cookie."
echo "> dig www.local.zone +ignore"
dig @127.0.0.1 -p $UNBOUND_PORT +ignore $nocookie +retry=0 +time=1 www.local.zone. | tee outfile
echo "> check answer"
if test x$USE_CACHEDB = "x1"; then
+
+###
+#
# Bring the cachedb configured Unbound up
-kill_pid $UNBOUND_PID # kill current Unbound
-echo ""
-cat unbound.log
-echo ""
-$PRE/unbound -d -c ub_cachedb.conf >unbound.log 2>&1 &
-UNBOUND_PID=$!
-echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
-wait_unbound_up unbound.log
-
-echo
-echo "[ Check cachedb cache miss. ]"
+#
+bring_up_alternate_configuration ub_cachedb.conf
+#
+###
+
+
+teststep "Check cachedb cache miss."
echo "> dig www.example.com."
dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile
echo "> check answer"
infra.cache.count=1
num.answer.rcode.NOERROR=1"
-echo
-echo "[ Check cachedb cache hit. ]"
+
+teststep "Check cachedb cache hit."
echo "> dig www.example.com."
dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile
echo "> check answer"
infra.cache.count=1
num.answer.rcode.NOERROR=1"
-echo
-echo "[ Check cachedb cache hit with stat reset ]"
+
+teststep "Check cachedb cache hit with stat reset."
echo "> dig www.example.com."
dig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile
echo "> check answer"