Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
slack_importer: Add validation to `check_slack_token_access`.
PieterCK7f45cfccbbff
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.pyindex 1a5cbacd4d3..faa2442b364 100644--- a/zerver/data_import/slack.py+++ b/zerver/data_import/slack.py@@ -1781,6 +1781,8 @@ def get_data_file(path: str) -> Any:def check_slack_token_access(token: str, required_scopes: set[str]) -> None:if token.startswith("xoxp-"):logging.info("This is a Slack user token, which grants all rights the user has!")+ elif not required_scopes:+ raise ValueError("required_scopes shouldn't be empty!")elif token.startswith("xoxb-"):data = requests.get("https://slack.com/api/api.test", headers={"Authorization": f"Bearer {token}"}diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.pyindex 518b7c9ebca..fe506d4c0d9 100644--- a/zerver/tests/test_slack_importer.py+++ b/zerver/tests/test_slack_importer.py@@ -391,6 +391,11 @@ class SlackImporter(ZulipTestCase):"Slack token is missing the following required scopes: ['team:read', 'users:read', 'users:read.email']",)+ self.assertEqual(+ exception_for("xoxb-valid-token", set()),+ "required_scopes shouldn't be empty!",+ )+check_slack_token_access("xoxb-valid-token", required_scopes=SLACK_IMPORT_TOKEN_SCOPES)def test_get_owner(self) -> None: