Skip to content

Commit 18f95f8

Browse files
xy24evergreen
authored andcommitted
SERVER-41947 Disallow using the system.views collection name as the source or target names in the rename command
1 parent 33621ea commit 18f95f8

File tree

7 files changed

+30
-152
lines changed

7 files changed

+30
-152
lines changed

buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ selector:
125125
- jstests/core/views/view_with_invalid_dbname.js
126126
- jstests/core/views/views_creation.js
127127
- jstests/core/views/views_drop.js
128-
- jstests/core/views/views_rename.js
129128

130129
# The tests below use applyOps, SERVER-1439.
131130
- jstests/core/list_collections1.js

jstests/change_streams/whole_cluster_metadata_notifications.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -191,46 +191,6 @@ for (let collToInvalidate of [db1Coll, db2Coll]) {
191191
assert.commandWorked(collToInvalidate.insert({_id: 2}));
192192
assert.eq(cst.getOneChange(aggCursor).operationType, "insert");
193193

194-
// Test that renaming a "system" collection to a user collection *does* return a rename
195-
// notification.
196-
assert.commandWorked(
197-
testDB.runCommand({create: "view1", viewOn: collToInvalidate.getName(), pipeline: []}));
198-
assert.commandWorked(testDB.system.views.renameCollection("non_system_collection"));
199-
cst.assertNextChangesEqual({
200-
cursor: aggCursor,
201-
expectedChanges: [{
202-
operationType: "rename",
203-
ns: {db: testDB.getName(), coll: "system.views"},
204-
to: {db: testDB.getName(), coll: "non_system_collection"}
205-
}],
206-
});
207-
208-
// Test that renaming a "system" collection to a different "system" collection does not
209-
// result in a notification in the change stream.
210-
aggCursor = cst.startWatchingAllChangesForCluster();
211-
assert.commandWorked(
212-
testDB.runCommand({create: "view1", viewOn: collToInvalidate.getName(), pipeline: []}));
213-
// Note that the target of the rename must be a valid "system" collection.
214-
assert.commandWorked(testDB.system.views.renameCollection("system.users"));
215-
// Verify that the change stream filters out the rename above, instead returning the
216-
// next insert to the test collection.
217-
assert.commandWorked(collToInvalidate.insert({_id: 1}));
218-
change = cst.getOneChange(aggCursor);
219-
assert.eq(change.operationType, "insert", tojson(change));
220-
assert.eq(change.ns, {db: testDB.getName(), coll: collToInvalidate.getName()});
221-
222-
// Test that renaming a user collection to a "system" collection *does* return a rename
223-
// notification.
224-
assert.commandWorked(collToInvalidate.renameCollection("system.views"));
225-
cst.assertNextChangesEqual({
226-
cursor: aggCursor,
227-
expectedChanges: [{
228-
operationType: "rename",
229-
ns: {db: testDB.getName(), coll: collToInvalidate.getName()},
230-
to: {db: testDB.getName(), coll: "system.views"}
231-
}],
232-
});
233-
234194
// Drop the "system.views" collection to avoid view catalog errors in subsequent tests.
235195
assertDropCollection(testDB, "system.views");
236196

jstests/change_streams/whole_db_metadata_notifications.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -194,54 +194,6 @@ change = cst.getOneChange(aggCursor);
194194
assert.eq(change.operationType, "insert", tojson(change));
195195
assert.eq(change.ns, {db: testDB.getName(), coll: coll.getName()});
196196

197-
// Test that renaming a "system" collection *does* return a notification if the target of
198-
// the rename is a non-system collection.
199-
assert.commandWorked(testDB.runCommand({create: "view1", viewOn: coll.getName(), pipeline: []}));
200-
assert.commandWorked(testDB.system.views.renameCollection("non_system_collection"));
201-
cst.assertNextChangesEqual({
202-
cursor: aggCursor,
203-
expectedChanges: [{
204-
operationType: "rename",
205-
ns: {db: testDB.getName(), coll: "system.views"},
206-
to: {db: testDB.getName(), coll: "non_system_collection"}
207-
}],
208-
});
209-
210-
// Test that renaming a "system" collection to a different "system" collection does not
211-
// result in a notification in the change stream.
212-
aggCursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: 1});
213-
assert.commandWorked(testDB.runCommand({create: "view1", viewOn: coll.getName(), pipeline: []}));
214-
// Note that the target of the rename must be a valid "system" collection.
215-
assert.commandWorked(testDB.system.views.renameCollection("system.users"));
216-
// Verify that the change stream filters out the rename above, instead returning the next insert
217-
// to the test collection.
218-
assert.commandWorked(coll.insert({_id: 1}));
219-
change = cst.getOneChange(aggCursor);
220-
assert.eq(change.operationType, "insert", tojson(change));
221-
assert.eq(change.ns, {db: testDB.getName(), coll: coll.getName()});
222-
223-
// Test that renaming a user collection to a "system" collection *is* returned in the change
224-
// stream.
225-
assert.commandWorked(coll.renameCollection("system.views"));
226-
cst.assertNextChangesEqual({
227-
cursor: aggCursor,
228-
expectedChanges: [{
229-
operationType: "rename",
230-
ns: {db: testDB.getName(), coll: coll.getName()},
231-
to: {db: testDB.getName(), coll: "system.views"}
232-
}],
233-
});
234-
235-
// Drop the "system.views" collection to avoid view catalog errors in subsequent tests.
236-
assertDropCollection(testDB, "system.views");
237-
assertDropCollection(testDB, "non_system_collection");
238-
cst.assertNextChangesEqual({
239-
cursor: aggCursor,
240-
expectedChanges: [
241-
{operationType: "drop", ns: {db: testDB.getName(), coll: "non_system_collection"}},
242-
]
243-
});
244-
245197
// Dropping the database should generate a 'dropDatabase' notification followed by an
246198
// 'invalidate'.
247199
assert.commandWorked(testDB.dropDatabase());

