Skip to content

Commit

Permalink
fix(cli): add impersonate_user to db import (#29522)
Browse files Browse the repository at this point in the history
Co-authored-by: Eugene Apollonsky <[email protected]>
Co-authored-by: Elizabeth Thompson <[email protected]>
  • Loading branch information
3 people committed Aug 12, 2024
1 parent c016ca5 commit 050c6da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/databases/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ def fix_allow_csv_upload(
allow_cvas = fields.Boolean()
allow_dml = fields.Boolean(required=False)
allow_csv_upload = fields.Boolean()
impersonate_user = fields.Boolean()
extra = fields.Nested(ImportV1DatabaseExtraSchema)
uuid = fields.UUID(required=True)
version = fields.String(required=True)
Expand Down
1 change: 1 addition & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
"allow_dml",
"allow_file_upload",
"extra",
"impersonate_user",
]
extra_import_fields = [
"password",
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/databases/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def test_export_database_command_key_order(self, mock_g):
"allow_dml",
"allow_csv_upload",
"extra",
"impersonate_user",
"uuid",
"version",
]
Expand Down
24 changes: 24 additions & 0 deletions tests/unit_tests/databases/commands/importers/v1/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ def test_import_database_with_version(mocker: MockerFixture, session: Session) -
assert json.loads(database.extra)["version"] == "1.1.1"


def test_import_database_with_user_impersonation(
mocker: MockerFixture,
session: Session,
) -> None:
"""
Test importing a database that is managed externally.
"""
from superset import security_manager
from superset.commands.database.importers.v1.utils import import_database
from superset.models.core import Database
from tests.integration_tests.fixtures.importexport import database_config

mocker.patch.object(security_manager, "can_access", return_value=True)
mocker.patch("superset.commands.database.importers.v1.utils.add_permissions")
engine = db.session.get_bind()
Database.metadata.create_all(engine) # pylint: disable=no-member

config = copy.deepcopy(database_config)
config["impersonate_user"] = True

database = import_database(config)
assert database.impersonate_user is True


def test_add_permissions(mocker: MockerFixture) -> None:
"""
Test adding permissions to a database when it's imported.
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/datasets/commands/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def test_export(session: Session) -> None:
engine_params: {{}}
metadata_cache_timeout: {{}}
schemas_allowed_for_file_upload: []
impersonate_user: false
uuid: {database.uuid}
version: 1.0.0
""",
Expand Down

0 comments on commit 050c6da

Please sign in to comment.