feat: request authorizers with null identitySource should return 401 #1618
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
According to the official Amazon docs, whenever you set a request authorizer with a specific identity source, such as
$request.header.Authorization
, and a request comes WITHOUT this identity source, then API Gateway responds with a 401 Unauthorized error.Motivation and Context
Currently, when doing a request to a function that has an Authorizer attached to it, if the identitySource is not present on the request, then serverless-offline responds with an error 500. I've made the change so it returns a 401 instead.
How Has This Been Tested?
The
request-authorizers
suite of tests have been updated with a new test case perdescribe
block (this change applies to payload format 1.0, 2.0 with simple response, with headers/query params).We previously had a test with description
should fail with an Unauthorized error
.Now, we have TWO tests, one with description
should fail with an Unauthorized error when identity source is explicitly not handled
and another one withshould fail with an Unauthorized error when identity source is not present on the request
.