diff options
author | Moustafa Maher <m.maher@10gen.com> | 2021-01-24 03:36:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-26 00:47:49 +0000 |
commit | 593de2a7ed6e6717ed35112c63ab3ee38b825851 (patch) | |
tree | 93f5f275b08b4006f798c953a938186c3ec8a5a9 /src | |
parent | 57aa9e6106905a8969af5b997e2b316ce2d71b62 (diff) | |
download | mongo-593de2a7ed6e6717ed35112c63ab3ee38b825851.tar.gz |
SERVER-54003 Validate BSON type to be array when parsing BSON object to Array
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/pipeline/document_source_union_with_test.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/query/killcursors_request_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/tenant_migration_recipient_service.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/storage_timestamp_tests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 21 |
5 files changed, 25 insertions, 7 deletions
diff --git a/src/mongo/db/pipeline/document_source_union_with_test.cpp b/src/mongo/db/pipeline/document_source_union_with_test.cpp index 8fa361ce540..48068466824 100644 --- a/src/mongo/db/pipeline/document_source_union_with_test.cpp +++ b/src/mongo/db/pipeline/document_source_union_with_test.cpp @@ -282,7 +282,7 @@ TEST_F(DocumentSourceUnionWithTest, ParseErrors) { .firstElement(), getExpCtx()), AssertionException, - 10065); + ErrorCodes::TypeMismatch); ASSERT_THROWS_CODE(DocumentSourceUnionWith::createFromBson( BSON("$unionWith" << BSON("coll" << nsToUnionWith.coll() << "pipeline" << BSON("not" @@ -290,7 +290,7 @@ TEST_F(DocumentSourceUnionWithTest, ParseErrors) { .firstElement(), getExpCtx()), AssertionException, - 40422); + ErrorCodes::TypeMismatch); } TEST_F(DocumentSourceUnionWithTest, PropagatePauses) { diff --git a/src/mongo/db/query/killcursors_request_test.cpp b/src/mongo/db/query/killcursors_request_test.cpp index 2a63ba50769..5535fa2c56f 100644 --- a/src/mongo/db/query/killcursors_request_test.cpp +++ b/src/mongo/db/query/killcursors_request_test.cpp @@ -89,7 +89,8 @@ TEST(KillCursorsRequestTest, parseCursorFieldNotArray) { << "coll" << "cursors" << CursorId(123) << "$db" << "db"); - ASSERT_THROWS_CODE(KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, 10065); + ASSERT_THROWS_CODE( + KillCursorsRequest::parse(ctxt, bsonObj), AssertionException, ErrorCodes::TypeMismatch); } TEST(KillCursorsRequestTest, parseCursorFieldArrayWithNonCursorIdValue) { diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp index 3f3b8d0f408..a63f2094bd7 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp @@ -579,7 +579,7 @@ void TenantMigrationRecipientService::Instance::_startOplogFetcher() { // The config is only used for setting the awaitData timeout; the defaults are fine. ReplSetConfig::parse(BSON("_id" << "dummy" - << "version" << 1 << "members" << BSONObj())), + << "version" << 1 << "members" << BSONArray(BSONObj()))), // We do not need to check the rollback ID. ReplicationProcess::kUninitializedRollbackId, tenantMigrationOplogFetcherBatchSize, diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp index 7cdc62217cc..c1ccb5df053 100644 --- a/src/mongo/dbtests/storage_timestamp_tests.cpp +++ b/src/mongo/dbtests/storage_timestamp_tests.cpp @@ -738,7 +738,7 @@ public: << "ns" << "test.$cmd" << "wall" << Date_t() << "o" - << BSON("applyOps" << BSONArrayBuilder().obj())))), + << BSON("applyOps" << BSONArrayBuilder().arr())))), repl::OplogApplication::Mode::kApplyOpsCmd, &result)); } diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 6ab160786ed..cdbfeb70210 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -1057,8 +1057,25 @@ TEST(IDLArrayTests, TestBadArrays) { } } -// Positive: Test arrays with good field names but made with BSONObjBuilder -TEST(IDLArrayTests, TestGoodArrays) { +// Negative: Test arrays with good field names but made with BSONObjBuilder::subobjStart +TEST(IDLArrayTests, TestGoodArraysWithObjectType) { + IDLParserErrorContext ctxt("root"); + + { + BSONObjBuilder builder; + { + BSONObjBuilder subBuilder(builder.subobjStart("field1")); + subBuilder.append("0", 1); + subBuilder.append("1", 2); + } + + auto testDoc = builder.obj(); + ASSERT_THROWS(Simple_int_array::parse(ctxt, testDoc), AssertionException); + } +} + +// Positive: Test arrays with good field names but made with BSONObjBuilder::subarrayStart +TEST(IDLArrayTests, TestGoodArraysWithArrayType) { IDLParserErrorContext ctxt("root"); { |