From 02edc985cff25ef18a3d646404c624844f98c45d Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Wed, 28 Jun 2023 11:12:13 +0200 Subject: [PATCH] Handle non-zero return codes in rootkeysentinel tests (cherry picked from commit d203681a750267eec38ac1a3b9312c74a0778d2b) --- bin/tests/system/rootkeysentinel/ns2/sign.sh | 11 ++++------- bin/tests/system/rootkeysentinel/tests.sh | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/bin/tests/system/rootkeysentinel/ns2/sign.sh b/bin/tests/system/rootkeysentinel/ns2/sign.sh index d4b19ccd73..3e48f8a16d 100644 --- a/bin/tests/system/rootkeysentinel/ns2/sign.sh +++ b/bin/tests/system/rootkeysentinel/ns2/sign.sh @@ -11,13 +11,10 @@ # 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 diff --git a/bin/tests/system/rootkeysentinel/tests.sh b/bin/tests/system/rootkeysentinel/tests.sh index 6095717e41..bfe653c4f0 100644 --- a/bin/tests/system/rootkeysentinel/tests.sh +++ b/bin/tests/system/rootkeysentinel/tests.sh @@ -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}"