mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
Password Policy: Update frontend facing messages (#83227)
* update tests * update error messages
This commit is contained in:
parent
fc29182f16
commit
a7fbe3c6dc
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user