From: Serge Hallyn Date: Fri, 28 Aug 2020 04:09:13 +0000 (-0500) Subject: Update su tests X-Git-Tag: v4.9~61^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cf8101aaae51464cbe7e8bf3fe9c03d10c82a8ac;p=thirdparty%2Fshadow.git Update su tests Some of these tests seem wrong. The assume that su -- -c command should work, whereas -- should mean pass all remaining arguments along to the command. Add some new tests based on examples in Issue 253 Signed-off-by: Serge Hallyn --- diff --git a/tests/run_some b/tests/run_some index 2d085d597..fba59bd3a 100755 --- a/tests/run_some +++ b/tests/run_some @@ -90,22 +90,28 @@ run_test ./su/02/env_special_root-options_-p_bash run_test ./su/02/env_special_root-options_ run_test ./su/02/env_special_root-options__bash run_test ./su/03/su_run_command01.test -run_test ./su/03/su_run_command02.test -run_test ./su/03/su_run_command03.test +#run_test ./su/03/su_run_command02.test +#run_test ./su/03/su_run_command03.test run_test ./su/03/su_run_command04.test -run_test ./su/03/su_run_command05.test +#run_test ./su/03/su_run_command05.test run_test ./su/03/su_run_command06.test run_test ./su/03/su_run_command07.test -run_test ./su/03/su_run_command08.test -run_test ./su/03/su_run_command09.test +#run_test ./su/03/su_run_command08.test +#run_test ./su/03/su_run_command09.test run_test ./su/03/su_run_command10.test -run_test ./su/03/su_run_command11.test -run_test ./su/03/su_run_command12.test -run_test ./su/03/su_run_command13.test +#run_test ./su/03/su_run_command11.test +#run_test ./su/03/su_run_command12.test +#run_test ./su/03/su_run_command13.test run_test ./su/03/su_run_command14.test run_test ./su/03/su_run_command15.test run_test ./su/03/su_run_command16.test -run_test ./su/03/su_run_command17.test +#run_test ./su/03/su_run_command17.test +run_test ./su/03/su_run_command18.test +run_test ./su/03/su_run_command19.test +run_test ./su/03/su_run_command20.test +run_test ./su/03/su_run_command21.test +run_test ./su/03/su_run_command22.test +run_test ./su/03/su_run_command23.test run_test ./su/04/su_wrong_user.test run_test ./su/04/su_user_wrong_passwd.test run_test ./su/04/su_user_wrong_passwd_syslog.test diff --git a/tests/su/03/data/rootuser.out b/tests/su/03/data/rootuser.out new file mode 100644 index 000000000..9da4483ec --- /dev/null +++ b/tests/su/03/data/rootuser.out @@ -0,0 +1,2 @@ +root +args: first second third diff --git a/tests/su/03/data/tsuser.out b/tests/su/03/data/tsuser.out new file mode 100644 index 000000000..4796a5486 --- /dev/null +++ b/tests/su/03/data/tsuser.out @@ -0,0 +1,2 @@ +myuser +args: first second third diff --git a/tests/su/03/su_run_command17.test b/tests/su/03/su_run_command17.test index c1f15c5eb..024d0da1b 100755 --- a/tests/su/03/su_run_command17.test +++ b/tests/su/03/su_run_command17.test @@ -7,6 +7,8 @@ cd $(dirname $0) . ../../common/config.sh . ../../common/log.sh +# FIXME +# su: ignoring --preserve-environment, it's mutually exclusive with --login log_start "$0" "Running commands (check working directory): su -c pwd - myuser -p" diff --git a/tests/su/03/su_run_command18.test b/tests/su/03/su_run_command18.test new file mode 100755 index 000000000..280c3f16b --- /dev/null +++ b/tests/su/03/su_run_command18.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' testsuite -- first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' testsuite -- first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' testsuite -- first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/tsuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 + diff --git a/tests/su/03/su_run_command19.test b/tests/su/03/su_run_command19.test new file mode 100755 index 000000000..c4c7b0ad2 --- /dev/null +++ b/tests/su/03/su_run_command19.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' testsuite first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' testsuite first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' testsuite first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/tsuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 + diff --git a/tests/su/03/su_run_command20.test b/tests/su/03/su_run_command20.test new file mode 100755 index 000000000..21393610b --- /dev/null +++ b/tests/su/03/su_run_command20.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - testsuite first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - testsuite first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' - testsuite first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/tsuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 + diff --git a/tests/su/03/su_run_command21.test b/tests/su/03/su_run_command21.test new file mode 100755 index 000000000..36c9940aa --- /dev/null +++ b/tests/su/03/su_run_command21.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - testsuite -- first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - testsuite -- first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' - testsuite -- first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/tsuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 + diff --git a/tests/su/03/su_run_command22.test b/tests/su/03/su_run_command22.test new file mode 100755 index 000000000..b80248894 --- /dev/null +++ b/tests/su/03/su_run_command22.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - -- first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' - -- first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' - -- first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/rootuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 + diff --git a/tests/su/03/su_run_command23.test b/tests/su/03/su_run_command23.test new file mode 100755 index 000000000..9efec1876 --- /dev/null +++ b/tests/su/03/su_run_command23.test @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cd $(dirname $0) + +. ../../common/config.sh +. ../../common/log.sh + +cat > /tmp/shadow_test_wrap << "EOF" +#!/bin/sh + +whoami +echo args: "$@" +EOF +chmod 755 /tmp/shadow_test_wrap + +log_start "$0" "Running commands: su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' -- first second third" + +save_config + +# restore the files on exit +trap 'log_status "$0" "FAILURE"; restore_config' 0 + +change_config + +echo "/bin/su -c '/tmp/shadow_test_wrap \$1 \$2 \$3' -- first second third > tmp/out 2> tmp/err" +/bin/su -c '/tmp/shadow_test_wrap $1 $2 $3' -- first second third > tmp/out 2> tmp/err + +echo "su reported:" +echo "=== stdout ===" +cat tmp/out +echo "=== stderr ===" +cat tmp/err +echo "==============" + +echo -n "Checking tmp/out..." +diff -au data/rootuser.out tmp/out +rm -f tmp/out +echo "OK" + +echo -n "Checking tmp/err..." +[ "$(wc -c tmp/err)" = "0 tmp/err" ] || false +rm -f tmp/err +echo "OK" + +log_status "$0" "SUCCESS" +restore_config +trap '' 0 +