Skip to content

Commit adee262

Browse files
committed
add test for masking rules
1 parent 4d4d717 commit adee262

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/unit/data_masking/_aws_encryption_sdk/test_unit_data_masking.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,37 @@ def test_erase_json_dict_with_fields_and_masks(data_masker):
248248
"b": {"3": {"4": "*******", "e": "world"}},
249249
},
250250
}
251+
252+
253+
def test_erase_json_dict_with_complex_masking_rules(data_masker):
254+
# GIVEN the data type is a json representation of a dictionary with nested and filtered paths
255+
data = json.dumps(
256+
{
257+
"email": "[email protected]",
258+
"age": 30,
259+
"addres": [
260+
{"postcode": 13000, "street": "123 Main St", "details": {"name": "Home", "type": "Primary"}},
261+
{"postcode": 14000, "street": "456 Other Street", "details": {"name": "Office", "type": "Secondary"}},
262+
],
263+
},
264+
)
265+
266+
# WHEN erase is called with complex masking rules
267+
masking_rules = {
268+
"email": {"regex_pattern": "(.)(.*)(@.*)", "mask_format": r"\1****\3"},
269+
"age": {"dynamic_mask": True},
270+
"addres..name": {"custom_mask": "xxx"},
271+
"addres[?(@.postcode > 12000)]": {"dynamic_mask": True},
272+
}
273+
274+
masked_json_string = data_masker.erase(data, masking_rules=masking_rules)
275+
276+
# THEN the result should have all specified fields masked according to their rules
277+
assert masked_json_string == {
278+
"email": "j****@example.com",
279+
"age": "*****",
280+
"addres": [
281+
{"postcode": "*****", "street": "*** *** **", "details": {"name": "xxx", "type": "*******"}},
282+
{"postcode": "*****", "street": "*** ***** ******", "details": {"name": "xxx", "type": "********"}},
283+
],
284+
}

0 commit comments

Comments
 (0)