jstests/core/views/views_rename.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

jstests/noPassthrough/view_catalog_deadlock_with_rename.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(function() {
2+
'use strict';
3+
assert.commandWorked(db.runCommand({insert: 'a', documents: [{x: 1}]}));
4+
5+
// Disallow renaming to system.views
6+
assert.commandFailedWithCode(db.adminCommand({renameCollection: 'test.a', to: 'test.system.views'}),
7+
ErrorCodes.IllegalOperation);
8+
9+
assert.commandWorked(db.createView('viewA', 'a', []));
10+
11+
// Disallow renaming from system.views
12+
assert.commandFailedWithCode(
13+
db.adminCommand({renameCollection: 'test.system.views', to: 'test.aaabb'}),
14+
ErrorCodes.IllegalOperation);
15+
16+
// User can still rename system.views (or to system.views) via applyOps command.
17+
assert.commandWorked(db.adminCommand({
18+
applyOps: [{op: 'c', ns: 'test.$cmd', o: {renameCollection: 'test.system.views', to: 'test.b'}}]
19+
}));
20+
21+
assert.commandWorked(db.adminCommand({
22+
applyOps: [{op: 'c', ns: 'test.$cmd', o: {renameCollection: 'test.b', to: 'test.system.views'}}]
23+
}));
24+
})();

src/mongo/db/catalog/rename_collection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ Status renameCollection(OperationContext* opCtx,
747747
<< source);
748748
}
749749

750+
if (source.isSystemDotViews() || target.isSystemDotViews()) {
751+
return Status(
752+
ErrorCodes::IllegalOperation,
753+
"renaming system.views collection or renaming to system.views is not allowed");
754+
}
755+
750756
const std::string dropTargetMsg =
751757
options.dropTarget ? " and drop " + target.toString() + "." : ".";
752758
log() << "renameCollectionForCommand: rename " << source << " to " << target << dropTargetMsg;

0 commit comments

Comments
 (0)