From 0dd9e8e770a69e5158e17ed58da4139803d08ae0 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 208ee7b7b..4e7f6028b 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 45ff61887..e32c66514 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 ]/ +Wait+CLIPrompt /Enter your one time credential/ /\[ Resend sms \]/ Show Hide @@ -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 diff --git a/pam/integration-tests/testdata/tapes/cli/max_attempts.tape b/pam/integration-tests/testdata/tapes/cli/max_attempts.tape index 218296d67..911034f69 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,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 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 24800dfbd..da5c89378 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 35945a90d..fd5b51a10 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 bb022bd3b..5a63ba8be 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,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 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 d9c38299e..a4244a6be 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 0449d1f3b..ce4a52952 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 89b65bd14..26ee2c6ca 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 9f27c01e2..80bd2f85d 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 @@ -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 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 ecd23bf33..67220cf1f 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+Prompt /Enter your one time credential/ +Wait+CLIPrompt /Enter your one time credential/ /\[ Resend sms \]/ Show Hide @@ -51,7 +51,7 @@ Show Hide Enter -Wait+Prompt /Enter your one time credential/ +Wait+CLIPrompt /Enter your one time credential/ /\[ Resend sms \]/ Show Hide diff --git a/pam/integration-tests/vhs-helpers_test.go b/pam/integration-tests/vhs-helpers_test.go index 6c6363fb1..c8ba95ccf 100644 --- a/pam/integration-tests/vhs-helpers_test.go +++ b/pam/integration-tests/vhs-helpers_test.go @@ -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+(/(.*)/|(.*))$`) @@ -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,