Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce header to override authorizer response #1328

Merged
merged 2 commits into from Feb 3, 2022

Conversation

ericctsf
Copy link
Contributor

@ericctsf ericctsf commented Feb 2, 2022

Description

This PR allows developers to mock AWS_IAM authorizer (and other authorizers) by providing the mock data independently for each REST/HTTP API call by adding the SLS_OFFLINE_AUTHORIZER_OVERRIDE http header.

Motivation and Context

serverless offline does not support AWS_IAM as an authorizer, but this is a common deployment architecture especially when using cognito identity pools.

It was already possible to 'mock' the authorizer by providing a JSON object in process.env.AUTHORIZER, but this does not allow developers to run a test suite with different auth states against a single instance of serverless offline.

This PR allows developers to more fully test their gateway and lambda implementations against a single instance of serverless offline.

How Has This Been Tested?

This PR includes additional integration tests demonstrating the behaviour with and without the inclusion of the SLS_OFFLINE_AUTHORIZER_OVERRIDE header.

Screenshots (if appropriate):

Added a http header SLS_OFFLINE_AUTHORISER_OVERRIDE which behaves like
the AUTHORIZER environment variable but allows for testing many handler behaviours in a single serverless offline run by changing the authorizer value on each request
Copy link
Collaborator

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR itself looks okay, I have some small suggestions and there seem to be some checks failing - could you look into that?

README.md Outdated Show resolved Hide resolved
SLS_OFFLINE_AUTHORIZER_OVERRIDE ==> sls-offline-authorizer-override
and run prettier on readme
Copy link
Collaborator

@pgrzesik pgrzesik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks @ericctsf

@pgrzesik pgrzesik changed the title Authorizer override header feat: Introduce header to override authorizer response Feb 3, 2022
@pgrzesik pgrzesik merged commit a5158a4 into dherault:master Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants