bito-code-review[bot] commented on code in PR #40653:
URL: https://github.com/apache/superset/pull/40653#discussion_r3343631816
##########
tests/unit_tests/mcp_service/test_auth_rbac.py:
##########
@@ -343,3 +343,105 @@ def
test_visibility_data_model_metadata_allowed(app_context) -> None:
result = is_tool_visible_to_current_user(tool)
assert result is True
+
+
+# -- Scope-aware authorization (intersection of token scopes and RBAC) --
+
+
+def _patch_token_scopes(scopes):
+ """Patch the JWT access-token lookup used by ``_get_token_scopes``.
+
+ ``scopes=None`` simulates no JWT context / no token; a list simulates a
+ token that advertises those scopes; an empty list simulates a token with
+ no scopes (treated as scope-less -> RBAC-only).
+ """
+ if scopes is None:
+ token = None
+ else:
+ token = MagicMock()
+ token.scopes = scopes
+ return patch(
+ "fastmcp.server.dependencies.get_access_token",
+ return_value=token,
+ )
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Test helper misplaced in test file</b></div>
<div id="fix">
Helper function `_patch_token_scopes` is defined in the middle of the test
file after all tests that use it have already been declared. While Python
resolves function names at runtime (not positionally), placing a helper between
test sections creates a maintenance hazard: any future test inserted between
the section comment and the function body will fail with a NameError. This also
breaks the established pattern where both `_make_tool_func` (line 62) and
`_make_mock_tool` (line 232) are defined in a contiguous block before any test
sections begin.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
--- a/tests/unit_tests/mcp_service/test_auth_rbac.py
+++ b/tests/unit_tests/mcp_service/test_auth_rbac.py
@@ -244,6 +244,23 @@ def _make_mock_tool(
return tool
+def _patch_token_scopes(scopes):
+ """Patch the JWT access-token lookup used by ``_get_token_scopes``.
+
+ ``scopes=None`` simulates no JWT context / no token; a list simulates a
+ token that advertises those scopes; an empty list simulates a token
with
+ no scopes (treated as scope-less -> RBAC-only).
+ """
+ if scopes is None:
+ token = None
+ else:
+ token = MagicMock()
+ token.scopes = scopes
+ return patch(
+ "fastmcp.server.dependencies.get_access_token",
+ return_value=token,
+ )
+
# -- is_tool_visible_to_current_user --
@@ -347,23 +330,6 @@ def
test_visibility_data_model_metadata_allowed(app_context) -> None:
assert result is True
-# -- Scope-aware authorization (intersection of token scopes and RBAC) --
-
-
-def _patch_token_scopes(scopes):
- """Patch the JWT access-token lookup used by ``_get_token_scopes``.
-
- ``scopes=None`` simulates no JWT context / no token; a list simulates a
- token that advertises those scopes; an empty list simulates a token
with
- no scopes (treated as scope-less -> RBAC-only).
- """
- if scopes is None:
- token = None
- else:
- token = MagicMock()
- token.scopes = scopes
- return patch(
- "fastmcp.server.dependencies.get_access_token",
- return_value=token,
- )
-
def test_scope_denies_when_token_lacks_required_scope(app_context) -> None:
```
</div>
</details>
</div>
<small><i>Code Review Run #2e13f4</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]