From 33887dd94172486a5c0ba3b25a5f2cbf51a2310a Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Sun, 21 Jul 2019 00:05:42 -0400 Subject: [PATCH] add digdelv +yaml system tests --- bin/tests/system/digdelv/tests.sh | 49 +++++++++++++++++++++++++++++ bin/tests/system/digdelv/yamlget.py | 33 +++++++++++++++++++ bin/tests/system/dnstap/tests.sh | 1 - util/copyrights | 1 + 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 bin/tests/system/digdelv/yamlget.py diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 0a0509f9be..9178f4ae4b 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -62,6 +62,11 @@ KEYID="$(cat ns2/keyid)" KEYDATA="$(< ns2/keydata sed -e 's/+/[+]/g')" NOSPLIT="$(< ns2/keydata sed -e 's/+/[+]/g' -e 's/ //g')" +HAS_PYYAML=0 +if [ -n "$PYTHON" ] ; then + $PYTHON -c "import yaml" 2> /dev/null && HAS_PYYAML=1 +fi + if [ -x "$DIG" ] ; then n=$((n+1)) echo_i "checking dig short form works ($n)" @@ -716,6 +721,21 @@ if [ -x "$DIG" ] ; then grep '^fd92:7065:0b8e:ffff:0000:0000:0000:0002$' dig.out.test$n > /dev/null || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) + + if [ $HAS_PYYAML -ne 0 ] ; then + n=$((n+1)) + echo_i "check dig +yaml output ($n)" + ret=0 + dig_with_opts +qr +yaml @10.53.0.3 any ns2.example > dig.out.test$n 2>&1 || ret=1 + value=$($PYTHON yamlget.py dig.out.test$n 0 message query_message_data status || ret=1) + [ "$value" = "NOERROR" ] || ret=1 + value=$($PYTHON yamlget.py dig.out.test$n 1 message response_message_data status || ret=1) + [ "$value" = "NOERROR" ] || ret=1 + value=$($PYTHON yamlget.py dig.out.test$n 1 message response_message_data QUESTION_SECTION 0 || ret=1) + [ "$value" = "ns2.example. IN ANY" ] || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) + fi else echo_i "$DIG is needed, so skipping these dig tests" fi @@ -744,6 +764,19 @@ if [ -x "$MDIG" ] ; then grep "; serial" < dig.out.test$n > /dev/null && ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) + + if [ $HAS_PYYAML -ne 0 ] ; then + n=$((n+1)) + echo_i "check mdig +yaml output ($n)" + ret=0 + mdig_with_opts +yaml @10.53.0.3 -t any ns2.example > dig.out.test$n 2>&1 || ret=1 + value=$($PYTHON yamlget.py dig.out.test$n 0 message response_message_data status || ret=1) + [ "$value" = "NOERROR" ] || ret=1 + value=$($PYTHON yamlget.py dig.out.test$n 0 message response_message_data QUESTION_SECTION 0 || ret=1) + [ "$value" = "ns2.example. IN ANY" ] || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) + fi else echo_i "$MDIG is needed, so skipping these mdig tests" fi @@ -965,6 +998,22 @@ if [ -x "$DELV" ] ; then check_ttl_range delv.out.test$n SOA 300 || ret=1 if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status+ret)) + + if [ $HAS_PYYAML -ne 0 ] ; then + n=$((n+1)) + echo_i "check delv +yaml output ($n)" + ret=0 + delv_with_opts +yaml @10.53.0.3 any ns2.example > delv.out.test$n 2>&1 || ret=1 + value=$($PYTHON yamlget.py delv.out.test$n status || ret=1) + [ "$value" = "success" ] || ret=1 + value=$($PYTHON yamlget.py delv.out.test$n query_name || ret=1) + [ "$value" = "ns2.example" ] || ret=1 + value=$($PYTHON yamlget.py delv.out.test$n records 0 answer_not_validated 0 || ret=1) + count=$(echo $value | wc -w ) + [ ${count:-0} -eq 5 ] || ret=1 + if [ $ret -ne 0 ]; then echo_i "failed"; fi + status=$((status+ret)) + fi else echo_i "$DELV is needed, so skipping these delv tests" fi diff --git a/bin/tests/system/digdelv/yamlget.py b/bin/tests/system/digdelv/yamlget.py new file mode 100644 index 0000000000..50be7ebca0 --- /dev/null +++ b/bin/tests/system/digdelv/yamlget.py @@ -0,0 +1,33 @@ +############################################################################ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# 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 http://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. +############################################################################ + +try: + import yaml +except: + print("No python yaml module, skipping") + exit(1) + +import subprocess +import pprint +import sys + +f = open(sys.argv[1], "r") +for item in yaml.safe_load_all(f): + for key in sys.argv[2:]: + try: + key = int(key) + except: pass + try: + item = item[key] + except: + print('error: index not found') + exit(1) + print (item) diff --git a/bin/tests/system/dnstap/tests.sh b/bin/tests/system/dnstap/tests.sh index 83877b102f..2b701a495f 100644 --- a/bin/tests/system/dnstap/tests.sh +++ b/bin/tests/system/dnstap/tests.sh @@ -484,7 +484,6 @@ ret=0 if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` - HAS_PYYAML=0 if [ -n "$PYTHON" ] ; then $PYTHON -c "import yaml" 2> /dev/null && HAS_PYYAML=1 diff --git a/util/copyrights b/util/copyrights index 6585a7c037..b508ed4517 100644 --- a/util/copyrights +++ b/util/copyrights @@ -501,6 +501,7 @@ ./bin/tests/system/digdelv/prereq.sh SH 2018,2019 ./bin/tests/system/digdelv/setup.sh SH 2018,2019 ./bin/tests/system/digdelv/tests.sh SH 2015,2016,2017,2018,2019 +./bin/tests/system/digdelv/yamlget.py PYTHON 2019 ./bin/tests/system/ditch.pl PERL 2015,2016,2018,2019 ./bin/tests/system/dlz/clean.sh SH 2010,2012,2014,2016,2018,2019 ./bin/tests/system/dlz/ns1/dns-root/com/broken/dns.d/@/DNAME=10=example.net.= TXT.BRIEF 2015,2016,2018,2019