Skip to content

Commit 2c415f6

Browse files
authored
test(pii): Scrub everything except certain values (#5382)
1 parent 07cab11 commit 2c415f6

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

relay-pii/src/processor.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,81 @@ mod tests {
838838
assert_annotated_snapshot!(event);
839839
}
840840

841+
#[test]
842+
fn test_redact_custom_negative_pattern() {
843+
let config = serde_json::from_str::<PiiConfig>(
844+
r#"
845+
{
846+
"applications": {
847+
"$string": ["myrule"]
848+
},
849+
"rules": {
850+
"myrule": {
851+
"type": "pattern",
852+
"pattern": "the good string|.*OK.*|(.*)",
853+
"replaceGroups": [1],
854+
"redaction": {
855+
"method": "mask"
856+
}
857+
}
858+
}
859+
}
860+
"#,
861+
)
862+
.unwrap();
863+
864+
let mut event = Annotated::<Event>::from_json(
865+
r#"{
866+
"extra": {
867+
"1": "the good string",
868+
"2": "a bad string",
869+
"3": "another OK string",
870+
"4": "another bad one"
871+
}
872+
}"#,
873+
)
874+
.unwrap();
875+
876+
let mut processor = PiiProcessor::new(config.compiled());
877+
process_value(&mut event, &mut processor, ProcessingState::root()).unwrap();
878+
assert_annotated_snapshot!(event.value().unwrap().extra, @r#"
879+
{
880+
"1": "the good string",
881+
"2": "************",
882+
"3": "another OK string",
883+
"4": "***************",
884+
"_meta": {
885+
"2": {
886+
"": {
887+
"rem": [
888+
[
889+
"myrule",
890+
"m",
891+
0,
892+
12
893+
]
894+
],
895+
"len": 12
896+
}
897+
},
898+
"4": {
899+
"": {
900+
"rem": [
901+
[
902+
"myrule",
903+
"m",
904+
0,
905+
15
906+
]
907+
],
908+
"len": 15
909+
}
910+
}
911+
}
912+
}
913+
"#);
914+
}
915+
841916
#[test]
842917
fn test_no_field_upsert() {
843918
let config = serde_json::from_str::<PiiConfig>(

0 commit comments

Comments
 (0)