Vitor-Avila commented on code in PR #38077:
URL: https://github.com/apache/superset/pull/38077#discussion_r2825650825
##########
tests/unit_tests/utils/json_tests.py:
##########
@@ -264,6 +266,119 @@ def test_json_int_dttm_ser():
json.json_int_dttm_ser(np.datetime64())
[email protected](
+ "payload,path_values,expected_result",
+ [
+ (
+ {
+ "credentials_info": {
+ "type": "service_account",
+ "private_key": "XXXXXXXXXX",
+ },
+ },
+ {"$.credentials_info.private_key": "NEW_KEY"},
+ {
+ "credentials_info": {
+ "type": "service_account",
+ "private_key": "NEW_KEY",
+ },
+ },
+ ),
+ (
+ {
+ "auth_params": {
+ "privatekey_body": "XXXXXXXXXX",
+ "privatekey_pass": "XXXXXXXXXX",
+ },
+ "other": "value",
+ },
+ {
+ "$.auth_params.privatekey_body": "-----BEGIN PRIVATE KEY-----",
+ "$.auth_params.privatekey_pass": "passphrase",
+ },
+ {
+ "auth_params": {
+ "privatekey_body": "-----BEGIN PRIVATE KEY-----",
+ "privatekey_pass": "passphrase",
+ },
+ "other": "value",
+ },
+ ),
+ (
+ {"existing": "value"},
+ {"$.nonexistent.path": "new_value"},
+ {"existing": "value"},
+ ),
+ ],
+)
+def test_set_masked_fields(
+ payload: dict[str, Any],
+ path_values: dict[str, Any],
+ expected_result: dict[str, Any],
+) -> None:
+ """
+ Test setting a value at a JSONPath location.
+ """
+ result = json.set_masked_fields(payload, path_values)
+ assert result == expected_result
+
+
[email protected](
+ "payload,sensitive_fields,expected_result",
+ [
+ (
+ {
+ "credentials_info": {
+ "type": "service_account",
+ "private_key": PASSWORD_MASK,
+ },
+ },
+ {"$.credentials_info.private_key", "$.credentials_info.type"},
+ ["$.credentials_info.private_key"],
+ ),
+ (
+ {
+ "credentials_info": {
+ "private_key": "ACTUAL_KEY",
+ },
+ },
+ {"$.credentials_info.private_key"},
+ [],
+ ),
+ (
+ {
+ "auth_params": {
+ "privatekey_body": PASSWORD_MASK,
+ "privatekey_pass": "actual_pass",
+ },
+ "oauth2_client_info": {
+ "secret": PASSWORD_MASK,
+ },
+ },
+ {
+ "$.auth_params.privatekey_body",
+ "$.auth_params.privatekey_pass",
+ "$.oauth2_client_info.secret",
+ },
+ [
+ "$.auth_params.privatekey_body",
+ "$.oauth2_client_info.secret",
+ ],
+ ),
+ ],
+)
+def test_get_masked_fields(
+ payload: dict[str, Any],
+ sensitive_fields: set[str],
+ expected_result: dict[str, Any],
+) -> None:
+ """
+ Test that get_masked_fields returns paths where value equals PASSWORD_MASK.
+ """
+ masked = json.get_masked_fields(payload, sensitive_fields)
+ assert masked == sorted(expected_result)
Review Comment:
Great catch as well. Fixing this now too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]