From: Karel Zak Date: Wed, 28 Aug 2024 10:23:25 +0000 (+0200) Subject: tests: add su --whitelist-environment test X-Git-Tag: v2.42-start~214^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3489e86248361611db214a7b866cdc8e9b1d9a7a;p=thirdparty%2Futil-linux.git tests: add su --whitelist-environment test Signed-off-by: Karel Zak --- diff --git a/tests/commands.sh b/tests/commands.sh index 3febcbc63..05d4d313e 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -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 index 000000000..ddbfaf66f --- /dev/null +++ b/tests/expected/su/environ @@ -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 index 000000000..cf271fd32 --- /dev/null +++ b/tests/ts/su/environ @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright (C) 2024 Karel Zak +# +# 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