Debian Codegraph @

tests/grouptools/gpasswd/67_gpasswd-A_myuser/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 != 3} {
7 puts "usage: gpasswd.exp <run_user> <group> <user_prompt>"
8 exit 1
9 }
10
11 set run_user [lindex $argv 0]
12 set group [lindex $argv 1]
13 set user_prompt [lindex $argv 3]
14
15 # First, switch to the testsuite user
16 # (otherwise, no password will be asked)
17 send_user "# switch to user '$run_user'\n"
18 send_user "# and expect a '$user_prompt' prompt\n"
19 spawn /bin/su $run_user
20
21 expect "$user_prompt" ;# Wait for the prompt
22
23 send_user "\n# make sure we are now '$run_user'"
24 send_user "\n# whoami should return '$run_user'"
25 send "\r" ;# restore the prompt for the logs
26 send "whoami\r" ;# Verify we are really testsuite
27
28 expect {
29 timeout {
30 puts "\ntimeout...FAIL"
31 exit 1
32 }
33 "$run_user"
34 }
35
36 expect "$user_prompt" ;# Wait for the prompt
37
38 send_user "\n\n"
39 send_user "# now change '$group' 's admins to 'root'\n"
40 send_user "# and expect a permission denied"
41 send "\r" ;# restore the prompt for the logs
42 send "gpasswd -A root $group\r" ;# Change the password
43 expect "gpasswd: Permission denied." ;# Not an admin
44
45 send_user "\n"
46 send_user "# expect prompt '$user_prompt'\n"
47
48 expect {
49 # Wait for the new prompt
50 "$user_prompt" {
51 send "exit\r"
52 expect "$ "
53 puts "\nPASS"
54 exit 0
55 }
56 }
57
58 puts "\ntimeout...FAIL"
59 exit 1