Skip to content

Commit

Permalink
Consolidate password validation in test
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron Durham <u64.cam@gmail.com>
  • Loading branch information
camerondurham committed Feb 27, 2024
1 parent 09dcdc9 commit ae6177a
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public class SecuritySettingsConfigurerTests {

private final String adminPasswordKey = ConfigConstants.OPENSEARCH_INITIAL_ADMIN_PASSWORD;

private static final String PASSWORD_VALIDATION_FAILURE_MESSAGE =
"Password %s failed validation: \"%s\". Please re-try with a minimum %d character password and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character that is strong. Password strength can be tested here: https://lowe.github.io/tryzxcvbn";

private static SecuritySettingsConfigurer securitySettingsConfigurer;

private static Installer installer;
Expand Down Expand Up @@ -130,7 +133,8 @@ public void testUpdateAdminPasswordWithWeakPassword() throws NoSuchFieldExceptio

verifyStdOutContainsString(
String.format(
"Password weakpassword failed validation: \"%s\". Please re-try with a minimum %d character password and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character that is strong. Password strength can be tested here: https://lowe.github.io/tryzxcvbn",
PASSWORD_VALIDATION_FAILURE_MESSAGE,
"weakpassword",
INVALID_PASSWORD_INVALID_REGEX.message(),
DEFAULT_PASSWORD_MIN_LENGTH
)
Expand All @@ -151,11 +155,7 @@ public void testUpdateAdminPasswordWithShortPassword() throws NoSuchFieldExcepti
}

verifyStdOutContainsString(
String.format(
"Password short failed validation: \"%s\". Please re-try with a minimum %d character password and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character that is strong. Password strength can be tested here: https://lowe.github.io/tryzxcvbn",
INVALID_PASSWORD_TOO_SHORT.message(),
DEFAULT_PASSWORD_MIN_LENGTH
)
String.format(PASSWORD_VALIDATION_FAILURE_MESSAGE, "short", INVALID_PASSWORD_TOO_SHORT.message(), DEFAULT_PASSWORD_MIN_LENGTH)
);
}

Expand Down

0 comments on commit ae6177a

Please sign in to comment.