From 8b1001c9b52f0d30abf69e5c0c879ab48a4c4caa Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Sun, 1 Oct 2017 13:34:23 +0000 Subject: [PATCH] tests/vmcheck: turn on strict bash mode Closes: #1032 Approved by: cgwalters --- tests/vmcheck/test-basic.sh | 2 +- tests/vmcheck/test-initramfs.sh | 2 +- tests/vmcheck/test-layering-basic.sh | 2 +- tests/vmcheck/test-layering-gpg.sh | 2 +- tests/vmcheck/test-layering-local.sh | 2 +- tests/vmcheck/test-layering-non-root-caps.sh | 30 +++++++++++--------- tests/vmcheck/test-layering-relayer.sh | 2 +- tests/vmcheck/test-layering-rpmdb.sh | 2 +- tests/vmcheck/test-layering-scripts.sh | 2 +- tests/vmcheck/test-layering-unified.sh | 2 +- tests/vmcheck/test-livefs.sh | 2 +- tests/vmcheck/test-override-local-replace.sh | 2 +- tests/vmcheck/test-override-remove.sh | 2 +- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/vmcheck/test-basic.sh b/tests/vmcheck/test-basic.sh index cb7a84aa..e5011b35 100755 --- a/tests/vmcheck/test-basic.sh +++ b/tests/vmcheck/test-basic.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-initramfs.sh b/tests/vmcheck/test-initramfs.sh index 4b7172f7..b4231ead 100755 --- a/tests/vmcheck/test-initramfs.sh +++ b/tests/vmcheck/test-initramfs.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-basic.sh b/tests/vmcheck/test-layering-basic.sh index 94ff1d29..e74aa445 100755 --- a/tests/vmcheck/test-layering-basic.sh +++ b/tests/vmcheck/test-layering-basic.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-gpg.sh b/tests/vmcheck/test-layering-gpg.sh index 85de844c..78b58611 100755 --- a/tests/vmcheck/test-layering-gpg.sh +++ b/tests/vmcheck/test-layering-gpg.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-local.sh b/tests/vmcheck/test-layering-local.sh index 8fb9b9f9..79f9db30 100755 --- a/tests/vmcheck/test-layering-local.sh +++ b/tests/vmcheck/test-layering-local.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-non-root-caps.sh b/tests/vmcheck/test-layering-non-root-caps.sh index c45ed166..7f4886b7 100755 --- a/tests/vmcheck/test-layering-non-root-caps.sh +++ b/tests/vmcheck/test-layering-non-root-caps.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh @@ -92,41 +92,45 @@ fi echo "ok all files layered" check_user() { - user=$(vm_cmd stat -c '%U' $1) + local user=$(vm_cmd stat -c '%U' $1) if [[ $user != $2 ]]; then assert_not_reached "expected user $2 on file $1 but got $user" fi } check_group() { - group=$(vm_cmd stat -c '%G' $1) + local group=$(vm_cmd stat -c '%G' $1) if [[ $group != $2 ]]; then assert_not_reached "expected group $2 on file $1 but got $group" fi } check_fcap() { - fcap=$(vm_cmd getcap $1) - fcap=${fcap#* = } # trim filename + local fcap=$(vm_cmd getcap $1) + local fcap=${fcap#* = } # trim filename if [[ $fcap != $2 ]]; then assert_not_reached "expected fcaps $2 on file $1 but got $fcap" fi } check_file() { - check_user $1 $2 - check_group $1 $3 - check_fcap $1 $4 + local file=$1; shift + local user=$1; shift + local group=$1; shift + local fcap=${1:-} + check_user "$file" "$user" + check_group "$file" "$group" + check_fcap "$file" "$fcap" } -check_file /usr/bin/nrc-none.sh root root "" -check_file /usr/bin/nrc-user.sh nrcuser root "" -check_file /usr/bin/nrc-user-link.sh nrcuser root "" -check_file /usr/bin/nrc-group.sh root nrcgroup "" +check_file /usr/bin/nrc-none.sh root root +check_file /usr/bin/nrc-user.sh nrcuser root +check_file /usr/bin/nrc-user-link.sh nrcuser root +check_file /usr/bin/nrc-group.sh root nrcgroup check_file /usr/bin/nrc-caps.sh root root "cap_net_bind_service+ep" check_file /usr/bin/nrc-caps-setuid.sh root root "cap_net_bind_service+ep" vm_cmd test -u /usr/bin/nrc-caps-setuid.sh -check_file /usr/bin/nrc-usergroup.sh nrcuser nrcgroup "" +check_file /usr/bin/nrc-usergroup.sh nrcuser nrcgroup check_file /usr/bin/nrc-usergroupcaps.sh nrcuser nrcgroup "cap_net_bind_service+ep" check_file /usr/bin/nrc-usergroupcaps-setuid.sh nrcuser nrcgroup "cap_net_bind_service+ep" vm_cmd test -u /usr/bin/nrc-usergroupcaps-setuid.sh diff --git a/tests/vmcheck/test-layering-relayer.sh b/tests/vmcheck/test-layering-relayer.sh index 095033cc..d9c384be 100755 --- a/tests/vmcheck/test-layering-relayer.sh +++ b/tests/vmcheck/test-layering-relayer.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-rpmdb.sh b/tests/vmcheck/test-layering-rpmdb.sh index fa2da302..ab0919fa 100755 --- a/tests/vmcheck/test-layering-rpmdb.sh +++ b/tests/vmcheck/test-layering-rpmdb.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-scripts.sh b/tests/vmcheck/test-layering-scripts.sh index 003b1582..41713b4d 100755 --- a/tests/vmcheck/test-layering-scripts.sh +++ b/tests/vmcheck/test-layering-scripts.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-layering-unified.sh b/tests/vmcheck/test-layering-unified.sh index bbfd4489..7389816a 100755 --- a/tests/vmcheck/test-layering-unified.sh +++ b/tests/vmcheck/test-layering-unified.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-livefs.sh b/tests/vmcheck/test-livefs.sh index 76d267d8..ab5b6374 100755 --- a/tests/vmcheck/test-livefs.sh +++ b/tests/vmcheck/test-livefs.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-override-local-replace.sh b/tests/vmcheck/test-override-local-replace.sh index 8831c5e6..e6623449 100755 --- a/tests/vmcheck/test-override-local-replace.sh +++ b/tests/vmcheck/test-override-local-replace.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh diff --git a/tests/vmcheck/test-override-remove.sh b/tests/vmcheck/test-override-remove.sh index a4bd09cc..222ed42d 100755 --- a/tests/vmcheck/test-override-remove.sh +++ b/tests/vmcheck/test-override-remove.sh @@ -17,7 +17,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -set -e +set -euo pipefail . ${commondir}/libtest.sh . ${commondir}/libvm.sh