Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 43 additions & 42 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
name: Run codecov

on:
push:
branches: [main]
pull_request:

jobs:
build:
# Avoiding -latest due to https://github.com/actions/setup-python/issues/162
runs-on: ubuntu-20.04
timeout-minutes: 15
strategy:
matrix:
python-version: ["3.11"]
env:
# default: multiprocessing
# threading is more stable on GitHub Actions
BOLT_PYTHON_MOCK_SERVER_MODE: threading
BOLT_PYTHON_CODECOV_RUNNING: "1"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python setup.py install
pip install -U pip
pip install -e ".[async]"
pip install -e ".[adapter]"
pip install -e ".[testing]"
pip install -e ".[adapter_testing]"
- name: Run all tests for codecov
run: |
pytest --cov=./slack_bolt/ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
# TODO: This CI job hangs as of April 2023
#name: Run codecov
#
#on:
# push:
# branches: [main]
# pull_request:
#
#jobs:
# build:
# # Avoiding -latest due to https://github.com/actions/setup-python/issues/162
# runs-on: ubuntu-20.04
# timeout-minutes: 10
# strategy:
# matrix:
# python-version: ["3.11"]
# env:
# # default: multiprocessing
# # threading is more stable on GitHub Actions
# BOLT_PYTHON_MOCK_SERVER_MODE: threading
# BOLT_PYTHON_CODECOV_RUNNING: "1"
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install dependencies
# run: |
# python setup.py install
# pip install -U pip
# pip install -e ".[async]"
# pip install -e ".[adapter]"
# pip install -e ".[testing]"
# pip install -e ".[adapter_testing]"
# - name: Run all tests for codecov
# run: |
# pytest --cov=./slack_bolt/ --cov-report=xml
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# fail_ci_if_error: true
# verbose: true
20 changes: 19 additions & 1 deletion slack_bolt/authorization/authorize_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class AuthorizeResult(dict):

enterprise_id: Optional[str]
team_id: Optional[str]
team: Optional[str] # since v1.18
url: Optional[str] # since v1.18

bot_id: Optional[str]
bot_user_id: Optional[str]
bot_token: Optional[str]
bot_scopes: Optional[List[str]] # since v1.17

user_id: Optional[str]
user: Optional[str] # since v1.18
user_token: Optional[str]
user_scopes: Optional[List[str]] # since v1.17

