]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Update su tests 275/head
authorSerge Hallyn <shallyn@cisco.com>
Fri, 28 Aug 2020 04:09:13 +0000 (23:09 -0500)
committerSerge Hallyn <shallyn@cisco.com>
Fri, 28 Aug 2020 04:59:07 +0000 (23:59 -0500)
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>
tests/run_some
tests/su/03/data/rootuser.out [new file with mode: 0644]
tests/su/03/data/tsuser.out [new file with mode: 0644]
tests/su/03/su_run_command17.test
tests/su/03/su_run_command18.test [new file with mode: 0755]
tests/su/03/su_run_command19.test [new file with mode: 0755]
tests/su/03/su_run_command20.test [new file with mode: 0755]
tests/su/03/su_run_command21.test [new file with mode: 0755]
tests/su/03/su_run_command22.test [new file with mode: 0755]
tests/su/03/su_run_command23.test [new file with mode: 0755]

index 2d085d5978b3e17bd01d0501ccfeac62a5be515f..fba59bd3a18a52701e6933f27e18d736ca987ab7 100755 (executable)
@@ -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 (file)
index 0000000..9da4483
--- /dev/null
@@ -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 (file)
index 0000000..4796a54
--- /dev/null
@@ -0,0 +1,2 @@
+myuser
+args: first second third
index c1f15c5eb26bac32c5f9f83f0620d41d81050e53..024d0da1b81dd6e5e3a66ed0bb8e5eeeeffb57bc 100755 (executable)
@@ -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 (executable)
index 0000000..280c3f1
--- /dev/null
@@ -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 (executable)
index 0000000..c4c7b0a
--- /dev/null
@@ -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 (executable)
index 0000000..2139361
--- /dev/null
@@ -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 (executable)
index 0000000..36c9940
--- /dev/null
@@ -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 (executable)
index 0000000..b802488
--- /dev/null
@@ -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 (executable)
index 0000000..9efec18
--- /dev/null
@@ -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
+