4ba560
From 54e281c11ee13eabc3c51d6391a58fc90836000c Mon Sep 17 00:00:00 2001
4ba560
From: Evan Hunt <each@isc.org>
4ba560
Date: Wed, 9 Nov 2022 21:56:16 -0800
4ba560
Subject: [PATCH] test failure conditions
4ba560
4ba560
verify that updates are refused when the client is disallowed by
4ba560
allow-query, and update forwarding is refused when the client is
4ba560
is disallowed by update-forwarding.
4ba560
4ba560
verify that "too many DNS UPDATEs" appears in the log file when too
4ba560
many simultaneous updates are processing.
4ba560
4ba560
(cherry picked from commit b91339b80e5b82a56622c93cc1e3cca2d0c11bc0)
4ba560
---
4ba560
 bin/tests/system/nsupdate/ns1/named.conf.in   |  2 +
4ba560
 bin/tests/system/nsupdate/tests.sh            | 28 +++++++++++++
4ba560
 bin/tests/system/upforwd/clean.sh             |  2 +
4ba560
 .../ns3/{named.conf.in => named1.conf.in}     | 13 ++++--
4ba560
 bin/tests/system/upforwd/ns3/named2.conf.in   | 41 +++++++++++++++++++
4ba560
 bin/tests/system/upforwd/setup.sh             |  2 +-
4ba560
 bin/tests/system/upforwd/tests.sh             | 39 ++++++++++++++++++
4ba560
 7 files changed, 123 insertions(+), 4 deletions(-)
4ba560
 rename bin/tests/system/upforwd/ns3/{named.conf.in => named1.conf.in} (78%)
4ba560
 create mode 100644 bin/tests/system/upforwd/ns3/named2.conf.in
4ba560
4ba560
diff --git a/bin/tests/system/nsupdate/ns1/named.conf.in b/bin/tests/system/nsupdate/ns1/named.conf.in
4ba560
index 436c97d..83fe884 100644
4ba560
--- a/bin/tests/system/nsupdate/ns1/named.conf.in
4ba560
+++ b/bin/tests/system/nsupdate/ns1/named.conf.in
4ba560
@@ -21,6 +21,7 @@ options {
4ba560
 	recursion no;
4ba560
 	notify yes;
4ba560
 	minimal-responses no;
4ba560
+	update-quota 1;
4ba560
 };
4ba560
 
