summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2021-12-13 11:21:33 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-16 19:03:39 +0000
commite166033f62f8efdc0499ce534235c0209c217405 (patch)
tree238cd689e73a29324822df2a13b3549a567c4087
parent1c5cf91ebff1a81a43be37ece3d5f5003bac81e7 (diff)
downloadmongo-e166033f62f8efdc0499ce534235c0209c217405.tar.gz
SERVER-61846 add redaction test for small fields
(cherry picked from commit c8de2a7f419f2486780fed5ae06ade4e78aa2a5d)
-rw-r--r--src/mongo/logv2/redaction_test.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/logv2/redaction_test.cpp b/src/mongo/logv2/redaction_test.cpp
index e6feb6de33c..8ab293822c2 100644
--- a/src/mongo/logv2/redaction_test.cpp
+++ b/src/mongo/logv2/redaction_test.cpp
@@ -154,5 +154,18 @@ TEST(RedactBSONTest, BSONWithArrays) {
testBSONCases(testCases);
}
+
+TEST(RedactBSONTest, RedactCausesBSONTooLarge) {
+ logv2::setShouldRedactLogs(true);
+ BSONObjBuilder bob;
+ for (int i = 0; i < 1024 * 1024; i++) {
+ auto fieldName = "abcdefg";
+ // The value of each field is smaller than the size of the kRedactionDefaultMask.
+ bob.append(fieldName, 1);
+ }
+ const auto obj = bob.obj();
+ // Demonstrates it is possible to grow a BSON too large by redacting fields.
+ ASSERT_THROWS_CODE(redact(obj), DBException, ErrorCodes::BSONObjectTooLarge);
+}
} // namespace
} // namespace mongo