Repository navigation
Fix #330 Potentially request.body can be None when using a custom adapter #331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import asyncio | ||
|
|
||
| import pytest | ||
| from slack_sdk.web.async_client import AsyncWebClient | ||
|
|
||
| from slack_bolt.app.async_app import AsyncApp | ||
| from slack_bolt.request.async_request import AsyncBoltRequest | ||
| from tests.mock_web_api_server import ( | ||
| setup_mock_web_api_server, | ||
| cleanup_mock_web_api_server, | ||
| ) | ||
| from tests.utils import remove_os_env_temporarily, restore_os_env | ||
|
|
||
|
|
||
| class TestAsyncAppDispatch: | ||
| signing_secret = "secret" | ||
| valid_token = "xoxb-valid" | ||
| mock_api_server_base_url = "http://localhost:8888" | ||
| web_client = AsyncWebClient(token=valid_token, base_url=mock_api_server_base_url) | ||
|
|
||
| @pytest.fixture | ||
| def event_loop(self): | ||
| old_os_env = remove_os_env_temporarily() | ||
| try: | ||
| setup_mock_web_api_server(self) | ||
| loop = asyncio.get_event_loop() | ||
| yield loop | ||
| loop.close() | ||
| cleanup_mock_web_api_server(self) | ||
| finally: | ||
| restore_os_env(old_os_env) | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_none_body(self): | ||
| app = AsyncApp( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ) | ||
|
|
||
| req = AsyncBoltRequest(body=None, headers={}, mode="http") | ||
| response = await app.async_dispatch(req) | ||
| # request verification failure | ||
| assert response.status == 401 | ||
| assert response.body == '{"error": "invalid request"}' | ||
|
|
||
| req = AsyncBoltRequest(body=None, headers={}, mode="socket_mode") | ||
| response = await app.async_dispatch(req) | ||
| # request verification is skipped for Socket Mode | ||
| assert response.status == 404 | ||
| assert response.body == '{"error": "unhandled request"}' | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_none_body_no_middleware(self): | ||
| app = AsyncApp( | ||
| client=self.web_client, | ||
| signing_secret=self.signing_secret, | ||
| ssl_check_enabled=False, | ||
| ignoring_self_events_enabled=False, | ||
| request_verification_enabled=False, | ||
| # token_verification_enabled=False, | ||
| url_verification_enabled=False, | ||
| ) | ||
|
|
||
| req = AsyncBoltRequest(body=None, headers={}, mode="http") | ||
| response = await app.async_dispatch(req) | ||
| assert response.status == 404 | ||
| assert response.body == '{"error": "unhandled request"}' | ||
|
|
||
| req = AsyncBoltRequest(body=None, headers={}, mode="socket_mode") | ||
| response = await app.async_dispatch(req) | ||
| assert response.status == 404 | ||
| assert response.body == '{"error": "unhandled request"}' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from slack_bolt.request.request import BoltRequest | ||
|
|
||
|
|
||
| class TestRequest: | ||
| def setup_method(self): | ||
| pass | ||
|
|
||
| def teardown_method(self): | ||
| pass | ||
|
|
||
| def test_all_none_inputs_http(self): | ||
| req = BoltRequest(body=None, headers=None, query=None, context=None) | ||
| assert req is not None | ||
| assert req.raw_body == "" | ||
| assert req.body == {} | ||
|
|
||
| def test_all_none_inputs_socket_mode(self): | ||
| req = BoltRequest( | ||
| body=None, headers=None, query=None, context=None, mode="socket_mode" | ||
| ) | ||
| assert req is not None | ||
| assert req.raw_body == "" | ||
| assert req.body == {} |
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import pytest | ||
|
|
||
| from slack_bolt.request.async_request import AsyncBoltRequest | ||
|
|
||
|
|
||
| class TestAsyncRequest: | ||
| @pytest.mark.asyncio | ||
| async def test_all_none_values_http(self): | ||
| req = AsyncBoltRequest(body=None, headers=None, query=None, context=None) | ||
| assert req is not None | ||
| assert req.raw_body == "" | ||
| assert req.body == {} | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_all_none_values_socket_mode(self): | ||
| req = AsyncBoltRequest( | ||
| body=None, headers=None, query=None, context=None, mode="socket_mode" | ||
| ) | ||
| assert req is not None | ||
| assert req.raw_body == "" | ||
| assert req.body == {} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this error message template as it's in internals source file and I'm sure no code outside this project uses it.