Anonymize UUIDs
Add a pattern to the anonymizer tool to catch and anonymize Universal
Unique Identidiers (UUIDs).
BUG=721115
TEST=components_unittests --gtest_filter=AnonymizerToolTest.AnonymizeCustomPatterns
Review-Url: https://codereview.chromium.org/2905723002
Cr-Commit-Position: refs/heads/master@{#474420}
diff --git a/components/feedback/anonymizer_tool.cc b/components/feedback/anonymizer_tool.cc
index f44dadf..198f979 100644
--- a/components/feedback/anonymizer_tool.cc
+++ b/components/feedback/anonymizer_tool.cc
@@ -165,14 +165,18 @@
// The |kCustomPatternWithoutContext| array defines further patterns to match
// and anonymize. Each pattern consists of a single capturing group.
CustomPatternWithoutContext kCustomPatternsWithoutContext[] = {
- {"URL", "(?i)(" IRI ")"},
- // Email Addresses need to come after URLs because they can be part
- // of a query parameter.
- {"email", "(?i)([0-9a-z._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6})"},
- // IP filter rules need to come after URLs so that they don't disturb the
- // URL pattern in case the IP address is part of a URL.
- {"IPv4", "(?i)(" IPV4ADDRESS ")"},
- {"IPv6", "(?i)(" IPV6ADDRESS ")"},
+ {"URL", "(?i)(" IRI ")"},
+ // Email Addresses need to come after URLs because they can be part
+ // of a query parameter.
+ {"email", "(?i)([0-9a-z._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6})"},
+ // IP filter rules need to come after URLs so that they don't disturb the
+ // URL pattern in case the IP address is part of a URL.
+ {"IPv4", "(?i)(" IPV4ADDRESS ")"},
+ {"IPv6", "(?i)(" IPV6ADDRESS ")"},
+ // Universal Unique Identifiers (UUIDs).
+ {"UUID",
+ "(?i)([0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-"
+ "[0-9a-zA-Z]{12})"},
};
// Like RE2's FindAndConsume, searches for the first occurrence of |pattern| in
diff --git a/components/feedback/anonymizer_tool_unittest.cc b/components/feedback/anonymizer_tool_unittest.cc
index b624763..c0b8754 100644
--- a/components/feedback/anonymizer_tool_unittest.cc
+++ b/components/feedback/anonymizer_tool_unittest.cc
@@ -47,6 +47,22 @@
// Make sure custom pattern anonymization is invoked.
EXPECT_EQ("Cell ID: '1'", AnonymizeCustomPatterns("Cell ID: 'A1B2'"));
+
+ // Make sure UUIDs are anonymized.
+ EXPECT_EQ(
+ "REQUEST localhost - - \"POST /printers/<UUID: 1> HTTP/1.1\" 200 291 "
+ "Create-Job successful-ok",
+ anonymizer_.Anonymize(
+ "REQUEST localhost - - \"POST /printers/"
+ "cb738a9f-6433-4d95-a81e-94e4ae0ed30b HTTP/1.1\" 200 291 Create-Job "
+ "successful-ok"));
+ EXPECT_EQ(
+ "REQUEST localhost - - \"POST /printers/<UUID: 2> HTTP/1.1\" 200 286 "
+ "Create-Job successful-ok",
+ anonymizer_.Anonymize(
+ "REQUEST localhost - - \"POST /printers/"
+ "d17188da-9cd3-44f4-b148-3e1d748a3b0f HTTP/1.1\" 200 286 Create-Job "
+ "successful-ok"));
}
TEST_F(AnonymizerToolTest, AnonymizeMACAddresses) {