Exclude requestor 401 logs

This commit is contained in:
Abhishek Pandey 2024-02-16 18:56:02 -08:00
parent 1afd20b67f
commit ca12138f13
2 changed files with 9 additions and 1 deletions

View File

@ -126,7 +126,13 @@ func getTokenLifetime(
return time.Time{}, time.Time{}, clues.New("nil request")
}
// Don't throw an error if auth header is absent. This is to prevent
// unnecessary noise in the logs for requests served by the http requestor
// client. These requests may be preauthenticated and may not carry auth headers.
rawToken := req.Header.Get("Authorization")
if len(rawToken) == 0 {
return time.Time{}, time.Time{}, nil
}
// Strip the "Bearer " prefix from the token. This prefix is guaranteed to be
// present as per msft docs. But even if it's not, the jwt lib will handle

View File

@ -528,12 +528,14 @@ func (suite *MiddlewareUnitSuite) TestGetTokenLifetime() {
request: nil,
expectErr: assert.Error,
},
// Test that we don't throw an error if auth header is absent.
// This is to prevent unnecessary noise in logs for requestor http client.
{
name: "no authorization header",
request: &http.Request{
Header: http.Header{},
},
expectErr: assert.Error,
expectErr: assert.NoError,
},
{
name: "well formed auth header with token",