bito-code-review[bot] commented on code in PR #44453:
URL: https://github.com/apache/superset/pull/44453#discussion_r4068272256
##########
tests/unit_tests/db_engine_specs/test_bigquery.py:
##########
@@ -1134,3 +1138,593 @@ def test_identifier_quote_uses_backticks() -> None:
"end": "`",
"escape_by_doubling": False,
}
+
+
+# --- OAuth2 / per-user impersonation --------------------------------------
+
+
+def test_oauth2_class_attributes() -> None:
+ """
+ The spec advertises OAuth2 with Google endpoints and offline access.
+ """
+ from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+ assert BigQueryEngineSpec.supports_oauth2 is True
+ assert BigQueryEngineSpec.oauth2_scope ==
"https://www.googleapis.com/auth/bigquery"
+ assert BigQueryEngineSpec.oauth2_authorization_request_uri == (
+ "https://accounts.google.com/o/oauth2/v2/auth"
+ )
+ assert BigQueryEngineSpec.oauth2_token_request_uri == (
+ "https://oauth2.googleapis.com/token" # noqa: S105
+ )
+ assert BigQueryEngineSpec.oauth2_additional_auth_uri_query_params == {
+ "access_type": "offline",
+ "include_granted_scopes": "false",
+ "prompt": "consent",
+ }
+ assert (
+ BigQueryEngineSpec.encrypted_extra_sensitive_fields[
+ "$.oauth2_client_info.secret"
+ ]
+ == "OAuth2 Client Secret"
+ )
+
+
+def test_get_oauth2_authorization_uri_includes_google_params(
+ mocker: MockerFixture,
+) -> None:
+ """
+ Google needs offline access and an explicit consent prompt to issue a
+ refresh token.
+ """
+ from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+ mocker.patch(
+ "superset.db_engine_specs.base.encode_oauth2_state",
+ return_value="STATE",
+ )
+ config: Any = {
+ "id": "XXX.apps.googleusercontent.com",
+ "secret": "GOCSPX-YYY",
+ "scope": "https://www.googleapis.com/auth/bigquery",
+ "redirect_uri": "http://localhost:8088/api/v1/database/oauth2/",
+ "authorization_request_uri":
"https://accounts.google.com/o/oauth2/v2/auth",
+ "token_request_uri": "https://oauth2.googleapis.com/token",
+ "request_content_type": "data",
+ }
+ state: Any = {
+ "database_id": 1,
+ "user_id": 1,
+ "default_redirect_uri":
"http://localhost:8088/api/v1/database/oauth2/",
+ "tab_id": "tab",
+ }
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Any annotations weaken typing</b></div>
<div id="fix">
`BigQueryEngineSpec.get_oauth2_authorization_uri` declares `config:
OAuth2ClientConfig` and `state: OAuth2State` (`superset_typing.py:378,420`),
and sibling tests in `test_base.py:979,989` annotate these dicts with those
exact TypedDicts. Annotating them `Any` here discards static key/type checking
for no benefit; this file already imports from `superset.superset_typing`.
</div>
</div>
<small><i>Code Review Run #dc3da6</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]