Skip to content

Commit

Permalink
pam/integration-tests/vhs-helpers: Add Wait+CLIPrompt utility command
Browse files Browse the repository at this point in the history
Use this to wait for a CLI Prompt request that may also include an error
message and/or a button.

In this way we can check the consistency of the output early.
  • Loading branch information
3v1n0 committed Nov 29, 2024
1 parent 6a112c9 commit de64ccc
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 59 deletions.
12 changes: 4 additions & 8 deletions pam/integration-tests/testdata/tapes/cli/bad_password.tape
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Show

Hide
Enter
Wait /No password supplied/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /No password supplied/
Show

Hide
Expand All @@ -45,8 +44,7 @@ Show

Hide
Enter
Wait+Screen /New password:\n>\n/
Wait /The password is shorter than \d+ characters/
Wait+CLIPrompt /New password/ /The password is shorter than \d+ characters/
Show

Hide
Expand All @@ -55,8 +53,7 @@ Show

Hide
Enter
Wait /The password fails the dictionary check/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /The password fails the dictionary check[^\n]*/
Show

Hide
Expand All @@ -74,8 +71,7 @@ Show

Hide
Enter
Wait /Password entries don't match/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /Password entries don't match/
Show

Hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ Show

Hide
Type "7"
Wait+Screen /Enter your one time credential:\n>\n/
Wait /[ Resend sms ]/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend sms \]/
Show

Hide
Expand All @@ -38,8 +37,7 @@ Show

Hide
Enter
Wait+Screen /Enter your one time credential:\n>\n/
Wait /[ Resend sms ]/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend sms \]/
Show

Hide
Expand Down
14 changes: 5 additions & 9 deletions pam/integration-tests/testdata/tapes/cli/max_attempts.tape
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -36,8 +35,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -46,8 +44,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -56,8 +53,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -66,7 +62,7 @@ Show

Hide
Enter
Wait+Screen /invalid password/
Wait+Screen /invalid password 'wrongpass', should be[^\n]+/
Wait+Screen /\nPAM Authenticate\(\)/
Wait+Screen /\nPAM AcctMgmt\(\)/
Wait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Show
# Wait for MFA auth to happen
Hide
Wait+Screen @${AUTHD_SLEEP_EXAMPLE_BROKER_MFA_WAIT} * 1.2 /Enter your new password \(3 days until mandatory\)\n/
Wait+Screen @${AUTHD_SLEEP_EXAMPLE_BROKER_MFA_WAIT} * 1.2 /New password:\n>\n/
Wait+CLIPrompt@${AUTHD_SLEEP_EXAMPLE_BROKER_MFA_WAIT} * 1.2 /New password/ /\[ Skip \]/
Show

Hide
Expand All @@ -41,8 +41,7 @@ Show

Hide
Enter
Wait /The password is the same as the old one/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /\[ Skip \]/ /The password is the same as the old one/
Show

Hide
Expand All @@ -51,8 +50,7 @@ Show

Hide
Enter
Wait /The password fails the dictionary check/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /\[ Skip \]\nThe password fails the dictionary check[^\n]+/
Show

Hide
Expand All @@ -61,8 +59,7 @@ Show

Hide
Enter
Wait /The password is the same as the old one/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /\[ Skip \]\nThe password is the same as the old one/
Show

Hide
Expand All @@ -71,8 +68,7 @@ Show

Hide
Enter
Wait /The password is shorter than \d+ characters/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /\[ Skip \]\nThe password is shorter than \d+ characters/
Show

Hide
Expand All @@ -81,7 +77,7 @@ Show

Hide
Enter
Wait+Screen /Confirm password:\n>\n/
Wait+CLIPrompt /Confirm password/ /\[ Skip \]/
Show

Hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Show

Hide
Enter
Wait+Screen /New password:\n>\n/
Wait /\[ Skip \]/
Wait+CLIPrompt /New password/ /\[ Skip \]/
Show

Hide
Expand Down
14 changes: 5 additions & 9 deletions pam/integration-tests/testdata/tapes/cli/passwd_auth_fail.tape
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -36,8 +35,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -46,8 +44,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -56,8 +53,7 @@ Show

