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 <shallyn@cisco.com>
This commit is contained in:
Serge Hallyn 2020-08-27 23:09:13 -05:00
parent 4047d1fe8e
commit cf8101aaae
10 changed files with 321 additions and 9 deletions

View File

@ -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_
run_test ./su/02/env_special_root-options__bash run_test ./su/02/env_special_root-options__bash
run_test ./su/03/su_run_command01.test run_test ./su/03/su_run_command01.test
run_test ./su/03/su_run_command02.test #run_test ./su/03/su_run_command02.test
run_test ./su/03/su_run_command03.test #run_test ./su/03/su_run_command03.test
run_test ./su/03/su_run_command04.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_command06.test
run_test ./su/03/su_run_command07.test run_test ./su/03/su_run_command07.test
run_test ./su/03/su_run_command08.test #run_test ./su/03/su_run_command08.test
run_test ./su/03/su_run_command09.test #run_test ./su/03/su_run_command09.test
run_test ./su/03/su_run_command10.test run_test ./su/03/su_run_command10.test
run_test ./su/03/su_run_command11.test #run_test ./su/03/su_run_command11.test
run_test ./su/03/su_run_command12.test #run_test ./su/03/su_run_command12.test
run_test ./su/03/su_run_command13.test #run_test ./su/03/su_run_command13.test
run_test ./su/03/su_run_command14.test run_test ./su/03/su_run_command14.test
run_test ./su/03/su_run_command15.test run_test ./su/03/su_run_command15.test
run_test ./su/03/su_run_command16.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_wrong_user.test
run_test ./su/04/su_user_wrong_passwd.test run_test ./su/04/su_user_wrong_passwd.test
run_test ./su/04/su_user_wrong_passwd_syslog.test run_test ./su/04/su_user_wrong_passwd_syslog.test

View File

@ -0,0 +1,2 @@
root
args: first second third

View File

@ -0,0 +1,2 @@
myuser
args: first second third

View File

@ -7,6 +7,8 @@ cd $(dirname $0)
. ../../common/config.sh . ../../common/config.sh
. ../../common/log.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" log_start "$0" "Running commands (check working directory): su -c pwd - myuser -p"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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