mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
feat: support for import/export masked_encrypted_extra (backend) (#38077)
This commit is contained in:
@@ -113,6 +113,58 @@ def test_import_assets(
|
||||
ssh_tunnel_passwords=None,
|
||||
ssh_tunnel_private_keys=None,
|
||||
ssh_tunnel_priv_key_passwords=None,
|
||||
encrypted_extra_secrets=None,
|
||||
)
|
||||
|
||||
|
||||
def test_import_assets_with_encrypted_extra_secrets(
|
||||
mocker: MockerFixture,
|
||||
client: Any,
|
||||
full_api_access: None,
|
||||
) -> None:
|
||||
"""
|
||||
Test that encrypted_extra_secrets are passed to ImportAssetsCommand.
|
||||
"""
|
||||
mocked_contents = {
|
||||
"metadata.yaml": (
|
||||
"version: 1.0.0\ntype: assets\ntimestamp: '2022-01-01T00:00:00+00:00'\n"
|
||||
),
|
||||
"databases/example.yaml": "<DATABASE CONTENTS>",
|
||||
}
|
||||
|
||||
ImportAssetsCommand = mocker.patch("superset.importexport.api.ImportAssetsCommand") # noqa: N806
|
||||
|
||||
root = Path("assets_export")
|
||||
buf = BytesIO()
|
||||
with ZipFile(buf, "w") as bundle:
|
||||
for path, contents in mocked_contents.items():
|
||||
with bundle.open(str(root / path), "w") as fp:
|
||||
fp.write(contents.encode())
|
||||
buf.seek(0)
|
||||
|
||||
secrets = {
|
||||
"assets_export/databases/example.yaml": {
|
||||
"$.credentials_info.private_key": "-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----\n", # noqa: E501
|
||||
}
|
||||
}
|
||||
form_data = {
|
||||
"bundle": (buf, "assets_export.zip"),
|
||||
"encrypted_extra_secrets": json.dumps(secrets),
|
||||
}
|
||||
response = client.post(
|
||||
"/api/v1/assets/import/", data=form_data, content_type="multipart/form-data"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json == {"message": "OK"}
|
||||
|
||||
ImportAssetsCommand.assert_called_with(
|
||||
mocked_contents,
|
||||
sparse=False,
|
||||
passwords=None,
|
||||
ssh_tunnel_passwords=None,
|
||||
ssh_tunnel_private_keys=None,
|
||||
ssh_tunnel_priv_key_passwords=None,
|
||||
encrypted_extra_secrets=secrets,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user