diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:22:06 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:22:06 +0000 |
commit | 741c1ef7a4f2ac316ad6e557ddbe03023413478d (patch) | |
tree | 38890f681daa26c57e865b4feca10d0ca53e1046 /tests/su/11_su_sulog_failure/run_su.exp | |
parent | Initial commit. (diff) | |
download | shadow-upstream.tar.xz shadow-upstream.zip |
Adding upstream version 1:4.5.upstream/1%4.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/su/11_su_sulog_failure/run_su.exp')
-rwxr-xr-x | tests/su/11_su_sulog_failure/run_su.exp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/su/11_su_sulog_failure/run_su.exp b/tests/su/11_su_sulog_failure/run_su.exp new file mode 100755 index 0000000..57bb98f --- /dev/null +++ b/tests/su/11_su_sulog_failure/run_su.exp @@ -0,0 +1,67 @@ +#!/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 { + timeout { + puts "\ntimeout...FAIL" + exit 1 + } + "uid=424243(testsuite) gid=424243 groups=424243" +} + +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 wrong\r" ;# Send the password + +send_user "\n# password '$password wrong' sent\n\n" +send_user "# expect prompt '$ '" + +expect { + # Wait for the new prompt + "$ " { + send_user "\n\n# make sure we are 'testsuite'\n" + 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 the id + expect "uid=424243(testsuite) gid=424243 groups=424243" + send "exit\r" + puts "\nPASS" + exit 0 + } +} + +puts "\ntimeout...FAIL" +exit 1 |