| 1 |
#!/usr/bin/expect |
| 2 |
|
| 3 |
set timeout 2 |
| 4 |
expect_after default {puts stderr "\nFAIL"; exit 1} |
| 5 |
|
| 6 |
if {$argc != 0} { |
| 7 |
puts "usage: run_groupmems.exp" |
| 8 |
exit 1 |
| 9 |
} |
| 10 |
|
| 11 |
# First, switch to the testsuite user |
| 12 |
# (otherwise, no password will be asked) |
| 13 |
send_user "# switch to the 'myuser' user\n" |
| 14 |
send_user "# and expect a '$ ' prompt\n" |
| 15 |
spawn /bin/su myuser |
| 16 |
|
| 17 |
expect "$ " ;# Wait for the prompt |
| 18 |
|
| 19 |
send_user "\n# make sure we are now 'myuser'" |
| 20 |
send_user "\n# id should return 'uid=424242(myuser) gid=424242(myuser) groups=424242(myuser),99(groupmems)'" |
| 21 |
send "\r" ;# restore the prompt for the logs |
| 22 |
send "id\r" ;# Verify we are really testsuite |
| 23 |
|
| 24 |
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser),99(groupmems)" |
| 25 |
|
| 26 |
expect "$ " ;# Wait for the prompt |
| 27 |
|
| 28 |
send_user "\n\n" |
| 29 |
send_user "# now add user utest1 to the myuser group\n" |
| 30 |
send_user "# and expect a password prompt" |
| 31 |
send "\r" ;# restore the prompt for the logs |
| 32 |
send "/usr/sbin/groupmems -d utest1\r" ;# |
| 33 |
expect "Password: " ;# Wait for the Password: prompt |
| 34 |
# Wait a little bit more (it is not ready to receive the password) |
| 35 |
sleep 0.1 |
| 36 |
|
| 37 |
send "myuserF00barbaz\r" ;# Send the password |
| 38 |
|
| 39 |
send_user "\n# password 'myuserF00barbaz' sent\n\n" |
| 40 |
send_user "# expect prompt '$ '" |
| 41 |
|
| 42 |
expect "$ " ;# Wait for the prompt |
| 43 |
send "echo $?\r" |
| 44 |
expect "0\r" |
| 45 |
expect "$ " ;# Wait for the prompt |
| 46 |
close |
| 47 |
|
| 48 |
puts "\nPASS" |
| 49 |
exit 0 |