From a7fbe3c6dc88ed8190cb8559ada72b3112225324 Mon Sep 17 00:00:00 2001 From: linoman <2051016+linoman@users.noreply.github.com> Date: Tue, 27 Feb 2024 10:34:43 -0600 Subject: [PATCH] Password Policy: Update frontend facing messages (#83227) * update tests * update error messages --- pkg/services/user/password.go | 10 +++++----- pkg/services/user/password_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/services/user/password.go b/pkg/services/user/password.go index 915d42733a5..70e0e131e58 100644 --- a/pkg/services/user/password.go +++ b/pkg/services/user/password.go @@ -8,8 +8,8 @@ import ( ) var ( - ErrPasswordTooShort = errutil.NewBase(errutil.StatusBadRequest, "password-policy-too-short", errutil.WithPublicMessage("New password is too short")) - ErrPasswordPolicyInfringe = errutil.NewBase(errutil.StatusBadRequest, "password-policy-infringe", errutil.WithPublicMessage("New password doesn't comply with the password policy")) + ErrPasswordTooShort = errutil.BadRequest("password.password-policy-too-short", errutil.WithPublicMessage("New password is too short")) + ErrPasswordPolicyInfringe = errutil.BadRequest("password.password-policy-infringe", errutil.WithPublicMessage("New password doesn't comply with the password policy")) MinPasswordLength = 12 ) @@ -33,12 +33,12 @@ func (p Password) Validate(config *setting.Cfg) error { func ValidatePassword(newPassword string, config *setting.Cfg) error { if !config.BasicAuthStrongPasswordPolicy { if len(newPassword) <= 4 { - return ErrPasswordTooShort + return ErrPasswordTooShort.Errorf("new password is too short") } return nil } if len(newPassword) < MinPasswordLength { - return ErrPasswordTooShort + return ErrPasswordPolicyInfringe.Errorf("new password is too short for the strong password policy") } hasUpperCase := false @@ -67,5 +67,5 @@ func ValidatePassword(newPassword string, config *setting.Cfg) error { return nil } } - return ErrPasswordPolicyInfringe + return ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy") } diff --git a/pkg/services/user/password_test.go b/pkg/services/user/password_test.go index 8f8235fae13..1953d1a1529 100644 --- a/pkg/services/user/password_test.go +++ b/pkg/services/user/password_test.go @@ -21,7 +21,7 @@ func TestPasswowrdService_ValidatePasswordHardcodePolicy(t *testing.T) { { name: "should return error when the password has less than 4 characters and strong password policy is disabled", passwordTest: NUMBER, - expectedError: ErrPasswordTooShort, + expectedError: ErrPasswordTooShort.Errorf("new password is too short"), strongPasswordPolicyEnabled: false, }, {name: "should not return error when the password has 4 characters and strong password policy is disabled", @@ -32,31 +32,31 @@ func TestPasswowrdService_ValidatePasswordHardcodePolicy(t *testing.T) { { name: "should return error when the password has less than 12 characters and strong password policy is enabled", passwordTest: NUMBER, - expectedError: ErrPasswordTooShort, + expectedError: ErrPasswordPolicyInfringe.Errorf("new password is too short for the strong password policy"), strongPasswordPolicyEnabled: true, }, { name: "should return error when the password is missing an uppercase character and strong password policy is enabled", passwordTest: LOWERCASE + NUMBER + SYMBOLS, - expectedError: ErrPasswordPolicyInfringe, + expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"), strongPasswordPolicyEnabled: true, }, { name: "should return error when the password is missing a lowercase character and strong password policy is enabled", passwordTest: UPPERCASE + NUMBER + SYMBOLS, - expectedError: ErrPasswordPolicyInfringe, + expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"), strongPasswordPolicyEnabled: true, }, { name: "should return error when the password is missing a number character and strong password policy is enabled", passwordTest: LOWERCASE + UPPERCASE + SYMBOLS, - expectedError: ErrPasswordPolicyInfringe, + expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"), strongPasswordPolicyEnabled: true, }, { name: "should return error when the password is missing a symbol characters and strong password policy is enabled", passwordTest: LOWERCASE + UPPERCASE + NUMBER, - expectedError: ErrPasswordPolicyInfringe, + expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"), strongPasswordPolicyEnabled: true, }, {