summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-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);
+}());