mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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 (
|
var (
|
||||||
ErrPasswordTooShort = errutil.NewBase(errutil.StatusBadRequest, "password-policy-too-short", errutil.WithPublicMessage("New password is too short"))
|
ErrPasswordTooShort = errutil.BadRequest("password.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"))
|
ErrPasswordPolicyInfringe = errutil.BadRequest("password.password-policy-infringe", errutil.WithPublicMessage("New password doesn't comply with the password policy"))
|
||||||
MinPasswordLength = 12
|
MinPasswordLength = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,12 +33,12 @@ func (p Password) Validate(config *setting.Cfg) error {
|
|||||||
func ValidatePassword(newPassword string, config *setting.Cfg) error {
|
func ValidatePassword(newPassword string, config *setting.Cfg) error {
|
||||||
if !config.BasicAuthStrongPasswordPolicy {
|
if !config.BasicAuthStrongPasswordPolicy {
|
||||||
if len(newPassword) <= 4 {
|
if len(newPassword) <= 4 {
|
||||||
return ErrPasswordTooShort
|
return ErrPasswordTooShort.Errorf("new password is too short")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(newPassword) < MinPasswordLength {
|
if len(newPassword) < MinPasswordLength {
|
||||||
return ErrPasswordTooShort
|
return ErrPasswordPolicyInfringe.Errorf("new password is too short for the strong password policy")
|
||||||
}
|
}
|
||||||
|
|
||||||
hasUpperCase := false
|
hasUpperCase := false
|
||||||
@ -67,5 +67,5 @@ func ValidatePassword(newPassword string, config *setting.Cfg) error {
|
|||||||
return nil
|
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",
|
name: "should return error when the password has less than 4 characters and strong password policy is disabled",
|
||||||
passwordTest: NUMBER,
|
passwordTest: NUMBER,
|
||||||
expectedError: ErrPasswordTooShort,
|
expectedError: ErrPasswordTooShort.Errorf("new password is too short"),
|
||||||
strongPasswordPolicyEnabled: false,
|
strongPasswordPolicyEnabled: false,
|
||||||
},
|
},
|
||||||
{name: "should not return error when the password has 4 characters and strong password policy is disabled",
|
{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",
|
name: "should return error when the password has less than 12 characters and strong password policy is enabled",
|
||||||
passwordTest: NUMBER,
|
passwordTest: NUMBER,
|
||||||
expectedError: ErrPasswordTooShort,
|
expectedError: ErrPasswordPolicyInfringe.Errorf("new password is too short for the strong password policy"),
|
||||||
strongPasswordPolicyEnabled: true,
|
strongPasswordPolicyEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "should return error when the password is missing an uppercase character and strong password policy is enabled",
|
name: "should return error when the password is missing an uppercase character and strong password policy is enabled",
|
||||||
passwordTest: LOWERCASE + NUMBER + SYMBOLS,
|
passwordTest: LOWERCASE + NUMBER + SYMBOLS,
|
||||||
expectedError: ErrPasswordPolicyInfringe,
|
expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"),
|
||||||
strongPasswordPolicyEnabled: true,
|
strongPasswordPolicyEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "should return error when the password is missing a lowercase character and strong password policy is enabled",
|
name: "should return error when the password is missing a lowercase character and strong password policy is enabled",
|
||||||
passwordTest: UPPERCASE + NUMBER + SYMBOLS,
|
passwordTest: UPPERCASE + NUMBER + SYMBOLS,
|
||||||
expectedError: ErrPasswordPolicyInfringe,
|
expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"),
|
||||||
strongPasswordPolicyEnabled: true,
|
strongPasswordPolicyEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "should return error when the password is missing a number character and strong password policy is enabled",
|
name: "should return error when the password is missing a number character and strong password policy is enabled",
|
||||||
passwordTest: LOWERCASE + UPPERCASE + SYMBOLS,
|
passwordTest: LOWERCASE + UPPERCASE + SYMBOLS,
|
||||||
expectedError: ErrPasswordPolicyInfringe,
|
expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"),
|
||||||
strongPasswordPolicyEnabled: true,
|
strongPasswordPolicyEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "should return error when the password is missing a symbol characters and strong password policy is enabled",
|
name: "should return error when the password is missing a symbol characters and strong password policy is enabled",
|
||||||
passwordTest: LOWERCASE + UPPERCASE + NUMBER,
|
passwordTest: LOWERCASE + UPPERCASE + NUMBER,
|
||||||
expectedError: ErrPasswordPolicyInfringe,
|
expectedError: ErrPasswordPolicyInfringe.Errorf("new password doesn't comply with the password policy"),
|
||||||
strongPasswordPolicyEnabled: true,
|
strongPasswordPolicyEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user