Expand All @@ -21,30 +26,38 @@ def __init__(
*,
enterprise_id: Optional[str],
team_id: Optional[str],
team: Optional[str] = None,
url: Optional[str] = None,
# bot
bot_user_id: Optional[str] = None,
bot_id: Optional[str] = None,
bot_token: Optional[str] = None,
bot_scopes: Optional[Union[List[str], str]] = None,
# user
user_id: Optional[str] = None,
user: Optional[str] = None,
user_token: Optional[str] = None,
user_scopes: Optional[Union[List[str], str]] = None,
):
"""
Args:
enterprise_id: Organization ID (Enterprise Grid) starting with `E`
team_id: Workspace ID starting with `T`
team: Workspace name
url: Workspace slack.com URL
bot_user_id: Bot user's User ID starting with either `U` or `W`
bot_id: Bot ID starting with `B`
bot_token: Bot user access token starting with `xoxb-`
bot_scopes: The scopes associated with the bot token
user_id: The request user ID
user: The request user's name
user_token: User access token starting with `xoxp-`
user_scopes: The scopes associated wth the user token
"""
self["enterprise_id"] = self.enterprise_id = enterprise_id
self["team_id"] = self.team_id = team_id
self["team"] = self.team = team
self["url"] = self.url = url
# bot
self["bot_user_id"] = self.bot_user_id = bot_user_id
self["bot_id"] = self.bot_id = bot_id
Expand All @@ -54,6 +67,7 @@ def __init__(
self["bot_scopes"] = self.bot_scopes = bot_scopes # type: ignore
# user
self["user_id"] = self.user_id = user_id
self["user"] = self.user = user
self["user_token"] = self.user_token = user_token
if user_scopes is not None and isinstance(user_scopes, str):
user_scopes = [scope.strip() for scope in user_scopes.split(",")]
Expand All @@ -76,17 +90,21 @@ def from_auth_test_response(
user_id: Optional[str] = ( # type:ignore
auth_test_response.get("user_id") if auth_test_response.get("bot_id") is None else None
)
# Since v1.28, user_id can be set when user_token w/ its auth.test response exists
user_name = auth_test_response.get("user")
if user_id is None and user_auth_test_response is not None:
user_id: Optional[str] = user_auth_test_response.get("user_id") # type:ignore
user_name: Optional[str] = user_auth_test_response.get("user") # type:ignore

return AuthorizeResult(
enterprise_id=auth_test_response.get("enterprise_id"),
team_id=auth_test_response.get("team_id"),
team=auth_test_response.get("team"),
url=auth_test_response.get("url"),
bot_id=auth_test_response.get("bot_id"),
bot_user_id=bot_user_id,
bot_scopes=bot_scopes,
user_id=user_id,
user=user_name,
bot_token=bot_token,
user_token=user_token,
user_scopes=user_scopes,
Expand Down
8 changes: 7 additions & 1 deletion tests/scenario_tests/test_app_actor_user_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def handle_events(context: BoltContext, say: Say):
assert context.authorize_result.user_id == "W99999"
assert context.authorize_result.user_token == "xoxp-valid-actor-based"
assert context.authorize_result.user_scopes == ["search:read", "chat:write"]
assert context.authorize_result.team_id == "T0G9PQBBK"
assert context.authorize_result.team == "Subarachnoid Workspace"
assert context.authorize_result.url == "https://subarachnoid.slack.com/"
say("What's up?")

response = app.dispatch(self.build_request())
Expand Down Expand Up @@ -196,14 +199,17 @@ def handle_events(context: BoltContext, say: Say):
assert context.actor_enterprise_id == "E013Y3SHLAY"
assert context.actor_team_id == "T111111"
assert context.actor_user_id == "W013QGS7BPF"

assert context.authorize_result.bot_id == "BZYBOTHED"
assert context.authorize_result.bot_user_id == "W23456789"
assert context.authorize_result.bot_token == "xoxb-valid-2"
assert context.authorize_result.bot_scopes == ["commands", "chat:write"]
assert context.authorize_result.user == "bot"
assert context.authorize_result.user_id is None
assert context.authorize_result.user_token is None
assert context.authorize_result.user_scopes is None
assert context.authorize_result.team_id == "T0G9PQBBK"
assert context.authorize_result.team == "Subarachnoid Workspace"
assert context.authorize_result.url == "https://subarachnoid.slack.com/"
say("What's up?")

response = app.dispatch(self.build_request(team_id="T111111"))
Expand Down
3 changes: 3 additions & 0 deletions tests/scenario_tests/test_app_installation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def handle_app_mention(context: BoltContext, say: Say):
assert context.authorize_result.user_id == "W99999"
assert context.authorize_result.user_token == "xoxp-valid"
assert context.authorize_result.user_scopes == ["search:read"]
assert context.authorize_result.team_id == "T0G9PQBBK"
assert context.authorize_result.team == "Subarachnoid Workspace"
assert context.authorize_result.url == "https://subarachnoid.slack.com/"
say("What's up?")

response = app.dispatch(self.build_app_mention_request())
Expand Down
3 changes: 3 additions & 0 deletions tests/scenario_tests_async/test_app_actor_user_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ async def handle_events(context: AsyncBoltContext, say: AsyncSay):
assert context.authorize_result.user_id == "W99999"
assert context.authorize_result.user_token == "xoxp-valid-actor-based"
assert context.authorize_result.user_scopes == ["search:read", "chat:write"]
assert context.authorize_result.team_id == "T0G9PQBBK"
assert context.authorize_result.team == "Subarachnoid Workspace"
assert context.authorize_result.url == "https://subarachnoid.slack.com/"
await say("What's up?")

request = self.build_request()
Expand Down
3 changes: 3 additions & 0 deletions tests/scenario_tests_async/test_app_installation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ async def handle_app_mention(context: AsyncBoltContext, say: AsyncSay):
assert context.authorize_result.user_id == "W99999"
assert context.authorize_result.user_token == "xoxp-valid"
assert context.authorize_result.user_scopes == ["search:read"]
assert context.authorize_result.team_id == "T0G9PQBBK"
assert context.authorize_result.team == "Subarachnoid Workspace"
assert context.authorize_result.url == "https://subarachnoid.slack.com/"
await say("What's up?")

request = self.build_valid_app_mention_request()
Expand Down
Loading