summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/create_collection_test.cpp
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2020-08-12 18:58:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-17 19:13:31 +0000
commite2cb34fa34829370153fe207950f8c74dea45826 (patch)
treee0967657072075024596b3d3ea22763b31ef9552 /src/mongo/db/catalog/create_collection_test.cpp
parent56b83070a83b2bf134a54063b27c2b48b22dd852 (diff)
downloadmongo-e2cb34fa34829370153fe207950f8c74dea45826.tar.gz
SERVER-49915 Disable document validation for <database>.system.resharding.* namespaces
Diffstat (limited to 'src/mongo/db/catalog/create_collection_test.cpp')
-rw-r--r--src/mongo/db/catalog/create_collection_test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/create_collection_test.cpp b/src/mongo/db/catalog/create_collection_test.cpp
index ea9bc5c02a5..cef79c84a45 100644
--- a/src/mongo/db/catalog/create_collection_test.cpp
+++ b/src/mongo/db/catalog/create_collection_test.cpp
@@ -271,4 +271,29 @@ TEST_F(CreateCollectionTest, ValidationOptions) {
validateValidator("{$expr: {$_internalJsEmit: {eval: 'function() {}', this: {}}}}", 4660801);
validateValidator("{$where: 'this.a == this.b'}", static_cast<int>(ErrorCodes::BadValue));
}
+
+// Tests that validator validation is disabled when inserting a document into a
+// <database>.system.resharding.* collection. The primary donor is responsible for validating
+// documents before they are inserted into the recipient's temporary resharding collection.
+TEST_F(CreateCollectionTest, ValidationDisabledForTemporaryReshardingCollection) {
+ NamespaceString reshardingNss("myDb", "system.resharding.yay");
+ auto opCtx = makeOpCtx();
+
+ Lock::GlobalLock lk(opCtx.get(), MODE_X); // Satisfy low-level locking invariants.
+ BSONObj createCmdObj = BSON("create" << reshardingNss.coll() << "validator" << BSON("a" << 5));
+ ASSERT_OK(createCollection(opCtx.get(), reshardingNss.db().toString(), createCmdObj));
+ ASSERT_TRUE(collectionExists(opCtx.get(), reshardingNss));
+
+ AutoGetCollection agc(opCtx.get(), reshardingNss, MODE_X);
+ Collection* collection = agc.getCollection();
+
+ WriteUnitOfWork wuow(opCtx.get());
+ // Ensure a document that violates validator criteria can be inserted into the temporary
+ // resharding collection.
+ auto insertObj = fromjson("{'_id':2, a:1}");
+ auto status =
+ collection->insertDocument(opCtx.get(), InsertStatement(insertObj), nullptr, false);
+ ASSERT_OK(status);
+}
+
} // namespace