feat: improve GSheets OAuth2 (#32048)

This commit is contained in:
Beto Dealmeida
2025-03-03 12:55:54 -05:00
committed by GitHub
parent 5766c36372
commit 5af4e61aff
16 changed files with 211 additions and 101 deletions

View File

@@ -15,6 +15,9 @@
# specific language governing permissions and limitations
# under the License.
import json
import pytest
from pytest_mock import MockerFixture
from sqlalchemy.orm.session import Session
@@ -28,6 +31,29 @@ from superset.migrations.shared.security_converge import (
PermissionView,
ViewMenu,
)
from superset.superset_typing import OAuth2ClientConfig
@pytest.fixture
def oauth2_config() -> OAuth2ClientConfig:
"""
Config for GSheets OAuth2.
"""
return {
"id": "XXX.apps.googleusercontent.com",
"secret": "GOCSPX-YYY",
"scope": " ".join(
[
"https://www.googleapis.com/auth/drive.readonly "
"https://www.googleapis.com/auth/spreadsheets "
"https://spreadsheets.google.com/feeds"
]
),
"redirect_uri": "http://localhost:8088/api/v1/oauth2/",
"authorization_request_uri": "https://accounts.google.com/o/oauth2/v2/auth",
"token_request_uri": "https://oauth2.googleapis.com/token",
"request_content_type": "json",
}
def test_upgrade_catalog_perms(mocker: MockerFixture, session: Session) -> None:
@@ -335,6 +361,7 @@ def test_upgrade_catalog_perms_graceful(
def test_upgrade_catalog_perms_oauth_connection(
mocker: MockerFixture,
session: Session,
oauth2_config: OAuth2ClientConfig,
) -> None:
"""
Test the `upgrade_catalog_perms` function when the DB is set up using OAuth.
@@ -362,7 +389,7 @@ def test_upgrade_catalog_perms_oauth_connection(
database = Database(
database_name="my_db",
sqlalchemy_uri="bigquery://my-test-project",
encrypted_extra='{"oauth2_client_info": "fake_mock_oauth_conn"}',
encrypted_extra=json.dumps({"oauth2_client_info": oauth2_config}),
)
dataset = SqlaTable(
table_name="my_table",