mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Authn: Standardize errors (#74012)
This commit is contained in:
parent
127473f4a4
commit
37ceffb74c
@ -12,10 +12,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
errEmptyPassword = errutil.Unauthorized("password-auth.empty", errutil.WithPublicMessage("Invalid username or password"))
|
||||
errPasswordAuthFailed = errutil.Unauthorized("password-auth.failed", errutil.WithPublicMessage("Invalid username or password"))
|
||||
errInvalidPassword = errutil.Unauthorized("password-auth.invalid", errutil.WithPublicMessage("Invalid password or username"))
|
||||
errLoginAttemptBlocked = errutil.Unauthorized("login-attempt.blocked", errutil.WithPublicMessage("Invalid username or password"))
|
||||
errInvalidPassword = errutil.Unauthorized("password-auth.invalid", errutil.WithPublicMessage("Invalid password or username"))
|
||||
errPasswordAuthFailed = errutil.Unauthorized("password-auth.failed", errutil.WithPublicMessage("Invalid username or password"))
|
||||
)
|
||||
|
||||
var _ authn.PasswordClient = new(Password)
|
||||
@ -38,11 +36,11 @@ func (c *Password) AuthenticatePassword(ctx context.Context, r *authn.Request, u
|
||||
return nil, err
|
||||
}
|
||||
if !ok {
|
||||
return nil, errLoginAttemptBlocked.Errorf("too many consecutive incorrect login attempts for user - login for user temporarily blocked")
|
||||
return nil, errPasswordAuthFailed.Errorf("too many consecutive incorrect login attempts for user - login for user temporarily blocked")
|
||||
}
|
||||
|
||||
if len(password) == 0 {
|
||||
return nil, errEmptyPassword.Errorf("no password provided")
|
||||
return nil, errPasswordAuthFailed.Errorf("no password provided")
|
||||
}
|
||||
|
||||
var clientErrs error
|
||||
|
@ -45,7 +45,7 @@ func TestPassword_AuthenticatePassword(t *testing.T) {
|
||||
username: "test",
|
||||
password: "",
|
||||
req: &authn.Request{},
|
||||
expectedErr: errEmptyPassword,
|
||||
expectedErr: errPasswordAuthFailed,
|
||||
},
|
||||
{
|
||||
desc: "should if login is blocked by to many attempts",
|
||||
@ -53,7 +53,7 @@ func TestPassword_AuthenticatePassword(t *testing.T) {
|
||||
password: "test",
|
||||
req: &authn.Request{},
|
||||
blockLogin: true,
|
||||
expectedErr: errLoginAttemptBlocked,
|
||||
expectedErr: errPasswordAuthFailed,
|
||||
},
|
||||
{
|
||||
desc: "should fail when not found in any clients",
|
||||
|
Loading…
Reference in New Issue
Block a user