Repository navigation
fix(oauth): evict cached installations for a workspace on save_bot #2090
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,11 @@ | |
| from slack_sdk.oauth.installation_store.sqlite3 import SQLite3InstallationStore | ||
|
|
||
|
|
||
| def build_installation(*, user_id: str, bot_token: str) -> Installation: | ||
| def build_installation(*, user_id: str, bot_token: str, team_id: str = "T111") -> Installation: | ||
| return Installation( | ||
| app_id="A111", | ||
| enterprise_id="E111", | ||
| team_id="T111", | ||
| team_id=team_id, | ||
| user_id=user_id, | ||
| bot_id="B111", | ||
| bot_token=bot_token, | ||
|
|
@@ -170,3 +170,19 @@ def test_save_evicts_stale_installations(self): | |
| store.save(build_installation(user_id="U222", bot_token="xoxb-u222")) | ||
| i = store.find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| self.assertEqual(i.bot_token, "xoxb-u222") | ||
|
|
||
| def test_save_bot_evicts_stale_installations(self): | ||
| base_dir = tempfile.TemporaryDirectory() | ||
| self.addCleanup(base_dir.cleanup) | ||
| file_store = FileInstallationStore(base_dir=base_dir.name, client_id="111.222") | ||
| store = CacheableInstallationStore(file_store) | ||
|
|
||
| store.save(build_installation(user_id="U111", bot_token="xoxb-initial")) | ||
| store.find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| store.save(build_installation(user_id="U111", bot_token="xoxb-other-team", team_id="T1111")) | ||
| store.find_installation(enterprise_id="E111", team_id="T1111", user_id="U111") | ||
|
|
||
| store.save_bot(build_installation(user_id="U111", bot_token="xoxb-refreshed").to_bot()) | ||
| i = store.find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| self.assertEqual(i.bot_token, "xoxb-refreshed") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧪 suggestion (non-blocking): Could we also cache a second workspace (say |
||
| self.assertIn("E111-T1111-U111", store.cached_installations) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,11 @@ | |
| from tests.helpers import async_test | ||
|
|
||
|
|
||
| def build_installation(*, user_id: str, bot_token: str) -> Installation: | ||
| def build_installation(*, user_id: str, bot_token: str, team_id: str = "T111") -> Installation: | ||
| return Installation( | ||
| app_id="A111", | ||
| enterprise_id="E111", | ||
| team_id="T111", | ||
| team_id=team_id, | ||
| user_id=user_id, | ||
| bot_id="B111", | ||
| bot_token=bot_token, | ||
|
|
@@ -122,3 +122,20 @@ async def test_save_evicts_stale_installations(self): | |
| await store.async_save(build_installation(user_id="U222", bot_token="xoxb-u222")) | ||
| i = await store.async_find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| self.assertEqual(i.bot_token, "xoxb-u222") | ||
|
|
||
| @async_test | ||
| async def test_save_bot_evicts_stale_installations(self): | ||
| base_dir = tempfile.TemporaryDirectory() | ||
| self.addCleanup(base_dir.cleanup) | ||
| file_store = FileInstallationStore(base_dir=base_dir.name, client_id="111.222") | ||
| store = AsyncCacheableInstallationStore(file_store) | ||
|
|
||
| await store.async_save(build_installation(user_id="U111", bot_token="xoxb-initial")) | ||
| await store.async_find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| await store.async_save(build_installation(user_id="U111", bot_token="xoxb-other-team", team_id="T1111")) | ||
| await store.async_find_installation(enterprise_id="E111", team_id="T1111", user_id="U111") | ||
|
|
||
| await store.async_save_bot(build_installation(user_id="U111", bot_token="xoxb-refreshed").to_bot()) | ||
| i = await store.async_find_installation(enterprise_id="E111", team_id="T111", user_id="U111") | ||
| self.assertEqual(i.bot_token, "xoxb-refreshed") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧪 suggestion (non-blocking): Same here, a second cached workspace that survives |
||
| self.assertIn("E111-T1111-U111", store.cached_installations) | ||
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.
note: The evict-after-save follow-up from #2051 applies here too: a lookup that lands during this await can cache the old bot again. Fine to keep it for that follow-up and not hold this PR.