Debian Codegraph @

tests/grouptools/gpasswd/19_gpasswd_change_passwd-root/gpasswd.exp

raw
1 #!/usr/bin/expect
2
3 set timeout 2
4 expect_after default {puts stderr "\nFAIL"; exit 1}
5
6 if {$argc != 4} {
7 puts "usage: gpasswd.exp <run_user> <group> <g_password> <user_prompt>"
8 exit 1
9 }
10
11 set run_user [lindex $argv 0]
12 set group [lindex $argv 1]
13 set g_password [lindex $argv 2]
14 set user_prompt [lindex $argv 3]
15
16 # First, switch to the testsuite user
17 # (otherwise, no password will be asked)
18 send_user "# switch to user '$run_user'\n"
19 send_user "# and expect a '$user_prompt' prompt\n"
20 spawn /bin/su $run_user
21
22 expect "$user_prompt" ;# Wait for the prompt
23
24 send_user "\n# make sure we are now '$run_user'"
25 send_user "\n# whoami should return '$run_user'"
26 send "\r" ;# restore the prompt for the logs
27 send "whoami\r" ;# Verify we are really testsuite
28
29 expect {
30 timeout {
31 puts "\ntimeout...FAIL"
32 exit 1
33 }
34 "$run_user"
35 }
36
37 expect "$user_prompt" ;# Wait for the prompt
38
39 send_user "\n\n"
40 send_user "# now change '$group' 's password to '$g_password'\n"
41 send_user "# and expect a password prompt"
42 send "\r" ;# restore the prompt for the logs
43 send "gpasswd $group\r" ;# Change the password
44 expect "New Password: " ;# Wait for the Password: prompt
45 # Wait a little bit more (gpasswd is not ready to receive the password)
46 sleep 0.1
47 send "$g_password\r" ;# Send the password
48
49 send_user "\n# password '$g_password' sent\n\n"
50
51 send_user "Expect a new password prompt\n"
52 expect "Re-enter new password: " ;# Wait for the Password: prompt
53 # Wait a little bit more (gpasswd is not ready to receive the password)
54 sleep 0.1
55 send "$g_password\r" ;# Send the password
56
57 send_user "# expect prompt '$user_prompt'"
58
59 expect {
60 # Wait for the new prompt
61 "$user_prompt" {
62 send "exit\r"
63 expect "$ "
64 puts "\nPASS"
65 exit 0
66 }
67 }
68
69 puts "\ntimeout...FAIL"
70 exit 1