Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): add impersonate_user to db import #29522

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

eschutho marked this conversation as resolved.
Show resolved Hide resolved
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
Loading