From 72476fe7799c95e6bd882f94ff7ffdf3774a4adb Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Sat, 6 Mar 2021 13:14:45 +0900 Subject: [PATCH] Resolve #251 by correcting response headers --- slack_bolt/oauth/async_oauth_flow.py | 1 - slack_bolt/oauth/internals.py | 2 -- slack_bolt/oauth/oauth_flow.py | 1 - tests/adapter_tests/aws/test_aws_chalice.py | 1 - tests/adapter_tests/aws/test_aws_lambda.py | 2 -- tests/adapter_tests/django/test_django.py | 1 - tests/adapter_tests/starlette/test_fastapi.py | 1 - tests/adapter_tests/starlette/test_starlette.py | 1 - tests/slack_bolt/oauth/test_oauth_flow.py | 1 - tests/slack_bolt/oauth/test_oauth_flow_sqlite3.py | 1 - tests/slack_bolt_async/oauth/test_async_oauth_flow.py | 1 - tests/slack_bolt_async/oauth/test_async_oauth_flow_sqlite3.py | 1 - 12 files changed, 14 deletions(-) diff --git a/slack_bolt/oauth/async_oauth_flow.py b/slack_bolt/oauth/async_oauth_flow.py index 3808c1408..ce26c3e03 100644 --- a/slack_bolt/oauth/async_oauth_flow.py +++ b/slack_bolt/oauth/async_oauth_flow.py @@ -172,7 +172,6 @@ async def handle_installation(self, request: AsyncBoltRequest) -> BoltResponse: body=html, headers={ "Content-Type": "text/html; charset=utf-8", - "Content-Length": len(bytes(html, "utf-8")), "Set-Cookie": [set_cookie_value], }, ) diff --git a/slack_bolt/oauth/internals.py b/slack_bolt/oauth/internals.py index e551f682f..39fcd9fcf 100644 --- a/slack_bolt/oauth/internals.py +++ b/slack_bolt/oauth/internals.py @@ -42,7 +42,6 @@ def _build_callback_success_response( # type: ignore status=200, headers={ "Content-Type": "text/html; charset=utf-8", - "Content-Length": len(bytes(html, "utf-8")), "Set-Cookie": self._state_utils.build_set_cookie_for_deletion(), }, body=html, @@ -66,7 +65,6 @@ def _build_callback_failure_response( # type: ignore status=status, headers={ "Content-Type": "text/html; charset=utf-8", - "Content-Length": len(bytes(html, "utf-8")), "Set-Cookie": self._state_utils.build_set_cookie_for_deletion(), }, body=html, diff --git a/slack_bolt/oauth/oauth_flow.py b/slack_bolt/oauth/oauth_flow.py index df03ef452..ccb31c826 100644 --- a/slack_bolt/oauth/oauth_flow.py +++ b/slack_bolt/oauth/oauth_flow.py @@ -167,7 +167,6 @@ def handle_installation(self, request: BoltRequest) -> BoltResponse: body=html, headers={ "Content-Type": "text/html; charset=utf-8", - "Content-Length": len(bytes(html, "utf-8")), "Set-Cookie": [set_cookie_value], }, ) diff --git a/tests/adapter_tests/aws/test_aws_chalice.py b/tests/adapter_tests/aws/test_aws_chalice.py index bf65601d0..ad9263550 100644 --- a/tests/adapter_tests/aws/test_aws_chalice.py +++ b/tests/adapter_tests/aws/test_aws_chalice.py @@ -288,5 +288,4 @@ def install() -> Response: ) assert response["statusCode"] == 200 assert response["headers"]["content-type"] == "text/html; charset=utf-8" - assert response["headers"]["content-length"] == "565" assert "https://slack.com/oauth/v2/authorize?state=" in response.get("body") diff --git a/tests/adapter_tests/aws/test_aws_lambda.py b/tests/adapter_tests/aws/test_aws_lambda.py index 4c6a1bb14..99000094d 100644 --- a/tests/adapter_tests/aws/test_aws_lambda.py +++ b/tests/adapter_tests/aws/test_aws_lambda.py @@ -305,7 +305,6 @@ def test_oauth(self): response = SlackRequestHandler(app).handle(event, self.context) assert response["statusCode"] == 200 assert response["headers"]["content-type"] == "text/html; charset=utf-8" - assert response["headers"]["content-length"] == "565" assert response.get("body") is not None event = { @@ -318,5 +317,4 @@ def test_oauth(self): response = SlackRequestHandler(app).handle(event, self.context) assert response["statusCode"] == 200 assert response["headers"]["content-type"] == "text/html; charset=utf-8" - assert response["headers"]["content-length"] == "565" assert "https://slack.com/oauth/v2/authorize?state=" in response.get("body") diff --git a/tests/adapter_tests/django/test_django.py b/tests/adapter_tests/django/test_django.py index c8254c52c..f387427a9 100644 --- a/tests/adapter_tests/django/test_django.py +++ b/tests/adapter_tests/django/test_django.py @@ -188,7 +188,6 @@ def test_oauth(self): response = SlackRequestHandler(app).handle(request) assert response.status_code == 200 assert response.get("content-type") == "text/html; charset=utf-8" - assert response.get("content-length") == "565" assert "https://slack.com/oauth/v2/authorize?state=" in response.content.decode( "utf-8" ) diff --git a/tests/adapter_tests/starlette/test_fastapi.py b/tests/adapter_tests/starlette/test_fastapi.py index 29282bc24..4b09c618a 100644 --- a/tests/adapter_tests/starlette/test_fastapi.py +++ b/tests/adapter_tests/starlette/test_fastapi.py @@ -213,5 +213,4 @@ async def endpoint(req: Request): response = client.get("/slack/install", allow_redirects=False) assert response.status_code == 200 assert response.headers.get("content-type") == "text/html; charset=utf-8" - assert response.headers.get("content-length") == "565" assert "https://slack.com/oauth/v2/authorize?state=" in response.text diff --git a/tests/adapter_tests/starlette/test_starlette.py b/tests/adapter_tests/starlette/test_starlette.py index 033d80f51..43b42cfbf 100644 --- a/tests/adapter_tests/starlette/test_starlette.py +++ b/tests/adapter_tests/starlette/test_starlette.py @@ -222,5 +222,4 @@ async def endpoint(req: Request): response = client.get("/slack/install", allow_redirects=False) assert response.status_code == 200 assert response.headers.get("content-type") == "text/html; charset=utf-8" - assert response.headers.get("content-length") == "565" assert "https://slack.com/oauth/v2/authorize?state=" in response.text diff --git a/tests/slack_bolt/oauth/test_oauth_flow.py b/tests/slack_bolt/oauth/test_oauth_flow.py index 9be907b66..a43db0b5f 100644 --- a/tests/slack_bolt/oauth/test_oauth_flow.py +++ b/tests/slack_bolt/oauth/test_oauth_flow.py @@ -56,7 +56,6 @@ def test_handle_installation_default(self): resp = oauth_flow.handle_installation(req) assert resp.status == 200 assert resp.headers.get("content-type") == ["text/html; charset=utf-8"] - assert resp.headers.get("content-length") == ["576"] assert "https://slack.com/oauth/v2/authorize?state=" in resp.body # https://github.com/slackapi/bolt-python/issues/183 diff --git a/tests/slack_bolt/oauth/test_oauth_flow_sqlite3.py b/tests/slack_bolt/oauth/test_oauth_flow_sqlite3.py index 00b3ad12b..26c54df15 100644 --- a/tests/slack_bolt/oauth/test_oauth_flow_sqlite3.py +++ b/tests/slack_bolt/oauth/test_oauth_flow_sqlite3.py @@ -41,7 +41,6 @@ def test_handle_installation(self): resp = oauth_flow.handle_installation(req) assert resp.status == 200 assert resp.headers.get("content-type") == ["text/html; charset=utf-8"] - assert resp.headers.get("content-length") == ["565"] assert "https://slack.com/oauth/v2/authorize?state=" in resp.body def test_handle_callback(self): diff --git a/tests/slack_bolt_async/oauth/test_async_oauth_flow.py b/tests/slack_bolt_async/oauth/test_async_oauth_flow.py index 2aecaf424..eea474b87 100644 --- a/tests/slack_bolt_async/oauth/test_async_oauth_flow.py +++ b/tests/slack_bolt_async/oauth/test_async_oauth_flow.py @@ -107,7 +107,6 @@ async def test_handle_installation_default(self): resp = await oauth_flow.handle_installation(req) assert resp.status == 200 assert resp.headers.get("content-type") == ["text/html; charset=utf-8"] - assert resp.headers.get("content-length") == ["565"] assert "https://slack.com/oauth/v2/authorize?state=" in resp.body @pytest.mark.asyncio diff --git a/tests/slack_bolt_async/oauth/test_async_oauth_flow_sqlite3.py b/tests/slack_bolt_async/oauth/test_async_oauth_flow_sqlite3.py index afd3cbdac..c9190ff55 100644 --- a/tests/slack_bolt_async/oauth/test_async_oauth_flow_sqlite3.py +++ b/tests/slack_bolt_async/oauth/test_async_oauth_flow_sqlite3.py @@ -55,7 +55,6 @@ async def test_handle_installation(self): resp = await oauth_flow.handle_installation(req) assert resp.status == 200 assert resp.headers.get("content-type") == ["text/html; charset=utf-8"] - assert resp.headers.get("content-length") == ["565"] assert "https://slack.com/oauth/v2/authorize?state=" in resp.body @pytest.mark.asyncio