4ba560
 acl named-acl {
4ba560
@@ -81,6 +82,7 @@ zone "other.nil" {
4ba560
 	check-integrity no;
4ba560
 	check-mx warn;
4ba560
 	update-policy local;
4ba560
+	allow-query { !10.53.0.2; any; };
4ba560
 	allow-query-on { 10.53.0.1; 127.0.0.1; };
4ba560
 	allow-transfer { any; };
4ba560
 };
4ba560
diff --git a/bin/tests/system/nsupdate/tests.sh b/bin/tests/system/nsupdate/tests.sh
4ba560
index b5f562f..13ba577 100755
4ba560
--- a/bin/tests/system/nsupdate/tests.sh
4ba560
+++ b/bin/tests/system/nsupdate/tests.sh
4ba560
@@ -1268,6 +1268,34 @@ END
4ba560
 grep "NSEC3PARAM has excessive iterations (> 150)" nsupdate.out-$n >/dev/null || ret=1
4ba560
 [ $ret = 0 ] || { echo_i "failed"; status=1; }
4ba560
 
4ba560
+n=$((n + 1))
4ba560
+ret=0
4ba560
+echo_i "check that update is rejected if query is not allowed ($n)"
4ba560
+{
4ba560
+  $NSUPDATE -d <
4ba560
+  local 10.53.0.2
4ba560
+  server 10.53.0.1 ${PORT}
4ba560
+  update add reject.other.nil 3600 IN TXT Whatever
4ba560
+  send
4ba560
+END
4ba560
+} > nsupdate.out.test$n 2>&1
4ba560
+grep 'failed: REFUSED' nsupdate.out.test$n > /dev/null || ret=1
4ba560
+[ $ret = 0 ] || { echo_i "failed"; status=1; }
4ba560
+
4ba560
+n=$((n + 1))
4ba560
+ret=0
4ba560
+echo_i "check that update is rejected if quota is exceeded ($n)"
4ba560
+for loop in 1 2 3 4 5 6 7 8 9 10; do
4ba560
+{
4ba560
+  $NSUPDATE -4 -l -p ${PORT} -k ns1/session.key > /dev/null 2>&1 <
4ba560
+  update add txt-$loop.other.nil 3600 IN TXT Whatever
4ba560
+  send
4ba560
+END
4ba560
+} &
4ba560
+done
4ba560
+wait_for_log 10 "too many DNS UPDATEs queued" ns1/named.run || ret=1
4ba560
+[ $ret = 0 ] || { echo_i "failed"; status=1; }
4ba560
+
4ba560
 if ! $FEATURETEST --gssapi ; then
4ba560
   echo_i "SKIPPED: GSSAPI tests"
4ba560
 else
4ba560
diff --git a/bin/tests/system/upforwd/clean.sh b/bin/tests/system/upforwd/clean.sh
4ba560
index 2025252..12311df 100644
4ba560
--- a/bin/tests/system/upforwd/clean.sh
4ba560
+++ b/bin/tests/system/upforwd/clean.sh
4ba560
@@ -29,3 +29,5 @@ rm -f keyname keyname.err
4ba560
 rm -f ns*/named.lock
4ba560
 rm -f ns1/example2.db
4ba560
 rm -f ns*/managed-keys.bind*
4ba560
+rm -f nsupdate.out.*
4ba560
+rm -f ns*/named.run.prev
4ba560
diff --git a/bin/tests/system/upforwd/ns3/named.conf.in b/bin/tests/system/upforwd/ns3/named1.conf.in
4ba560
similarity index 78%
4ba560
rename from bin/tests/system/upforwd/ns3/named.conf.in
4ba560
rename to bin/tests/system/upforwd/ns3/named1.conf.in
4ba560
index 7bd13d3..2f690ff 100644
4ba560
--- a/bin/tests/system/upforwd/ns3/named.conf.in
4ba560
+++ b/bin/tests/system/upforwd/ns3/named1.conf.in
4ba560
@@ -28,20 +28,27 @@ key rndc_key {
4ba560
 };
4ba560
 
4ba560
 controls {
4ba560
-        inet 10.53.0.3 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
4ba560
+	inet 10.53.0.3 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
4ba560
 };
4ba560
 
4ba560
 zone "example" {
4ba560
 	type secondary;
4ba560
 	file "example.bk";
4ba560
-	allow-update-forwarding { any; };
4ba560
+	allow-update-forwarding { 10.53.0.1; };
4ba560
 	primaries { 10.53.0.1; };
4ba560
 };
4ba560
 
4ba560
 zone "example2" {
4ba560
 	type secondary;
4ba560
 	file "example2.bk";
4ba560
-	allow-update-forwarding { any; };
4ba560
+	allow-update-forwarding { 10.53.0.1; };
4ba560
+	primaries { 10.53.0.1; };
4ba560
+};
4ba560
+
4ba560
+zone "example3" {
4ba560
+	type secondary;
4ba560
+	file "example3.bk";
4ba560
+	allow-update-forwarding { 10.53.0.1; };
4ba560
 	primaries { 10.53.0.1; };
4ba560
 };
4ba560
 
4ba560
diff --git a/bin/tests/system/upforwd/ns3/named2.conf.in b/bin/tests/system/upforwd/ns3/named2.conf.in
4ba560
new file mode 100644
4ba560
index 0000000..e15459a
4ba560
--- /dev/null
4ba560
+++ b/bin/tests/system/upforwd/ns3/named2.conf.in
4ba560
@@ -0,0 +1,41 @@
4ba560
+/*
4ba560
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4ba560
+ *
4ba560
+ * SPDX-License-Identifier: MPL-2.0
4ba560
+ *
4ba560
+ * This Source Code Form is subject to the terms of the Mozilla Public
4ba560
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
4ba560
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
4ba560
+ *
4ba560
+ * See the COPYRIGHT file distributed with this work for additional
4ba560
+ * information regarding copyright ownership.
4ba560
+ */
4ba560
+
4ba560
+options {
4ba560
+	query-source address 10.53.0.3;
4ba560
+	notify-source 10.53.0.3;
4ba560
+	transfer-source 10.53.0.3;
4ba560
+	port @PORT@;
4ba560
+	pid-file "named.pid";
4ba560
+	listen-on { 10.53.0.3; };
4ba560
+	listen-on-v6 { none; };
4ba560
+	recursion no;
4ba560
+	notify yes;
4ba560
+	update-quota 1;
4ba560
+};
4ba560
+
4ba560
+key rndc_key {
4ba560
+	secret "1234abcd8765";
4ba560
+        algorithm hmac-sha256;
4ba560
+};
4ba560
+
4ba560
+controls {
4ba560
+	inet 10.53.0.3 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
4ba560
+};
4ba560
+
4ba560
+zone "example" {
4ba560
+	type secondary;
4ba560
+	file "example.bk";
4ba560
+	allow-update-forwarding { any; };
4ba560
+	primaries { 10.53.0.1; };
4ba560
+};
4ba560
diff --git a/bin/tests/system/upforwd/setup.sh b/bin/tests/system/upforwd/setup.sh
4ba560
index e748078..88ab28d 100644
4ba560
--- a/bin/tests/system/upforwd/setup.sh
4ba560
+++ b/bin/tests/system/upforwd/setup.sh
4ba560
@@ -17,7 +17,7 @@ cp -f ns3/nomaster.db ns3/nomaster1.db
4ba560
 
4ba560
 copy_setports ns1/named.conf.in ns1/named.conf
4ba560
 copy_setports ns2/named.conf.in ns2/named.conf
4ba560
-copy_setports ns3/named.conf.in ns3/named.conf
4ba560
+copy_setports ns3/named1.conf.in ns3/named.conf
4ba560
 
4ba560
 if $FEATURETEST --enable-dnstap
4ba560
 then
4ba560
diff --git a/bin/tests/system/upforwd/tests.sh b/bin/tests/system/upforwd/tests.sh
4ba560
index 8062d68..20fc46f 100644
4ba560
--- a/bin/tests/system/upforwd/tests.sh
4ba560
+++ b/bin/tests/system/upforwd/tests.sh
4ba560
@@ -80,6 +80,7 @@ if [ $ret != 0 ] ; then echo_i "failed"; status=`expr $status + $ret`; fi
4ba560
 echo_i "updating zone (signed) ($n)"
4ba560
 ret=0
4ba560
 $NSUPDATE -y hmac-sha256:update.example:c3Ryb25nIGVub3VnaCBmb3IgYSBtYW4gYnV0IG1hZGUgZm9yIGEgd29tYW4K -- - <
4ba560
+local 10.53.0.1
4ba560
 server 10.53.0.3 ${PORT}
4ba560
 update add updated.example. 600 A 10.10.10.1
4ba560
 update add updated.example. 600 TXT Foo
4ba560
@@ -138,6 +139,7 @@ fi
4ba560
 echo_i "updating zone (unsigned) ($n)"
4ba560
 ret=0
4ba560
 $NSUPDATE -- - <
4ba560
+local 10.53.0.1
4ba560
 server 10.53.0.3 ${PORT}
4ba560
 update add unsigned.example. 600 A 10.10.10.1
4ba560
 update add unsigned.example. 600 TXT Foo
4ba560
@@ -194,6 +196,7 @@ while [ $count -lt 5 -a $ret -eq 0 ]
4ba560
 do
4ba560
 (
4ba560
 $NSUPDATE -- - <
4ba560
+local 10.53.0.1
4ba560
 server 10.53.0.3 ${PORT}
4ba560
 zone nomaster
4ba560
 update add unsigned.nomaster. 600 A 10.10.10.1
4ba560
@@ -225,6 +228,7 @@ then
4ba560
 	ret=0
4ba560
 	keyname=`cat keyname`
4ba560
 	$NSUPDATE -k $keyname.private -- - <
4ba560
+	local 10.53.0.1
4ba560
 	server 10.53.0.3 ${PORT}
4ba560
 	zone example2
4ba560
 	update add unsigned.example2. 600 A 10.10.10.1
4ba560
@@ -249,5 +253,40 @@ EOF
4ba560
 	fi
4ba560
 fi
4ba560
 
4ba560
+echo_i "attempting an update that should be rejected by ACL ($n)"
4ba560
+ret=0
4ba560
+{
4ba560
+        $NSUPDATE -- - << EOF
4ba560
+        local 10.53.0.2
4ba560
+        server 10.53.0.3 ${PORT}
4ba560
+        update add another.unsigned.example. 600 A 10.10.10.2
4ba560
+        update add another.unsigned.example. 600 TXT Bar
4ba560
+        send
4ba560
+EOF
4ba560
+} > nsupdate.out.$n 2>&1
4ba560
+grep REFUSED nsupdate.out.$n > /dev/null || ret=1
4ba560
+if [ $ret != 0 ] ; then echo_i "failed"; status=`expr $status + $ret`; fi
4ba560
+n=`expr $n + 1`
4ba560
+
4ba560
+n=$((n + 1))
4ba560
+ret=0
4ba560
+echo_i "attempting updates that should exceed quota ($n)"
4ba560
+# lower the update quota to 1.
4ba560
+copy_setports ns3/named2.conf.in ns3/named.conf
4ba560
+rndc_reconfig ns3 10.53.0.3
4ba560
+nextpart ns3/named.run > /dev/null
4ba560
+for loop in 1 2 3 4 5 6 7 8 9 10; do
4ba560
+{
4ba560
+  $NSUPDATE -- - > /dev/null 2>&1 <
4ba560
+  local 10.53.0.1
4ba560
+  server 10.53.0.3 ${PORT}
4ba560
+  update add txt-$loop.unsigned.example 300 IN TXT Whatever
4ba560
+  send
4ba560
+END
4ba560
+} &
4ba560
+done
4ba560
+wait_for_log 10 "too many DNS UPDATEs queued" ns3/named.run || ret=1
4ba560
+[ $ret = 0 ] || { echo_i "failed"; status=1; }
4ba560
+
4ba560
 echo_i "exit status: $status"
4ba560
 [ $status -eq 0 ] || exit 1
4ba560
-- 
4ba560
2.39.2
4ba560