|
|
@ -168,8 +168,8 @@ TEST_F(TextFormatTest, ShortFormat) { |
|
|
|
unittest::RedactedFields proto; |
|
|
|
unittest::RedactedFields proto; |
|
|
|
unittest::TestNestedMessageRedaction redacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction redacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction unredacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction unredacted_nested_proto; |
|
|
|
redacted_nested_proto.set_optional_nested_string("hello"); |
|
|
|
redacted_nested_proto.set_optional_unredacted_nested_string("hello"); |
|
|
|
unredacted_nested_proto.set_optional_nested_string("world"); |
|
|
|
unredacted_nested_proto.set_optional_unredacted_nested_string("world"); |
|
|
|
proto.set_optional_redacted_string("foo"); |
|
|
|
proto.set_optional_redacted_string("foo"); |
|
|
|
proto.set_optional_unredacted_string("bar"); |
|
|
|
proto.set_optional_unredacted_string("bar"); |
|
|
|
proto.add_repeated_redacted_string("1"); |
|
|
|
proto.add_repeated_redacted_string("1"); |
|
|
@ -186,38 +186,53 @@ TEST_F(TextFormatTest, ShortFormat) { |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
unittest::TestNestedMessageRedaction* unredacted_message_2 = |
|
|
|
unittest::TestNestedMessageRedaction* unredacted_message_2 = |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
redacted_message_1->set_optional_nested_string("5"); |
|
|
|
redacted_message_1->set_optional_unredacted_nested_string("5"); |
|
|
|
redacted_message_2->set_optional_nested_string("6"); |
|
|
|
redacted_message_2->set_optional_unredacted_nested_string("6"); |
|
|
|
unredacted_message_1->set_optional_nested_string("7"); |
|
|
|
unredacted_message_1->set_optional_unredacted_nested_string("7"); |
|
|
|
unredacted_message_2->set_optional_nested_string("8"); |
|
|
|
unredacted_message_2->set_optional_unredacted_nested_string("8"); |
|
|
|
(*proto.mutable_map_redacted_string())["abc"] = "def"; |
|
|
|
(*proto.mutable_map_redacted_string())["abc"] = "def"; |
|
|
|
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl"; |
|
|
|
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl"; |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_THAT( |
|
|
|
std::string value_replacement = "\\[REDACTED\\]"; |
|
|
|
google::protobuf::ShortFormat(proto), |
|
|
|
EXPECT_THAT(google::protobuf::ShortFormat(proto), |
|
|
|
testing::MatchesRegex( |
|
|
|
testing::MatchesRegex( |
|
|
|
"optional_redacted_string: \\[REDACTED\\] " |
|
|
|
"optional_redacted_string: " + |
|
|
|
"optional_unredacted_string: \"bar\" " |
|
|
|
value_replacement + |
|
|
|
"repeated_redacted_string: \\[REDACTED\\] " |
|
|
|
" " |
|
|
|
"repeated_redacted_string: \\[REDACTED\\] " |
|
|
|
"optional_unredacted_string: \"bar\" " |
|
|
|
"repeated_unredacted_string: \"3\" " |
|
|
|
"repeated_redacted_string: " + |
|
|
|
"repeated_unredacted_string: \"4\" " |
|
|
|
value_replacement + |
|
|
|
"optional_redacted_message: \\[REDACTED\\] " |
|
|
|
" " |
|
|
|
"optional_unredacted_message \\{ " |
|
|
|
"repeated_redacted_string: " + |
|
|
|
"optional_nested_string: \"world\" \\} " |
|
|
|
value_replacement + |
|
|
|
"repeated_redacted_message: \\[REDACTED\\] " |
|
|
|
" " |
|
|
|
"repeated_unredacted_message \\{ optional_nested_string: \"7\" \\} " |
|
|
|
"repeated_unredacted_string: \"3\" " |
|
|
|
"repeated_unredacted_message \\{ optional_nested_string: \"8\" \\} " |
|
|
|
"repeated_unredacted_string: \"4\" " |
|
|
|
"map_redacted_string: \\[REDACTED\\] " |
|
|
|
"optional_redacted_message: " + |
|
|
|
"map_unredacted_string \\{ key: \"ghi\" value: \"jkl\" \\}")); |
|
|
|
value_replacement + |
|
|
|
|
|
|
|
" " |
|
|
|
|
|
|
|
"optional_unredacted_message \\{ " |
|
|
|
|
|
|
|
"optional_unredacted_nested_string: \"world\" \\} " |
|
|
|
|
|
|
|
"repeated_redacted_message: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
" " |
|
|
|
|
|
|
|
"repeated_unredacted_message " |
|
|
|
|
|
|
|
"\\{ optional_unredacted_nested_string: \"7\" \\} " |
|
|
|
|
|
|
|
"repeated_unredacted_message " |
|
|
|
|
|
|
|
"\\{ optional_unredacted_nested_string: \"8\" \\} " |
|
|
|
|
|
|
|
"map_redacted_string: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
" " |
|
|
|
|
|
|
|
"map_unredacted_string \\{ key: \"ghi\" value: \"jkl\" \\}")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(TextFormatTest, Utf8Format) { |
|
|
|
TEST_F(TextFormatTest, Utf8Format) { |
|
|
|
unittest::RedactedFields proto; |
|
|
|
unittest::RedactedFields proto; |
|
|
|
unittest::TestNestedMessageRedaction redacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction redacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction unredacted_nested_proto; |
|
|
|
unittest::TestNestedMessageRedaction unredacted_nested_proto; |
|
|
|
redacted_nested_proto.set_optional_nested_string("\350\260\267\346\255\214"); |
|
|
|
redacted_nested_proto.set_optional_unredacted_nested_string( |
|
|
|
unredacted_nested_proto.set_optional_nested_string( |
|
|
|
"\350\260\267\346\255\214"); |
|
|
|
|
|
|
|
unredacted_nested_proto.set_optional_unredacted_nested_string( |
|
|
|
"\350\260\267\346\255\214"); |
|
|
|
"\350\260\267\346\255\214"); |
|
|
|
proto.set_optional_redacted_string("foo"); |
|
|
|
proto.set_optional_redacted_string("foo"); |
|
|
|
proto.set_optional_unredacted_string("bar"); |
|
|
|
proto.set_optional_unredacted_string("bar"); |
|
|
@ -235,30 +250,44 @@ TEST_F(TextFormatTest, Utf8Format) { |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
unittest::TestNestedMessageRedaction* unredacted_message_2 = |
|
|
|
unittest::TestNestedMessageRedaction* unredacted_message_2 = |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
proto.add_repeated_unredacted_message(); |
|
|
|
redacted_message_1->set_optional_nested_string("5"); |
|
|
|
redacted_message_1->set_optional_unredacted_nested_string("5"); |
|
|
|
redacted_message_2->set_optional_nested_string("6"); |
|
|
|
redacted_message_2->set_optional_unredacted_nested_string("6"); |
|
|
|
unredacted_message_1->set_optional_nested_string("7"); |
|
|
|
unredacted_message_1->set_optional_unredacted_nested_string("7"); |
|
|
|
unredacted_message_2->set_optional_nested_string("8"); |
|
|
|
unredacted_message_2->set_optional_unredacted_nested_string("8"); |
|
|
|
(*proto.mutable_map_redacted_string())["abc"] = "def"; |
|
|
|
(*proto.mutable_map_redacted_string())["abc"] = "def"; |
|
|
|
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl"; |
|
|
|
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string value_replacement = "\\[REDACTED\\]"; |
|
|
|
EXPECT_THAT(google::protobuf::Utf8Format(proto), |
|
|
|
EXPECT_THAT(google::protobuf::Utf8Format(proto), |
|
|
|
testing::MatchesRegex( |
|
|
|
testing::MatchesRegex( |
|
|
|
"optional_redacted_string: \\[REDACTED\\]\n" |
|
|
|
"optional_redacted_string: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
"optional_unredacted_string: \"bar\"\n" |
|
|
|
"optional_unredacted_string: \"bar\"\n" |
|
|
|
"repeated_redacted_string: \\[REDACTED\\]\n" |
|
|
|
"repeated_redacted_string: " + |
|
|
|
"repeated_redacted_string: \\[REDACTED\\]\n" |
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
|
|
|
|
"repeated_redacted_string: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
"repeated_unredacted_string: \"3\"\n" |
|
|
|
"repeated_unredacted_string: \"3\"\n" |
|
|
|
"repeated_unredacted_string: \"4\"\n" |
|
|
|
"repeated_unredacted_string: \"4\"\n" |
|
|
|
"optional_redacted_message: \\[REDACTED\\]\n" |
|
|
|
"optional_redacted_message: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
"optional_unredacted_message \\{\n " |
|
|
|
"optional_unredacted_message \\{\n " |
|
|
|
"optional_nested_string: \"\xE8\xB0\xB7\xE6\xAD\x8C\"\n\\}\n" |
|
|
|
"optional_unredacted_nested_string: " |
|
|
|
"repeated_redacted_message: \\[REDACTED\\]\n" |
|
|
|
"\"\xE8\xB0\xB7\xE6\xAD\x8C\"\n\\}\n" |
|
|
|
|
|
|
|
"repeated_redacted_message: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
"repeated_unredacted_message \\{\n " |
|
|
|
"repeated_unredacted_message \\{\n " |
|
|
|
"optional_nested_string: \"7\"\n\\}\n" |
|
|
|
"optional_unredacted_nested_string: \"7\"\n\\}\n" |
|
|
|
"repeated_unredacted_message \\{\n " |
|
|
|
"repeated_unredacted_message \\{\n " |
|
|
|
"optional_nested_string: \"8\"\n\\}\n" |
|
|
|
"optional_unredacted_nested_string: \"8\"\n\\}\n" |
|
|
|
"map_redacted_string: \\[REDACTED\\]\n" |
|
|
|
"map_redacted_string: " + |
|
|
|
|
|
|
|
value_replacement + |
|
|
|
|
|
|
|
"\n" |
|
|
|
"map_unredacted_string \\{\n " |
|
|
|
"map_unredacted_string \\{\n " |
|
|
|
"key: \"ghi\"\n value: \"jkl\"\n\\}\n")); |
|
|
|
"key: \"ghi\"\n value: \"jkl\"\n\\}\n")); |
|
|
|
} |
|
|
|
} |
|
|
|