mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(OAuth2): Update connection should not fail if connection is missing OAuth2 token (#33100)
This commit is contained in:
@@ -64,6 +64,8 @@ def database_without_catalog(mocker: MockerFixture) -> MagicMock:
|
||||
database.db_engine_spec.__name__ = "test_engine"
|
||||
database.db_engine_spec.supports_catalog = False
|
||||
database.get_all_schema_names.return_value = ["schema1", "schema2"]
|
||||
database.is_oauth2_enabled.return_value = False
|
||||
database.db_engine_spec.needs_oauth2.return_value = False
|
||||
|
||||
return database
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from superset import db
|
||||
from superset.commands.database.exceptions import (
|
||||
DatabaseConnectionFailedError,
|
||||
DatabaseNotFoundError,
|
||||
MissingOAuth2TokenError,
|
||||
UserNotFoundInSessionError,
|
||||
)
|
||||
from superset.commands.database.sync_permissions import SyncPermissionsCommand
|
||||
@@ -146,14 +147,18 @@ def test_sync_permissions_command_passing_all_values(
|
||||
|
||||
|
||||
@with_config({"SYNC_DB_PERMISSIONS_IN_ASYNC_MODE": False})
|
||||
def test_sync_permissions_command_raise(mocker: MockerFixture):
|
||||
def test_sync_permissions_command_raise(
|
||||
mocker: MockerFixture,
|
||||
database_without_catalog: MagicMock,
|
||||
database_needs_oauth2: MagicMock,
|
||||
):
|
||||
"""
|
||||
Test ``SyncPermissionsCommand`` when an exception is raised.
|
||||
"""
|
||||
mock_database_dao = mocker.patch(
|
||||
"superset.commands.database.sync_permissions.DatabaseDAO"
|
||||
)
|
||||
mock_database_dao.find_by_id.return_value = mocker.MagicMock()
|
||||
mock_database_dao.find_by_id.return_value = database_without_catalog
|
||||
mock_database_dao.get_ssh_tunnel.return_value = mocker.MagicMock()
|
||||
mock_user = mocker.patch(
|
||||
"superset.commands.database.sync_permissions.security_manager.get_user_by_username"
|
||||
@@ -169,6 +174,11 @@ def test_sync_permissions_command_raise(mocker: MockerFixture):
|
||||
mock_ping.side_effect = Exception
|
||||
with pytest.raises(DatabaseConnectionFailedError):
|
||||
SyncPermissionsCommand(1, "admin").run()
|
||||
# OAuth2 error
|
||||
mock_database_dao.find_by_id.reset_mock()
|
||||
mock_database_dao.find_by_id.return_value = database_needs_oauth2
|
||||
with pytest.raises(MissingOAuth2TokenError):
|
||||
SyncPermissionsCommand(1, "admin").run()
|
||||
|
||||
# User not found in session
|
||||
mock_user.reset_mock()
|
||||
|
||||
Reference in New Issue
Block a user