Remove redaction flag from DebugString.

PiperOrigin-RevId: 528540493
pull/12610/head
bangert 2 years ago committed by Copybara-Service
parent f8a51421c7
commit aacb773988
  1. 26
      src/google/protobuf/text_format.cc
  2. 2
      src/google/protobuf/text_format.h
  3. 52
      src/google/protobuf/text_format_unittest.cc

@ -105,13 +105,7 @@ namespace internal {
const char kDebugStringSilentMarker[] = "";
const char kDebugStringSilentMarkerForDetection[] = "\t ";
// Controls insertion of a marker making debug strings non-parseable.
PROTOBUF_EXPORT std::atomic<bool> enable_debug_text_redaction_marker;
// Controls insertion of a randomized marker in debug strings.
PROTOBUF_EXPORT std::atomic<bool> enable_debug_text_random_marker;
// Controls insertion of kDebugStringSilentMarker.
// Controls insertion of kDebugStringSilentMarker into DebugString() output.
PROTOBUF_EXPORT std::atomic<bool> enable_debug_text_format_marker;
int64_t GetRedactedFieldCount() {
@ -128,12 +122,6 @@ std::string Message::DebugString() const {
printer.SetExpandAny(true);
printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load(
std::memory_order_relaxed));
printer.SetRedactDebugString(
internal::enable_debug_text_redaction_marker.load(
std::memory_order_relaxed));
printer.SetRandomizeDebugString(
internal::enable_debug_text_random_marker.load(
std::memory_order_relaxed));
printer.PrintToString(*this, &debug_string);
@ -150,12 +138,6 @@ std::string Message::ShortDebugString() const {
printer.SetExpandAny(true);
printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load(
std::memory_order_relaxed));
printer.SetRedactDebugString(
internal::enable_debug_text_redaction_marker.load(
std::memory_order_relaxed));
printer.SetRandomizeDebugString(
internal::enable_debug_text_random_marker.load(
std::memory_order_relaxed));
printer.PrintToString(*this, &debug_string);
// Single line mode currently might have an extra space at the end.
@ -176,12 +158,6 @@ std::string Message::Utf8DebugString() const {
printer.SetExpandAny(true);
printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load(
std::memory_order_relaxed));
printer.SetRedactDebugString(
internal::enable_debug_text_redaction_marker.load(
std::memory_order_relaxed));
printer.SetRandomizeDebugString(
internal::enable_debug_text_random_marker.load(
std::memory_order_relaxed));
printer.PrintToString(*this, &debug_string);

@ -67,8 +67,6 @@ namespace internal {
PROTOBUF_EXPORT extern const char kDebugStringSilentMarker[1];
PROTOBUF_EXPORT extern const char kDebugStringSilentMarkerForDetection[3];
PROTOBUF_EXPORT extern std::atomic<bool> enable_debug_text_redaction_marker;
PROTOBUF_EXPORT extern std::atomic<bool> enable_debug_text_random_marker;
PROTOBUF_EXPORT extern std::atomic<bool> enable_debug_text_format_marker;
PROTOBUF_EXPORT int64_t GetRedactedFieldCount();

@ -2385,58 +2385,6 @@ TEST(TextFormatUnknownFieldTest, TestUnknownExtension) {
EXPECT_FALSE(parser.ParseFromString("unknown_field: 1", &proto));
}
template <bool silent, bool redact, bool randomize>
class TextFormatBaseMarkerTest : public testing::Test {
public:
void SetUp() override {
saved_enable_debug_text_format_marker_ =
internal::enable_debug_text_format_marker;
saved_enable_debug_text_redaction_marker_ =
internal::enable_debug_text_redaction_marker;
saved_enable_debug_text_random_marker_ =
internal::enable_debug_text_random_marker;
internal::enable_debug_text_format_marker = silent;
internal::enable_debug_text_redaction_marker = redact;
internal::enable_debug_text_random_marker = randomize;
}
void TearDown() override {
internal::enable_debug_text_format_marker =
saved_enable_debug_text_format_marker_;
internal::enable_debug_text_redaction_marker =
saved_enable_debug_text_redaction_marker_;
internal::enable_debug_text_random_marker =
saved_enable_debug_text_random_marker_;
}
private:
bool saved_enable_debug_text_format_marker_;
bool saved_enable_debug_text_redaction_marker_;
bool saved_enable_debug_text_random_marker_;
};
using TextFormatRedactionTest = TextFormatBaseMarkerTest<false, true, false>;
TEST_F(TextFormatRedactionTest, TestRedactedField) {
unittest::RedactedFields proto;
proto.set_optional_redacted_string("foo");
EXPECT_THAT(
proto.DebugString(),
testing::MatchesRegex("optional_redacted_string: \\[REDACTED\\]\n"));
EXPECT_THAT(
proto.ShortDebugString(),
testing::MatchesRegex("optional_redacted_string: \\[REDACTED\\]"));
}
TEST_F(TextFormatRedactionTest, TestTextFormatIsNotRedacted) {
unittest::RedactedFields proto;
proto.set_optional_redacted_string("foo");
std::string text;
ASSERT_TRUE(TextFormat::PrintToString(proto, &text));
EXPECT_EQ("optional_redacted_string: \"foo\"\n", text);
}
TEST(TextFormatFloatingPointTest, PreservesNegative0) {
proto3_unittest::TestAllTypes in_message;

Loading…
Cancel
Save