Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

slack: Handle the special case of permissions denied on team.info call.

Alex Vandiver21aeb4a04020
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 32185af32d6..83bb14b3152 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1472,7 +1472,8 @@ def check_token_access(token: str) -> None:
)
if not data.json()["ok"]:
error = data.json()["error"]
- raise ValueError(f"Invalid Slack token: {token}, {error}")
+ if error != "missing_scope":
+ raise ValueError(f"Invalid Slack token: {token}, {error}")
has_scopes = set(data.headers.get("x-oauth-scopes", "").split(","))
required_scopes = {"emoji:read", "users:read", "users:read.email", "team:read"}
missing_scopes = required_scopes - has_scopes
diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py
index bb21f18c3f5..2c416be2e66 100644
--- a/zerver/tests/test_slack_importer.py
+++ b/zerver/tests/test_slack_importer.py
@@ -192,10 +192,23 @@ class SlackImporter(ZulipTestCase):
if auth == "Bearer xoxb-invalid-token":
return (200, {}, orjson.dumps({"ok": False, "error": "invalid_auth"}))
- if auth == "Bearer xoxb-limited-scopes":
+ if auth == "Bearer xoxb-very-limited-scopes":
return (
200,
{"x-oauth-scopes": "emoji:read,bogus:scope"},
+ orjson.dumps(
+ {
+ "ok": False,
+ "error": "missing_scope",
+ "needed": "team:read",
+ "provided": "emoji:read,bogus:scope",
+ }
+ ),
+ )
+ if auth == "Bearer xoxb-limited-scopes":
+ return (
+ 200,
+ {"x-oauth-scopes": "team:read,bogus:scope"},
orjson.dumps({"ok": True}),
)
if auth == "Bearer xoxb-valid-token":
@@ -233,6 +246,10 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(
exception_for("xoxb-limited-scopes"),
+ "Slack token is missing the following required scopes: ['emoji:read', 'users:read', 'users:read.email']",
+ )
+ self.assertEqual(
+ exception_for("xoxb-very-limited-scopes"),
"Slack token is missing the following required scopes: ['team:read', 'users:read', 'users:read.email']",
)