Skip to content

Commit

Permalink
Merge pull request #32 from gin-contrib/update_status_code
Browse files Browse the repository at this point in the history
change status code for invalid key to unauthorized
  • Loading branch information
ductm54 authored Dec 28, 2022
2 parents 0c33f40 + f8cd474 commit a3fb6bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (a *Authenticator) Authenticated() gin.HandlerFunc {

secret, err := a.getSecret(sigHeader.keyID, sigHeader.algorithm)
if err != nil {
if err == ErrInvalidKeyID {
_ = c.AbortWithError(http.StatusUnauthorized, err)
return
}
_ = c.AbortWithError(http.StatusBadRequest, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion authenticator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestAuthenticatedHeaderWrongKey(t *testing.T) {
req.Header.Set(authorizationHeader, sigHeader)
req.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
c := runTest(secrets, requiredHeaders, nil, req)
assert.Equal(t, http.StatusBadRequest, c.Writer.Status())
assert.Equal(t, http.StatusUnauthorized, c.Writer.Status())
assert.Equal(t, ErrInvalidKeyID, c.Errors[0])
}

Expand Down

0 comments on commit a3fb6bb

Please sign in to comment.