codeant-ai-for-open-source[bot] commented on code in PR #41965:
URL: https://github.com/apache/superset/pull/41965#discussion_r3564823903


##########
tests/unit_tests/security/api_test.py:
##########
@@ -66,6 +66,50 @@ def test_csrf_exempt_blueprints_with_api_key(app: Any, 
app_context: None) -> Non
     assert "ApiKeyApi" in {blueprint.name for blueprint in 
csrf._exempt_blueprints}
 
 
+def test_security_api_trailing_slash_handled_consistently(client: Any) -> None:
+    """Regression for #29934: sibling ``/api/v1/security/*`` endpoints handle a
+    misspelled (wrong trailing-slash) URL inconsistently.
+
+    Three routes live under the same ``/api/v1/security/`` prefix but are
+    declared with different slash conventions:
+
+      * ``login``       -> ``@expose("/login")``        (no trailing slash, 
FAB)
+      * ``csrf_token``  -> ``@expose("/csrf_token/")``  (trailing slash, 
Superset)
+      * ``guest_token`` -> ``@expose("/guest_token/")`` (trailing slash, 
Superset)
+
+    Because of that mix, a client that gets the slash "wrong" is treated three
+    different ways by Werkzeug routing:
+
+      * ``POST /api/v1/security/login/``  -> 404 (no redirect for the extra 
slash)
+      * ``GET  /api/v1/security/csrf_token`` -> 308 redirect to the canonical 
URL
+      * ``POST /api/v1/security/guest_token`` -> 308 redirect to the canonical 
URL
+
+    A user hitting one misspelled security URL gets a clean redirect while
+    another gets a hard 404, which is exactly the inconsistency reported in the
+    issue. This asserts the *desired* contract β€” that a trailing-slash
+    misspelling is handled uniformly across the sibling endpoints β€” so it fails
+    (red) on master where the responses diverge, and would pass once the slash
+    conventions are unified. It does not prescribe which uniform behavior is
+    correct (all-redirect or all-404), only that they agree.
+    """
+    # (method, canonical route, misspelled route)
+    misspelled = [
+        ("post", "/api/v1/security/login/"),
+        ("get", "/api/v1/security/csrf_token"),
+        ("post", "/api/v1/security/guest_token"),
+    ]

Review Comment:
   βœ… **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for local variables in test files 
when the project’s type checks are already green and the annotation would add 
low-value noise.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.py`
   
   ---
   πŸ’‘ *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
tests/unit_tests/security/api_test.py:
##########
@@ -66,6 +66,50 @@ def test_csrf_exempt_blueprints_with_api_key(app: Any, 
app_context: None) -> Non
     assert "ApiKeyApi" in {blueprint.name for blueprint in 
csrf._exempt_blueprints}
 
 
+def test_security_api_trailing_slash_handled_consistently(client: Any) -> None:
+    """Regression for #29934: sibling ``/api/v1/security/*`` endpoints handle a
+    misspelled (wrong trailing-slash) URL inconsistently.
+
+    Three routes live under the same ``/api/v1/security/`` prefix but are
+    declared with different slash conventions:
+
+      * ``login``       -> ``@expose("/login")``        (no trailing slash, 
FAB)
+      * ``csrf_token``  -> ``@expose("/csrf_token/")``  (trailing slash, 
Superset)
+      * ``guest_token`` -> ``@expose("/guest_token/")`` (trailing slash, 
Superset)
+
+    Because of that mix, a client that gets the slash "wrong" is treated three
+    different ways by Werkzeug routing:
+
+      * ``POST /api/v1/security/login/``  -> 404 (no redirect for the extra 
slash)
+      * ``GET  /api/v1/security/csrf_token`` -> 308 redirect to the canonical 
URL
+      * ``POST /api/v1/security/guest_token`` -> 308 redirect to the canonical 
URL
+
+    A user hitting one misspelled security URL gets a clean redirect while
+    another gets a hard 404, which is exactly the inconsistency reported in the
+    issue. This asserts the *desired* contract β€” that a trailing-slash
+    misspelling is handled uniformly across the sibling endpoints β€” so it fails
+    (red) on master where the responses diverge, and would pass once the slash
+    conventions are unified. It does not prescribe which uniform behavior is
+    correct (all-redirect or all-404), only that they agree.
+    """
+    # (method, canonical route, misspelled route)
+    misspelled = [
+        ("post", "/api/v1/security/login/"),
+        ("get", "/api/v1/security/csrf_token"),
+        ("post", "/api/v1/security/guest_token"),
+    ]
+    statuses = {}

Review Comment:
   βœ… **Customized review instruction saved!**
   
   **Instruction:**
   > Avoid flagging missing type annotations for throwaway local variables in 
test files when the code is only used within the test body and CI/type-checking 
already passes.
   
   **Applied to:**
     - `**/test/**`
     - `**/tests/**`
     - `**/*test*.<ext>`
   
   ---
   πŸ’‘ *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
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]

Reply via email to