Add additional Scrubber tests.

This commit is contained in:
Greyson Parrelli
2023-08-04 11:43:33 -04:00
parent ae2998bcf2
commit ca79929141
2 changed files with 40 additions and 1 deletions

View File

@@ -77,6 +77,9 @@ public final class Scrubber {
"\\b");
private static final String IPV4_CENSOR = "...ipv4...";
private static final Pattern IPV6_PATTERN = Pattern.compile("([0-9a-fA-F]{0,4}:){3,7}([0-9a-fA-F]){0,4}");
private static final String IPV6_CENSOR = "...ipv6...";
/**
* The domain name except for TLD will be censored.
*/
@@ -104,6 +107,7 @@ public final class Scrubber {
in = scrubUuids(in);
in = scrubDomains(in);
in = scrubIpv4(in);
in = scrubIpv6(in);
in = scrubCallLinkKeys(in);
return in;
@@ -177,6 +181,12 @@ public final class Scrubber {
(matcher, output) -> output.append(IPV4_CENSOR));
}
private static CharSequence scrubIpv6(@NonNull CharSequence in) {
return scrub(in,
IPV6_PATTERN,
(matcher, output) -> output.append(IPV6_CENSOR));
}
private static CharSequence scrubCallLinkKeys(@NonNull CharSequence in) {
return scrub(in,
CALL_LINK_PATTERN,

View File

@@ -125,7 +125,36 @@ public final class ScrubberTest {
{ "Not a Call Link Root Key (Missing Quartet) BCAF-FGHK-MNPQ-RSTX-ZRQH-BCDF-STXZ",
"Not a Call Link Root Key (Missing Quartet) BCAF-FGHK-MNPQ-RSTX-ZRQH-BCDF-STXZ"
}
},
{
"2345:0425:2CA1:0000:0000:0567:5673:23b5",
"...ipv6..."
},
{ "2345:425:2CA1:0000:0000:567:5673:23b5",
"...ipv6..." },
{ "2345:0425:2CA1:0:0:0567:5673:23b5",
"...ipv6..." },
{ "2345:0425:2CA1::0567:5673:23b5",
"...ipv6..." },
{ "FF01:0:0:0:0:0:0:1",
"...ipv6..." },
{ "2001:db8::a3",
"...ipv6..." },
{ "text before 2345:0425:2CA1:0000:0000:0567:5673:23b5 text after",
"text before ...ipv6... text after" },
{ "Recipient::1",
"Recipient::1" },
{ "Recipient::123",
"Recipient::123" },
});
}