Authn: Standardize errors (#74012)

This commit is contained in:
Karl Persson 2023-08-29 15:44:04 +02:00 committed by GitHub
parent 127473f4a4
commit 37ceffb74c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -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

View File

@ -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",