codeant-ai-for-open-source[bot] commented on code in PR #43534:
URL: https://github.com/apache/superset/pull/43534#discussion_r3859572070
##########
tests/unit_tests/db_engine_specs/test_trino.py:
##########
@@ -1753,3 +1753,85 @@ def test_unmask_encrypted_extra() -> None:
"auth_params": {"username": "alice", "password": "old-password"},
}
)
+
+
+def test_impersonate_user_non_trino_backend() -> None:
+ """
+ Test impersonate_user for non-Trino backends.
+ """
+ from superset.db_engine_specs.trino import TrinoEngineSpec
+
+ url = make_url("presto://user@host:443/catalog/schema")
+ engine_kwargs: dict[str, Any] = {"connect_args": {}}
+
+ _, new_kwargs = TrinoEngineSpec.impersonate_user(
+ database=MagicMock(),
+ username="alice",
+ user_token=None,
+ url=url,
+ engine_kwargs=engine_kwargs,
+ )
+
+ assert new_kwargs["connect_args"] == {}
+
+
+def test_impersonate_user_without_token() -> None:
+ """
+ Test impersonate_user when there isn't a `user_token`.
+
+ Without a user token only the `user` connect arg is set; no HTTP session is
+ built, so the driver keeps handling `verify` itself.
+ """
+ from superset.db_engine_specs.trino import TrinoEngineSpec
+
+ url = make_url("trino://host:443/catalog/schema")
+ engine_kwargs: dict[str, Any] = {"connect_args": {"verify": False}}
+
+ _, new_kwargs = TrinoEngineSpec.impersonate_user(
+ database=MagicMock(),
+ username="alice",
+ user_token=None,
+ url=url,
+ engine_kwargs=engine_kwargs,
+ )
+
+ assert new_kwargs["connect_args"] == {"user": "alice", "verify": False}
+
+
[email protected](
+ "verify",
+ [None, False, True, "/path/to/ca-bundle.pem"],
+)
+def test_impersonate_user_with_token(verify: Any) -> None:
+ """
+ Test impersonate_user with a `user_token`.
+
+ With a user token an HTTP session carrying the bearer token is injected.
+ """
+ from superset.db_engine_specs.trino import TrinoEngineSpec
+
+ url = make_url("trino://host:443/catalog/schema")
+ connect_args: dict[str, Any] = {}
+ if verify is not None:
+ connect_args["verify"] = verify
Review Comment:
**Suggestion:** The `None` parameter is treated as an omitted setting
because this condition prevents `"verify": None` from being inserted into
`connect_args`. Production distinguishes those cases with `if "verify" in
connect_args`, so this test does not exercise the newly added assignment for an
explicit null value and could pass while that case is broken. Add a separate
case that preserves the key with a `None` value and asserts the resulting
session behavior. [incomplete implementation]
<details>
<summary><b>Severity Level:</b> Minor ๐งน</summary>
```mdx
- โ ๏ธ Explicit `verify=None` session behavior lacks regression coverage.
- โ ๏ธ Trino impersonation tests do not cover key-presence semantics.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=cfb491cb428641ce82a603f87bc7a828&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=cfb491cb428641ce82a603f87bc7a828&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** tests/unit_tests/db_engine_specs/test_trino.py
**Line:** 1815:1816
**Comment:**
*Incomplete Implementation: The `None` parameter is treated as an
omitted setting because this condition prevents `"verify": None` from being
inserted into `connect_args`. Production distinguishes those cases with `if
"verify" in connect_args`, so this test does not exercise the newly added
assignment for an explicit null value and could pass while that case is broken.
Add a separate case that preserves the key with a `None` value and asserts the
resulting session behavior.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43534&comment_hash=89ebc47328264a53e578c81396e5620cc291752d249b1859ff2104ae4efeb503&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43534&comment_hash=89ebc47328264a53e578c81396e5620cc291752d249b1859ff2104ae4efeb503&reaction=dislike'>๐</a>
--
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]