diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-18 17:02:53 -0300 |
| commit | 959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch) | |
| tree | acc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/db/update/addtoset_node_test.cpp | |
| parent | 76588293975fc059cf076779e4283e6ffaf8afff (diff) | |
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/db/update/addtoset_node_test.cpp')
| -rw-r--r-- | src/mongo/db/update/addtoset_node_test.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mongo/db/update/addtoset_node_test.cpp b/src/mongo/db/update/addtoset_node_test.cpp index d2b7f90be65..f590c7140dc 100644 --- a/src/mongo/db/update/addtoset_node_test.cpp +++ b/src/mongo/db/update/addtoset_node_test.cpp @@ -99,6 +99,23 @@ TEST(AddToSetNodeTest, InitSucceedsWithArray) { ASSERT_OK(node.init(update["$addToSet"]["a"], expCtx)); } +TEST(AddToSetNodeTest, InitFailsWhenArgumentIsInvalidBSONArray) { + // Create our invalid array by creating a BSONObj with non contiguous array indexes that is then + // passed to the BSONArray ctor. + BSONObj updateArrAsObj = BSON("0" + << "foo" + << "2" + << "bar"); + BSONArray updateArr(updateArrAsObj); + + auto update = BSON("$addToSet" << BSON("fieldName" << BSON("$each" << updateArr))); + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + AddToSetNode node; + + ASSERT_THROWS(node.init(update["$addToSet"]["fieldName"], expCtx), + ExceptionFor<ErrorCodes::BadValue>); +} + TEST(AddToSetNodeTest, InitSucceedsWithScaler) { auto update = fromjson("{$addToSet: {a: 1}}"); boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); |
