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 Dec 11, 2024
1 parent 2538aa4 commit 496f166
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 61 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 \(1 sent\) \]/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend SMS \(1 sent\) \]/
Show

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

Hide
Enter
Wait+Screen /Enter your one time credential:\n>\n/
Wait /\[ Resend SMS \(2 sent\) \]/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend SMS \(2 sent\) \]/
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,6 +62,6 @@ Show

Hide
Enter
Wait+Screen /invalid password/
Wait+Screen /invalid password 'wrongpass', should be[^\n]+/
${AUTHD_TEST_TAPE_COMMAND_AUTH_FINAL_WAIT}
Show
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,6 +62,6 @@ Show

Hide
Enter
Wait+Screen /invalid password/
Wait+Screen /invalid password '.+', should be[^\n]+/
${AUTHD_TEST_TAPE_COMMAND_PASSWD_FINAL_WAIT}
Show
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 @@ -97,8 +96,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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Show

Hide
Type "7"
Wait+Screen /Enter your one time credential:\n>\n/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend SMS \(1 sent\) \]/
Show

Hide
Expand All @@ -49,7 +49,7 @@ Show

Hide
Enter
Wait+Screen /Enter your one time credential:\n>\n/
Wait+CLIPrompt /Enter your one time credential/ /\[ Resend SMS \(1 sent\) \]/
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 @@ -109,6 +109,9 @@ var (
vhsWaitSuffix = regexp.MustCompile(`\bWait\+Suffix(@\S+)?[\t ]+(/(.*)/|(.*))`)
// vhsWaitPromptRegex adds support for Wait+Prompt /Pattern/ command.
vhsWaitPromptRegex = regexp.MustCompile(`\bWait\+Prompt(@\S+)?[\t ]+(/(.*)/|(.*))`)
// vhsWaitCLIPromptRegex adds support for Wait+CLIPrompt /Pattern1/ /Pattern2/ command.
vhsWaitCLIPromptRegex = regexp.MustCompile(
`\bWait\+CLIPrompt(@\S+)?[\t ]+/([^/]+)/([\t ]+/([^/]+)/)?([\t ]+/(.+)/)?`)
// vhsWaitNth adds support for Wait+Nth(X) /Pattern/ command, where X is the
// number of values of the same content we want to match.
vhsWaitNth = regexp.MustCompile(`\bWait\+Nth\((\d+)\)(@\S+)?[\t ]+(/(.*)/|(.*))`)
Expand Down Expand Up @@ -456,6 +459,8 @@ Wait+Screen /\n> %s\n/`,
regexp.QuoteMeta(strings.Repeat("*", len(password)))))
}

tapeString = vhsWaitCLIPromptRegex.ReplaceAllString(tapeString,
`Wait+Suffix$1 /$2:\n>[\n]+[ ]*$4[\n]*[\n]+$6/`)
tapeString = vhsWaitPromptRegex.ReplaceAllString(tapeString,
`Wait+Suffix$1 /$3$4:\n>/`)
tapeString = vhsWaitSuffix.ReplaceAllString(tapeString,
Expand Down

0 comments on commit 496f166

Please sign in to comment.