]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: add su --whitelist-environment test
authorKarel Zak <kzak@redhat.com>
Wed, 28 Aug 2024 10:23:25 +0000 (12:23 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 4 Sep 2024 11:37:32 +0000 (13:37 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
tests/commands.sh
tests/expected/su/environ [new file with mode: 0644]
tests/ts/su/environ [new file with mode: 0755]

index 3febcbc6321327e1622c5df4cef29dcb4a2f34b7..05d4d313e33abfb40fb7e4e957c78cd959667ad7 100644 (file)
@@ -126,6 +126,7 @@ TS_CMD_SETARCH=${TS_CMD_SETARCH-"${ts_commandsdir}setarch"}
 TS_CMD_SETPGID=${TS_CMD_SETPGID-"${ts_commandsdir}setpgid"}
 TS_CMD_SETPRIV=${TS_CMD_SETPRIV-"${ts_commandsdir}setpriv"}
 TS_CMD_SETSID=${TS_CMD_SETSID-"${ts_commandsdir}setsid"}
+TS_CMD_SU=${TS_CMD_SU-"${ts_commandsdir}su"}
 TS_CMD_SWAPLABEL=${TS_CMD_SWAPLABEL:-"${ts_commandsdir}swaplabel"}
 TS_CMD_SWAPOFF=${TS_CMD_SWAPOFF:-"${ts_commandsdir}swapoff"}
 TS_CMD_SWAPON=${TS_CMD_SWAPON:-"${ts_commandsdir}swapon"}
diff --git a/tests/expected/su/environ b/tests/expected/su/environ
new file mode 100644 (file)
index 0000000..ddbfaf6
--- /dev/null
@@ -0,0 +1,4 @@
+foo:abc bar:baar zuu:zuux
+foo: bar: zuu:
+foo:abc bar: zuu:
+foo:abc bar:baar zuu:
diff --git a/tests/ts/su/environ b/tests/ts/su/environ
new file mode 100755 (executable)
index 0000000..cf271fd
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Copyright (C) 2024 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="environ"
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+ts_skip_nonroot 
+ts_check_test_command "$TS_CMD_SU"
+
+export ZUU=zuux
+export FOO=abc
+export BAR=baar
+
+# All should be available
+$TS_CMD_SU --command 'echo foo:$FOO bar:$BAR zuu:$ZUU' >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+# All should be removed
+$TS_CMD_SU --login --command 'echo foo:$FOO bar:$BAR zuu:$ZUU' >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+# Only specified options should be available
+$TS_CMD_SU --whitelist-environment FOO --login --command 'echo foo:$FOO bar:$BAR zuu:$ZUU' >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+# Only specified options should be available
+$TS_CMD_SU --whitelist-environment FOO,BAR --login --command 'echo foo:$FOO bar:$BAR zuu:$ZUU' >> $TS_OUTPUT 2>> $TS_ERRLOG
+
+# We do not have control over PAM setup, and the goal of this test is to check
+# the environment, not the overall functionality of su(1). Therefore, if su(1)
+# fails due to authentication, the test should be skipped.
+#
+grep -q 'Authentication failure' $TS_ERRLOG
+[ $? -eq 0 ] && ts_skip "authentication failure"
+
+ts_finalize