Skip to content

Commit

Permalink
Fix slackapi#132 by handling requestContext in AWS Lambda payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Oct 29, 2020
1 parent bea7fc7 commit 3f67a08
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/install_all_and_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
script_dir=`dirname $0`
cd ${script_dir}/..
rm -rf ./slack_bolt.egg-info
# The package causes a conflict with moto
pip uninstall python-lambda

test_target="$1"

Expand Down
3 changes: 3 additions & 0 deletions slack_bolt/adapter/aws_lambda/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def handle(self, event, context):
self.logger.debug(f"Incoming event: {event}, context: {context}")

method = event.get("requestContext", {}).get("http", {}).get("method")
if method is None:
method = event.get("requestContext", {}).get("httpMethod")

if method is None:
return not_found()
if method == "GET":
Expand Down
43 changes: 43 additions & 0 deletions tests/adapter_tests/test_aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def event_handler():
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

event = {
"body": body,
"queryStringParameters": {},
"headers": self.build_headers(timestamp, body),
"requestContext": {"httpMethod": "POST"},
"isBase64Encoded": False,
}
response = SlackRequestHandler(app).handle(event, self.context)
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

@mock_lambda
def test_shortcuts(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
Expand Down Expand Up @@ -151,6 +162,17 @@ def shortcut_handler(ack):
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

event = {
"body": body,
"queryStringParameters": {},
"headers": self.build_headers(timestamp, body),
"requestContext": {"httpMethod": "POST"},
"isBase64Encoded": False,
}
response = SlackRequestHandler(app).handle(event, self.context)
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

@mock_lambda
def test_commands(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
Expand Down Expand Up @@ -187,6 +209,17 @@ def command_handler(ack):
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

event = {
"body": body,
"queryStringParameters": {},
"headers": self.build_headers(timestamp, body),
"requestContext": {"httpMethod": "POST"},
"isBase64Encoded": False,
}
response = SlackRequestHandler(app).handle(event, self.context)
assert response["statusCode"] == 200
assert self.mock_received_requests["/auth.test"] == 1

@mock_lambda
def test_lazy_listeners(self):
app = App(client=self.web_client, signing_secret=self.signing_secret,)
Expand Down Expand Up @@ -251,3 +284,13 @@ def test_oauth(self):
}
response = SlackRequestHandler(app).handle(event, self.context)
assert response["statusCode"] == 302

event = {
"body": "",
"queryStringParameters": {},
"headers": {},
"requestContext": {"httpMethod": "GET"},
"isBase64Encoded": False,
}
response = SlackRequestHandler(app).handle(event, self.context)
assert response["statusCode"] == 302

0 comments on commit 3f67a08

Please sign in to comment.