summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-03-20 11:39:34 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-20 18:44:06 +0000
commit0773e877547ce58c28dceca5a49ecb113d61baf8 (patch)
tree72a707342fb318b0928b89b64d9a4798a0b86698 /jstests
parent7260060587d27731bbcb1f8a27e2d2d75b6cc287 (diff)
downloadmongo-0773e877547ce58c28dceca5a49ecb113d61baf8.tar.gz
SERVER-38426 Verify that renaming collections to system collections is disallowed and vice-versa
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthroughWithMongod/cannot_rename_collection_to_system_collection.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/cannot_rename_collection_to_system_collection.js b/jstests/noPassthroughWithMongod/cannot_rename_collection_to_system_collection.js
new file mode 100644
index 00000000000..4be1738cf8f
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/cannot_rename_collection_to_system_collection.js
@@ -0,0 +1,24 @@
+/**
+ * Verifies that we disallow renaming collections to system collections and vice-versa.
+ */
+(function() {
+"use strict";
+
+const dbName = "cannot_rename_collection_to_system_collection";
+
+const testDB = db.getSiblingDB(dbName);
+
+assert.commandFailedWithCode(testDB.createCollection("system.a"), ErrorCodes.InvalidNamespace);
+
+testDB.getCollection("a").drop();
+assert.commandWorked(testDB.createCollection("a"));
+
+// Ensure we cannot rename "a" to a system collections
+assert.commandFailedWithCode(testDB.getCollection("a").renameCollection("system.a"),
+ ErrorCodes.IllegalOperation);
+
+// Ensure we cannot rename system collections to "a".
+assert.commandFailedWithCode(
+ db.getSiblingDB("admin").getCollection("system.version").renameCollection("a"),
+ ErrorCodes.IllegalOperation);
+}());