summaryrefslogtreecommitdiff
path: root/tests/grouptools/gpasswd/70_gpasswd_change_passwd_3_tries/gpasswd.exp
blob: b8ac4e9b59fe21acc7e5a20fa28b70fe453da85c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/expect

set timeout 2
expect_after default {puts "\nFAIL"; exit 1}

if {$argc != 4} {
	puts "usage: gpasswd.exp <run_user> <group> <g_password> <user_prompt>"
	exit 1
}

set run_user    [lindex $argv 0]
set group       [lindex $argv 1]
set g_password  [lindex $argv 2]
set user_prompt [lindex $argv 3]

# First, switch to the testsuite user
# (otherwise, no password will be asked)
send_user "# switch to user '$run_user'\n"
send_user "# and expect a '$user_prompt' prompt\n"
spawn /bin/su $run_user

expect "$user_prompt"		;# Wait for the prompt

send_user "\n# make sure we are now '$run_user'"
send_user "\n# whoami should return '$run_user'"
send "\r"			;# restore the prompt for the logs
send "whoami\r"			;# Verify we are really testsuite

expect {
	timeout {
		puts "\ntimeout...FAIL"
		exit 1
	}
	"$run_user"
}

expect "$user_prompt"			;# Wait for the prompt

send_user "\n\n"
send_user "# now change '$group' 's password to '$g_password'\n"
send_user "# and expect a password prompt"
send "\r"			;# restore the prompt for the logs
send "gpasswd $group\r"		;# Change the password
expect "New Password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "wrong $g_password\r"		;# Send the password
send_user "\n# wrong password 'wrong $g_password' sent\n\n"
send_user "Expect a new password prompt\n"
expect "Re-enter new password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "$g_password\r"		;# Send the password
send_user "# expect failure 1 and retry"
expect "They don't match; try again"

expect "New Password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "wrong $g_password\r"		;# Send the password
send_user "\n# wrong password 'wrong $g_password' sent\n\n"
send_user "Expect a new password prompt\n"
expect "Re-enter new password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "$g_password\r"		;# Send the password
send_user "# expect failure 2 and retry"
expect "They don't match; try again"

expect "New Password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "$g_password\r"		;# Send the password

send_user "\n# password '$g_password' sent for the last try\n\n"

send_user "Expect a new password prompt\n"
expect "Re-enter new password: "		;# Wait for the Password: prompt
# Wait a little bit more (gpasswd is not ready to receive the password)
sleep 0.1
send "$g_password\r"		;# Send the password

send_user "# expect prompt '$user_prompt'"

expect {
	# Wait for the new prompt
	"$user_prompt" {
		send "exit\r"
		expect "$ "
		puts "\nPASS"
		exit 0
	}
}

puts "\ntimeout...FAIL"
exit 1