Hide
Enter
Wait /invalid password/
Wait+Screen /Gimme your password:\n>\n/
Wait+CLIPrompt /Gimme your password/ /invalid password '.+', should be[^\n]+/
Show

Hide
Expand All @@ -66,7 +62,7 @@ Show

Hide
Enter
Wait+Screen /invalid password/
Wait+Screen /invalid password '.+', should be[^\n]+/
Wait+Screen /\nPAM ChangeAuthTok\(\)/
Wait+Screen /\nPAM AcctMgmt\(\)/
Wait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,24 @@ Show

Hide
Enter
Wait+Prompt /New password/
Wait+CLIPrompt /New password/
Show

Hide
Enter
Wait /No password supplied/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /No password supplied/
Show

Hide
TypeCLIPassword "1234"
Enter
Wait /The password is shorter than \d+ characters/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /The password is shorter than \d+ characters/
Show

Hide
TypeCLIPassword "12345678"
Enter
Wait /The password fails the dictionary check/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /The password fails the dictionary check[^\n]*/
Show

Hide
Expand All @@ -61,8 +58,7 @@ Show

Hide
Enter
Wait /Password entries don't match/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /Password entries don't match/
Show

Hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Show

Hide
Enter
Wait /The password is the same as the old one/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /The password is the same as the old one/
Show

Hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Show

Hide
Enter
Wait /Password entries don't match/
Wait+Screen /New password:\n>\n/
Wait+CLIPrompt /New password/ /Password entries don't match/
Show

Hide
Expand Down
6 changes: 2 additions & 4 deletions pam/integration-tests/testdata/tapes/cli/passwd_rejected.tape
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Show

Hide
Enter
Wait+Screen /New password:\n>\n/
Wait /new password does not match criteria/
Wait+CLIPrompt /New password/ /new password does not match criteria: must be [^\n]+/
Show

Hide
Expand Down Expand Up @@ -98,8 +97,7 @@ Show

Hide
Enter
Wait+Screen /New password:\n>\n/
Wait /new password does not match criteria/
Wait+CLIPrompt /New password/ /new password does not match criteria: must be [^\n]+/
Show

Hide
Expand Down
5 changes: 5 additions & 0 deletions pam/integration-tests/vhs-helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ var (
vhsWaitRegex = regexp.MustCompile(`(?m)^\s?Wait(\+Line)?(@[^\s]+)?[ ]+(/(.*)/|(.*))$`)
// vhsWaitForPromptRegex adds support for Wait+Prompt /Pattern/ command.
vhsWaitForPromptRegex = regexp.MustCompile(`(?m)^\s?Wait\+Prompt(@[^\s]+)?\s+(/(.*)/|(.*))$`)
// vhsWaitForCLIPromptRegex adds support for Wait+CLIPrompt /Pattern1/ /Pattern2/ command.
vhsWaitForCLIPromptRegex = regexp.MustCompile(
`(?m)^\s?Wait\+CLIPrompt(@[^\s]+)?[ ]+/([^/]+)/([ ]+/([^/]+)/)?([ ]+/(.+)/)?`)
// vhsWaitForNth adds support for Wait+Nth(X) /Pattern/ command, where X is the
// number of values of the same content we want to match.
vhsWaitForNth = regexp.MustCompile(`(?m)^\s?Wait\+Nth\((\d+)\)(@[^\s]+)?\s+(/(.*)/|(.*))$`)
Expand Down Expand Up @@ -387,6 +390,8 @@ Wait+Nth(1) /\n> %s\n/`,

tapeString = vhsWaitRegex.ReplaceAllString(tapeString,
`Wait+Screen$2 /(^|[\n]+)[^\n]*$4$5[^\n]*[\n]*$$/`)
tapeString = vhsWaitForCLIPromptRegex.ReplaceAllString(tapeString,
`Wait+Screen$1 /$2:\n>[\n]+[ ]*$4[\n]*[\n]+$6[\n]*$$/`)
tapeString = vhsWaitForPromptRegex.ReplaceAllString(tapeString,
`Wait+Screen$1 /$3$4:\n>[\n]*$$/`)
tapeString = vhsWaitForNth.ReplaceAllString(tapeString,
Expand Down

0 comments on commit de64ccc

Please sign in to comment.