From 0b6ee6b953b2292b3a87912046dafbc75d25a63a Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Fri, 10 Nov 2023 11:14:58 +0000 Subject: [PATCH] Add a check for the 'first refresh' data in the stats channel Currently we test the incoming zone transfers data in the statistics channel by retransfering the zones in slow mode and capturing the XML and JSON outputs in the meantime to check their validity. Add a new transfer to the test, and check that the XML and JSON files correctly indicate that we have 3 retransfers and 1 new (first time) transfer. --- .../system/statschannel/ns1/example-new.db | 49 +++++++++++++++++++ .../system/statschannel/ns1/named.conf.in | 6 +++ .../system/statschannel/ns3/named.conf.in | 1 + bin/tests/system/statschannel/tests.sh | 20 +++++++- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 bin/tests/system/statschannel/ns1/example-new.db diff --git a/bin/tests/system/statschannel/ns1/example-new.db b/bin/tests/system/statschannel/ns1/example-new.db new file mode 100644 index 0000000000..e258bd5fdb --- /dev/null +++ b/bin/tests/system/statschannel/ns1/example-new.db @@ -0,0 +1,49 @@ +; Copyright (C) Internet Systems Consortium, Inc. ("ISC") +; +; SPDX-License-Identifier: MPL-2.0 +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, you can obtain one at https://mozilla.org/MPL/2.0/. +; +; See the COPYRIGHT file distributed with this work for additional +; information regarding copyright ownership. + +$ORIGIN . +$TTL 300 ; 5 minutes +example-new IN SOA mname1. . ( + 1 ; serial + 20 ; refresh (20 seconds) + 20 ; retry (20 seconds) + 1814400 ; expire (3 weeks) + 3600 ; minimum (1 hour) + ) +example-new. NS ns2.example-new. +ns2.example-new. A 10.53.0.2 + +$ORIGIN example-new. +a A 10.0.0.1 + MX 10 mail.example-new. +short TXT "short text" +long TXT ( + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + "longlonglonglonglonglonglonglonglonglong" + ) + +mail A 10.0.0.2 diff --git a/bin/tests/system/statschannel/ns1/named.conf.in b/bin/tests/system/statschannel/ns1/named.conf.in index 5bdfdf0cb6..b70c871da4 100644 --- a/bin/tests/system/statschannel/ns1/named.conf.in +++ b/bin/tests/system/statschannel/ns1/named.conf.in @@ -67,3 +67,9 @@ zone "example-tls" { file "example-tls.db"; allow-transfer { any; }; }; + +zone "example-new" { + type primary; + file "example-new.db"; + allow-transfer { any; }; +}; diff --git a/bin/tests/system/statschannel/ns3/named.conf.in b/bin/tests/system/statschannel/ns3/named.conf.in index 4fa2adeb40..901dc84764 100644 --- a/bin/tests/system/statschannel/ns3/named.conf.in +++ b/bin/tests/system/statschannel/ns3/named.conf.in @@ -28,6 +28,7 @@ options { notify no; minimal-responses no; version none; // make statistics independent of the version number + allow-new-zones yes; }; statistics-channels { inet 10.53.0.3 port @EXTRAPORT1@ allow { localhost; }; }; diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh index c871120e36..f8ba35cf36 100644 --- a/bin/tests/system/statschannel/tests.sh +++ b/bin/tests/system/statschannel/tests.sh @@ -689,7 +689,7 @@ if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) n=$((n + 1)) -echo_i "Retransfering 'example' from ns1 to ns3 in slow mode ($n)" +echo_i "Transfering zones from ns1 to ns3 in slow mode ($n)" ret=0 i=0 # Restart ns1 with '-T transferslowly' to see the xfrins information in ns3's statschannel while it's ongoing @@ -700,6 +700,7 @@ nextpart ns3/named.run >/dev/null $RNDCCMD 10.53.0.3 retransfer example | sed "s/^/ns3 /" | cat_i $RNDCCMD 10.53.0.3 retransfer example-tcp | sed "s/^/ns3 /" | cat_i $RNDCCMD 10.53.0.3 retransfer example-tls | sed "s/^/ns3 /" | cat_i +$RNDCCMD 10.53.0.3 addzone 'example-new { type secondary; primaries { 10.53.0.1; }; file "example-new.db"; };' 2>&1 | sed "s/^/ns3 /" | cat_i wait_for_log_fast 200 "zone example/IN: Transfer started" ns3/named.run || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) @@ -708,11 +709,26 @@ n=$((n + 1)) _wait_for_transfers() { getxfrins xml x$n || return 1 getxfrins json j$n || return 1 + # XML is encoded in one line, use awk to separate each transfer with a newline + + # We expect 4 transfers count=$(awk '{ gsub("(Zone Transfer Request|First Data|Receiving AXFR Data)') - if [ $count != 3 ]; then return 1; fi + if [ $count != 4 ]; then return 1; fi count=$(grep -c -E '"state":"(Zone Transfer Request|First Data|Receiving AXFR Data)"' xfrins.json.j$n) + if [ $count != 4 ]; then return 1; fi + + # We expect 3 of 4 to be retransfers + count=$(awk '{ gsub("No') if [ $count != 3 ]; then return 1; fi + count=$(grep -c -F '"firstrefresh":"No"' xfrins.json.j$n) + if [ $count != 3 ]; then return 1; fi + + # We expect 1 of 4 to be a new transfer + count=$(awk '{ gsub("Yes') + if [ $count != 1 ]; then return 1; fi + count=$(grep -c -F '"firstrefresh":"Yes"' xfrins.json.j$n) + if [ $count != 1 ]; then return 1; fi } # We have now less than one second to catch the zone transfers in progress