fix(OAuth2): Support OAuth2 exception with legacy endpoint (#39897)

This commit is contained in:
Vitor Avila
2026-05-05 21:21:48 -03:00
committed by GitHub
parent 4b17ac2629
commit 3745e37182
6 changed files with 358 additions and 3 deletions

View File

@@ -41,7 +41,7 @@ from superset.common.db_query_status import QueryStatus
from superset.connectors.sqla.models import SqlaTable
from superset.db_engine_specs.base import BaseEngineSpec
from superset.db_engine_specs.mssql import MssqlEngineSpec
from superset.exceptions import SupersetException
from superset.exceptions import OAuth2RedirectError, SupersetException
from superset.extensions import cache_manager
from superset.models import core as models
from superset.models.dashboard import Dashboard
@@ -458,6 +458,59 @@ class TestCore(SupersetTestCase):
assert rv.status_code == 404
assert data["error"] == "Cached data not found"
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@mock.patch("superset.viz.BaseViz.get_df")
def test_explore_json_propagates_oauth2_redirect_error(
self, mock_get_df: mock.Mock
) -> None:
"""
SupersetErrorException exceptions bubble up properly.
"""
mock_get_df.side_effect = OAuth2RedirectError(
url="https://accounts.example.com/o/oauth2/v2/auth?...",
tab_id="tab-123",
redirect_uri="https://superset.example.com/oauth2/redirect",
)
self.login(ADMIN_USERNAME)
slc = self.get_slice("Life Expectancy VS Rural %")
rv = self.client.post(
f"/superset/explore_json/{slc.datasource_type}/{slc.datasource_id}/",
data={"form_data": json.dumps(slc.form_data)},
)
data = json.loads(rv.data.decode("utf-8"))
assert "errors" in data, data
assert data["errors"][0]["error_type"] == "OAUTH2_REDIRECT"
assert data["errors"][0]["extra"] == {
"url": "https://accounts.example.com/o/oauth2/v2/auth?...",
"tab_id": "tab-123",
"redirect_uri": "https://superset.example.com/oauth2/redirect",
}
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@mock.patch("superset.viz.BaseViz.get_df")
def test_explore_json_generic_exception_still_returns_viz_get_df_error(
self, mock_get_df: mock.Mock
) -> None:
"""
Non-Superset exceptions raised by ``get_df`` are reported as the
generic ``VIZ_GET_DF_ERROR``.
"""
mock_get_df.side_effect = RuntimeError("boom")
self.login(ADMIN_USERNAME)
slc = self.get_slice("Life Expectancy VS Rural %")
rv = self.client.post(
f"/superset/explore_json/{slc.datasource_type}/{slc.datasource_id}/",
data={"form_data": json.dumps(slc.form_data)},
)
data = json.loads(rv.data.decode("utf-8"))
assert "errors" in data, data
assert data["errors"][0]["error_type"] == "VIZ_GET_DF_ERROR"
assert data["errors"][0]["message"] == "boom"
def test_results_default_deserialization(self):
use_new_deserialization = False
data = [("a", 4, 4.0, "2019-08-18T16:39:16.660000")]