Skip to content

Commit

Permalink
fix(OAuth): Remove masked_encrypted_extra from DB update properties (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila authored Jan 14, 2025
1 parent c2d7cf3 commit 8050e35
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/commands/database/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def run(self) -> Model:
self._properties["encrypted_extra"] = (
self._model.db_engine_spec.unmask_encrypted_extra(
self._model.encrypted_extra,
self._properties["masked_encrypted_extra"],
self._properties.pop("masked_encrypted_extra"),
)
)

Expand Down
48 changes: 48 additions & 0 deletions tests/unit_tests/commands/databases/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,54 @@ def test_remove_oauth_config_purges_tokens(
database_needs_oauth2.purge_oauth2_tokens.assert_called()


def test_update_oauth2_removes_masked_encrypted_extra_key(
mocker: MockerFixture,
database_needs_oauth2: MockerFixture,
) -> None:
"""
Test that the ``masked_encrypted_extra`` key is properly purged from the properties.
"""
DatabaseDAO = mocker.patch("superset.commands.database.update.DatabaseDAO") # noqa: N806
DatabaseDAO.find_by_id.return_value = database_needs_oauth2
DatabaseDAO.update.return_value = database_needs_oauth2

find_permission_view_menu = mocker.patch.object(
security_manager,
"find_permission_view_menu",
)
find_permission_view_menu.side_effect = [
None,
"[my_db].[schema2]",
]
add_permission_view_menu = mocker.patch.object(
security_manager,
"add_permission_view_menu",
)

modified_oauth2_client_info = oauth2_client_info.copy()
modified_oauth2_client_info["scope"] = "scope-b"

UpdateDatabaseCommand(
1,
{
"masked_encrypted_extra": json.dumps(
{"oauth2_client_info": modified_oauth2_client_info}
)
},
).run()

add_permission_view_menu.assert_not_called()
database_needs_oauth2.purge_oauth2_tokens.assert_called()
DatabaseDAO.update.assert_called_with(
database_needs_oauth2,
{
"encrypted_extra": json.dumps(
{"oauth2_client_info": modified_oauth2_client_info}
)
},
)


def test_update_other_fields_dont_affect_oauth(
mocker: MockerFixture,
database_needs_oauth2: MockerFixture,
Expand Down

0 comments on commit 8050e35

Please sign in to comment.