diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2021-06-24 11:33:53 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-15 19:54:56 +0000 |
commit | d1f74cceb696a33b2486b04e569152de4922b2de (patch) | |
tree | 764423df87837a7d96ae7aab7f2f278a9eea86f4 /src | |
parent | 6f544fdc28219537626cbe5c3a078aa5e389a1b9 (diff) | |
download | mongo-d1f74cceb696a33b2486b04e569152de4922b2de.tar.gz |
SERVER-57289 redact should not convert BSONArray into BSONObj
(cherry picked from commit 3b8806bef0f65df11e4d49786bf962ce0dd6b4dd)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/bson/bsonobj.cpp | 6 | ||||
-rw-r--r-- | src/mongo/logv2/redaction_test.cpp | 15 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp index adf1710001b..c12cf7f77c1 100644 --- a/src/mongo/bson/bsonobj.cpp +++ b/src/mongo/bson/bsonobj.cpp @@ -144,10 +144,14 @@ BSONObj BSONObj::redact() const { struct redactor { void operator()(BSONObjBuilder& builder, const BSONObj& obj) { for (BSONElement e : obj) { - if (e.type() == Object || e.type() == Array) { + if (e.type() == Object) { BSONObjBuilder subBuilder = builder.subobjStart(e.fieldNameStringData()); operator()(subBuilder, e.Obj()); subBuilder.done(); + } else if (e.type() == Array) { + BSONObjBuilder subBuilder = builder.subarrayStart(e.fieldNameStringData()); + operator()(subBuilder, e.Obj()); + subBuilder.done(); } else { builder.append(e.fieldNameStringData(), "###"_sd); } diff --git a/src/mongo/logv2/redaction_test.cpp b/src/mongo/logv2/redaction_test.cpp index c7db40ab768..e6feb6de33c 100644 --- a/src/mongo/logv2/redaction_test.cpp +++ b/src/mongo/logv2/redaction_test.cpp @@ -106,7 +106,6 @@ void testBSONCases(std::initializer_list<BSONStringPair> testCases) { TEST(RedactBSONTest, BasicBSON) { logv2::setShouldRedactLogs(true); - std::vector<BSONStringPair> testCases; testBSONCases({BSONStringPair(BSONObj(), "{}"), BSONStringPair(BSON("" << 1), "{ : \"###\" }"), @@ -122,7 +121,13 @@ TEST(RedactBSONTest, BasicBSON) { << "1"), "{ a: \"###\", a: \"###\" }")}); } -/* + +void testBSONCases(std::vector<BSONStringPair>& testCases) { + for (auto m : testCases) { + ASSERT_EQ(redact(m.first).toString(), m.second); + } +} + TEST(RedactBSONTest, NestedBSON) { logv2::setShouldRedactLogs(true); std::vector<BSONStringPair> testCases; @@ -134,7 +139,7 @@ TEST(RedactBSONTest, NestedBSON) { testCases.push_back(BSONStringPair(BSON("a" << BSON("a" << 1)), "{ a: { a: \"###\" } }")); testCases.push_back(BSONStringPair(BSON("a" << BSON("a" << 1 << "b" << 1)), "{ a: { a: \"###\", b: \"###\" } }")); - testBSONVector(testCases); + testBSONCases(testCases); } TEST(RedactBSONTest, BSONWithArrays) { @@ -147,7 +152,7 @@ TEST(RedactBSONTest, BSONWithArrays) { testCases.push_back(BSONStringPair(BSON("a" << BSON_ARRAY(BSON("a" << 1) << BSON("b" << 1))), "{ a: [ { a: \"###\" }, { b: \"###\" } ] }")); - testBSONVector(testCases); -}*/ + testBSONCases(testCases); +} } // namespace } // namespace mongo |