Отвечать 400 и 401 вместо 500 на NUL и невалидный UTF-8 во входных данных
This commit is contained in:
@@ -172,7 +172,13 @@ func TestAuthenticateFailuresLookTheSame(t *testing.T) {
|
||||
}
|
||||
_, wrong := svc.Authenticate(ctx, "alice", pw+"!")
|
||||
_, unknown := svc.Authenticate(ctx, "nobody", pw)
|
||||
for name, err := range map[string]error{"wrong password": wrong, "unknown user": unknown} {
|
||||
// Basic credentials are client bytes: a username the database cannot
|
||||
// even compare must still be a plain credential failure.
|
||||
_, nul := svc.Authenticate(ctx, "a\x00b", pw)
|
||||
_, notUTF8 := svc.Authenticate(ctx, "\xff\xfe", pw)
|
||||
for name, err := range map[string]error{
|
||||
"wrong password": wrong, "unknown user": unknown, "nul username": nul, "invalid utf-8 username": notUTF8,
|
||||
} {
|
||||
if !errors.Is(err, user.ErrInvalidCredentials) || apperr.KindOf(err) != apperr.KindUnauthorized {
|
||||
t.Errorf("%s: err = %v, want ErrInvalidCredentials", name, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user