summaryrefslogtreecommitdiffstats
path: root/tests/su/05/run_su_failed.exp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/su/05/run_su_failed.exp')
-rwxr-xr-xtests/su/05/run_su_failed.exp58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/su/05/run_su_failed.exp b/tests/su/05/run_su_failed.exp
new file mode 100755
index 0000000..3ef2443
--- /dev/null
+++ b/tests/su/05/run_su_failed.exp
@@ -0,0 +1,58 @@
+#!/usr/bin/expect
+
+set timeout 5
+expect_after default {puts "\nFAIL"; exit 1}
+
+if {$argc != 3} {
+ puts "usage: run_su.exp <user> <password> <prompt>"
+ exit 1
+}
+
+set user [lindex $argv 0]
+set password [lindex $argv 1]
+set prompt [lindex $argv 2]
+
+# First, switch to the testsuite user
+# (otherwise, no password will be asked)
+send_user "# switch to the passwordless 'testsuite' user\n"
+send_user "# and expect a '$ ' prompt\n"
+spawn /bin/su testsuite
+
+expect "$ " ;# Wait for the prompt
+
+send_user "\n# make sure we are now 'testsuite'"
+send_user "\n# id should return 'uid=424243(testsuite) gid=424243 groups=424243'"
+send "\r" ;# restore the prompt for the logs
+send "id\r" ;# Verify we are really testsuite
+
+expect "uid=424243(testsuite) gid=424243 groups=424243\r"
+
+expect "$ " ;# Wait for the prompt
+
+send_user "\n\n"
+send_user "# now switch to user '$user'\n"
+send_user "# and expect a password prompt"
+send "\r" ;# restore the prompt for the logs
+send "su $user\r" ;# Switch to the user
+expect "Password: " ;# Wait for the Password: prompt
+# Wait a little bit more (su is not ready to receive the password)
+sleep 0.1
+
+send "$password\r" ;# Send the password
+
+send_user "\n# password '$password' sent\n\n"
+send_user "# expect failure"
+
+expect "su: Authentication failure\r"
+expect "$ " ;# Wait for the prompt
+
+send_user "\n\n# make sure we are still 'testsuite'"
+send "\r" ;# restore the prompt for the logs
+expect "$ " ;# Wait for the prompt
+send "id\r" ;# Verify we are really testsuite
+
+expect "uid=424243(testsuite) gid=424243 groups=424243\r"
+expect "$ " ;# Wait for the prompt
+send "exit\r"
+puts "\nPASS"
+exit 0