From a6fb61be771715e8e07d9db4196a67f44f55d487 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 22 Dec 2023 13:16:06 +0100 Subject: [PATCH 1/3] test: make the test actually test Follow-up for dd25a95763e6ee52d40f4012ffeb2ce719f26b8d. --- test/units/testsuite-74.run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/testsuite-74.run.sh b/test/units/testsuite-74.run.sh index d43d17ca61..1b4daf8bf4 100755 --- a/test/units/testsuite-74.run.sh +++ b/test/units/testsuite-74.run.sh @@ -229,7 +229,7 @@ assert_eq "$A" "$B" # Check that invoking the tool under the uid0 alias name works uid0 ls / -echo "$(uid0 echo foo)" = "foo" +assert_eq "$(uid0 echo foo)" "foo" umount /proc/version rm "$V" From 7de211891658a3f74c4afefdf4083d1ef3f10249 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 22 Dec 2023 14:09:58 +0100 Subject: [PATCH 2/3] test: slightly extend uid0's coverage --- test/units/testsuite-74.run.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/units/testsuite-74.run.sh b/test/units/testsuite-74.run.sh index 1b4daf8bf4..69907d4f38 100755 --- a/test/units/testsuite-74.run.sh +++ b/test/units/testsuite-74.run.sh @@ -230,6 +230,15 @@ assert_eq "$A" "$B" # Check that invoking the tool under the uid0 alias name works uid0 ls / assert_eq "$(uid0 echo foo)" "foo" +# Check if we set some expected environment variables +for arg in "" "--user=root" "--user=testuser"; do + assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_USER')" "$USER" + assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_UID')" "$(id -u "$USER")" + assert_eq "$(uid0 ${arg:+"$arg"} bash -c 'echo $SUDO_GID')" "$(id -u "$USER")" +done +# Let's chain a couple of uid0 calls together, for fun +readarray -t cmdline < <(printf "%.0suid0\n" {0..31}) +assert_eq "$("${cmdline[@]}" bash -c 'echo $SUDO_USER')" "$USER" umount /proc/version rm "$V" From addbe898a704bc6402907488ba16f97f6ab337d9 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 22 Dec 2023 14:16:56 +0100 Subject: [PATCH 3/3] test: make the variable names slightly more descriptive Follow-up for 5ca8d2474ca8b8b3f42999fb2f6e5e1498b22aa9. --- test/units/testsuite-74.run.sh | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test/units/testsuite-74.run.sh b/test/units/testsuite-74.run.sh index 69907d4f38..38cbca54ce 100755 --- a/test/units/testsuite-74.run.sh +++ b/test/units/testsuite-74.run.sh @@ -213,19 +213,18 @@ for opt in nice on-{active,boot,calendar,startup,unit-active,unit-inactive} prop done # Let's make sure that ProtectProc= properly moves submounts of the original /proc over to the new proc +BOOT_ID="$( "$V" -mount --bind "$V" /proc/version - -B=$(systemd-run -q --wait --pipe -p ProtectProc=invisible cat /proc/version) - -assert_eq "$A" "$B" +TMP_KVER="/tmp/version.$RANDOM" +KVER="$("$TMP_KVER" +mount --bind "$TMP_KVER" /proc/version +UNIT_KVER="$(systemd-run -q --wait --pipe -p ProtectProc=invisible cat /proc/version)" +assert_eq "$KVER" "$UNIT_KVER" +umount /proc/version +rm -f "$TMP_KVER" # Check that invoking the tool under the uid0 alias name works uid0 ls / @@ -239,6 +238,3 @@ done # Let's chain a couple of uid0 calls together, for fun readarray -t cmdline < <(printf "%.0suid0\n" {0..31}) assert_eq "$("${cmdline[@]}" bash -c 'echo $SUDO_USER')" "$USER" - -umount /proc/version -rm "$V"