diff options
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()); |
