@@ -248,3 +248,37 @@ def test_erase_json_dict_with_fields_and_masks(data_masker):
248
248
"b" : {"3" : {"4" : "*******" , "e" : "world" }},
249
249
},
250
250
}
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
+
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