Repository navigation
fix(aws_lambda): handle null headers, query string, and body in API Gateway events - #1587
Open
sahiljagtap08 wants to merge 1 commit into
Open
sahiljagtap08 wants to merge 1 commit into
sahiljagtap08 wants to merge 1 commit into
Conversation
…ateway events API Gateway sends null, not a missing key, for request fields that have no value. For example "headers", "multiValueHeaders" and "queryStringParameters" are null when the request has none of them. The Lambda adapter assumed these were always dicts and raised AttributeError before the request was dispatched. It also raised KeyError when "isBase64Encoded" was absent, and TypeError when the flag was true but the body was null. - Treat None the same as a missing key for every event field - Copy the headers dict so the caller's event is not modified - Add tests for null fields, a missing base64 flag, and a real base64-encoded body
|
Thanks for the contribution! Before we can merge this, we need @sahiljagtap08 to sign the Salesforce Inc. Contributor License Agreement. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
API Gateway sends
null, not a missing key, for request fields that have no value. For a REST API (payload format v1)headers,multiValueHeaders, andqueryStringParametersare allnullwhen the request has none of them. The AWS Lambda adapter assumed these were always dicts and raisedAttributeErrorinsideto_bolt_request, before the request reached the middleware chain.Two related edge cases were fixed at the same time:
isBase64Encodedmissing from the event raisedKeyError. This happens when the function is invoked by test tooling or a custom integration that does not set the flag.isBase64Encoded: truewith anullbody raisedTypeErrorfrombase64.b64decode.Changes in
slack_bolt/adapter/aws_lambda/handler.py:Nonethe same as a missing key.trueand a body is present.Testing
New tests in
tests/adapter_tests/aws/test_aws_lambda.py:test_null_fields_in_api_gateway_event: nullheaders,multiValueHeaders, andqueryStringParametersnow produce a 401 (no signature) instead of a crash, and the original event is not modified.test_missing_is_base64_encoded_and_null_body: covers the missing flag and the null body with the flag set.test_base64_encoded_body: a properly signed base64-encoded body is decoded and handled with a 200.Both crash tests fail on
mainand pass with this change. Ran./scripts/format.sh,./scripts/lint.sh,./scripts/run_mypy.sh, and the adapter test suite.Category
Requirements
./scripts/install_all_and_run_tests.shafter making the changes.