]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle non-zero return codes in rootkeysentinel tests
authorTom Krizek <tkrizek@isc.org>
Wed, 28 Jun 2023 09:12:13 +0000 (11:12 +0200)
committerTom Krizek <tkrizek@isc.org>
Fri, 14 Jul 2023 13:49:18 +0000 (15:49 +0200)
bin/tests/system/rootkeysentinel/ns2/sign.sh
bin/tests/system/rootkeysentinel/tests.sh

index d4b19ccd733f987c7073708df54fa54ba9d4ae07..3e48f8a16d108a275e4a0d4fdf7cb9bf3f1b557a 100644 (file)
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-# leave as expr as expr treats arguments with leading 0's as base 10
-# handle exit code 1 from expr when the result is 0
-oldid=${1:-00000}
-newid=$(expr \( ${oldid} + 1000 \) % 65536 || true)
-newid=$(expr "0000${newid}" : '.*\(.....\)$')  # prepend leading 0's
-badid=$(expr \( ${oldid} + 7777 \) % 65536 || true)
-badid=$(expr "0000${badid}" : '.*\(.....\)$')  # prepend leading 0's
+oldid=$(echo ${1:-0} | sed 's/^0*//')
+newid=$(printf '%05u' $(((oldid + 1000) % 65536)))
+badid=$(printf '%05u' $(((oldid + 7777) % 65536)))
+oldid=$(printf '%05u' $((oldid + 0)))
 
 . ../../conf.sh
 
index 6095717e41447abe2f4dcad211fe7bf943ea4625..bfe653c4f080c025d4dafd70955d6f32f63b7935 100644 (file)
@@ -38,12 +38,10 @@ newtest() {
 
 newtest "get test ids"
 $DIG $DIGOPTS . dnskey +short +rrcomm @10.53.0.1 > dig.out.ns1.test$n || ret=1
-oldid=`sed -n 's/.*key id = //p' < dig.out.ns1.test$n`
-oldid=`expr "0000${oldid}" : '.*\(.....\)$'`
-newid=`expr \( ${oldid} + 1000 \) % 65536`
-newid=`expr "0000${newid}" : '.*\(.....\)$'`
-badid=`expr \( ${oldid} + 7777 \) % 65536`
-badid=`expr "0000${badid}" : '.*\(.....\)$'`
+oldid=$(sed -n 's/.*key id = //p' < dig.out.ns1.test$n)
+newid=$(printf "%05u" $(((oldid + 1000) % 65536)))
+badid=$(printf "%05u" $(((oldid + 7777) % 65536)))
+oldid=$(printf "%05u" $((oldid + 0)))
 echo_i "test id: oldid=${oldid} (configured)"
 echo_i "test id: newid=${newid} (not configured)"
 echo_i "test id: badid=${badid}"