Debian Codegraph @

tests/grouptools/gpasswd/68_gpasswd-M_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 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 members to root\n"
41 send_user "# and expect a permission denied"
42 send "\r" ;# restore the prompt for the logs
43 send "gpasswd -M root $group\r" ;# Change the password
44 expect "gpasswd: Permission denied." ;# Not an admin
45
46 send_user "\n"
47 send_user "# expect prompt '$user_prompt'\n"
48
49 expect {
50 # Wait for the new prompt
51 "$user_prompt" {
52 send "exit\r"
53 expect "$ "
54 puts "\nPASS"
55 exit 0
56 }
57 }
58
59 puts "\ntimeout...FAIL"
60 exit 1