From 496f1669507c11bf6db2776526a24b1be9099012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 29 Nov 2024 03:17:33 +0000 Subject: [PATCH] pam/integration-tests/vhs-helpers: Add Wait+CLIPrompt utility command 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. --- .../testdata/tapes/cli/bad_password.tape | 12 ++++-------- .../testdata/tapes/cli/form_with_button.tape | 6 ++---- .../testdata/tapes/cli/max_attempts.tape | 14 +++++--------- .../tapes/cli/mfa_reset_pwquality_auth.tape | 16 ++++++---------- .../tapes/cli/optional_password_reset_skip.tape | 3 +-- .../testdata/tapes/cli/passwd_auth_fail.tape | 14 +++++--------- .../testdata/tapes/cli/passwd_bad_password.tape | 14 +++++--------- .../testdata/tapes/cli/passwd_not_changed.tape | 3 +-- .../testdata/tapes/cli/passwd_not_confirmed.tape | 3 +-- .../testdata/tapes/cli/passwd_rejected.tape | 6 ++---- .../tapes/cli/remember_broker_and_mode.tape | 4 ++-- pam/integration-tests/vhs-helpers_test.go | 5 +++++ 12 files changed, 39 insertions(+), 61 deletions(-) diff --git a/pam/integration-tests/testdata/tapes/cli/bad_password.tape b/pam/integration-tests/testdata/tapes/cli/bad_password.tape index 52a1d91175..aa4abb61d3 100644 --- a/pam/integration-tests/testdata/tapes/cli/bad_password.tape +++ b/pam/integration-tests/testdata/tapes/cli/bad_password.tape @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/form_with_button.tape b/pam/integration-tests/testdata/tapes/cli/form_with_button.tape index e82b5bd000..abf9a6f81f 100644 --- a/pam/integration-tests/testdata/tapes/cli/form_with_button.tape +++ b/pam/integration-tests/testdata/tapes/cli/form_with_button.tape @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/max_attempts.tape b/pam/integration-tests/testdata/tapes/cli/max_attempts.tape index 6bedd6cc8d..34b0103e2d 100644 --- a/pam/integration-tests/testdata/tapes/cli/max_attempts.tape +++ b/pam/integration-tests/testdata/tapes/cli/max_attempts.tape @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/mfa_reset_pwquality_auth.tape b/pam/integration-tests/testdata/tapes/cli/mfa_reset_pwquality_auth.tape index ef250d5db6..85ebf9aefc 100644 --- a/pam/integration-tests/testdata/tapes/cli/mfa_reset_pwquality_auth.tape +++ b/pam/integration-tests/testdata/tapes/cli/mfa_reset_pwquality_auth.tape @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -81,7 +77,7 @@ Show Hide Enter -Wait+Screen /Confirm password:\n>\n/ +Wait+CLIPrompt /Confirm password/ /\[ Skip \]/ Show Hide diff --git a/pam/integration-tests/testdata/tapes/cli/optional_password_reset_skip.tape b/pam/integration-tests/testdata/tapes/cli/optional_password_reset_skip.tape index 25d6a32a6f..593c5d66c2 100644 --- a/pam/integration-tests/testdata/tapes/cli/optional_password_reset_skip.tape +++ b/pam/integration-tests/testdata/tapes/cli/optional_password_reset_skip.tape @@ -26,8 +26,7 @@ Show Hide Enter -Wait+Screen /New password:\n>\n/ -Wait /\[ Skip \]/ +Wait+CLIPrompt /New password/ /\[ Skip \]/ Show Hide diff --git a/pam/integration-tests/testdata/tapes/cli/passwd_auth_fail.tape b/pam/integration-tests/testdata/tapes/cli/passwd_auth_fail.tape index 28071a98c1..ce23172144 100644 --- a/pam/integration-tests/testdata/tapes/cli/passwd_auth_fail.tape +++ b/pam/integration-tests/testdata/tapes/cli/passwd_auth_fail.tape @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/passwd_bad_password.tape b/pam/integration-tests/testdata/tapes/cli/passwd_bad_password.tape index ae46115af5..61044f4779 100644 --- a/pam/integration-tests/testdata/tapes/cli/passwd_bad_password.tape +++ b/pam/integration-tests/testdata/tapes/cli/passwd_bad_password.tape @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/passwd_not_changed.tape b/pam/integration-tests/testdata/tapes/cli/passwd_not_changed.tape index 1a864b7966..098b38901d 100644 --- a/pam/integration-tests/testdata/tapes/cli/passwd_not_changed.tape +++ b/pam/integration-tests/testdata/tapes/cli/passwd_not_changed.tape @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/passwd_not_confirmed.tape b/pam/integration-tests/testdata/tapes/cli/passwd_not_confirmed.tape index fee92678ed..78773ef3d2 100644 --- a/pam/integration-tests/testdata/tapes/cli/passwd_not_confirmed.tape +++ b/pam/integration-tests/testdata/tapes/cli/passwd_not_confirmed.tape @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/passwd_rejected.tape b/pam/integration-tests/testdata/tapes/cli/passwd_rejected.tape index 8af3759694..21c29fb5c4 100644 --- a/pam/integration-tests/testdata/tapes/cli/passwd_rejected.tape +++ b/pam/integration-tests/testdata/tapes/cli/passwd_rejected.tape @@ -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 @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/remember_broker_and_mode.tape b/pam/integration-tests/testdata/tapes/cli/remember_broker_and_mode.tape index 8a2b89d66b..01a7145ac4 100644 --- a/pam/integration-tests/testdata/tapes/cli/remember_broker_and_mode.tape +++ b/pam/integration-tests/testdata/tapes/cli/remember_broker_and_mode.tape @@ -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 @@ -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 diff --git a/pam/integration-tests/vhs-helpers_test.go b/pam/integration-tests/vhs-helpers_test.go index b925fc11c7..a66ce34ce3 100644 --- a/pam/integration-tests/vhs-helpers_test.go +++ b/pam/integration-tests/vhs-helpers_test.go @@ -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 ]+(/(.*)/|(.*))`) @@ -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,