diff options
author | Max Hirschhorn <max.hirschhorn@mongodb.com> | 2015-10-29 12:45:45 -0400 |
---|---|---|
committer | Ramon Fernandez <ramon@mongodb.com> | 2016-01-12 12:57:13 -0500 |
commit | afcc50b846742189d4250a8f2ac9786f66e70e05 (patch) | |
tree | bb338124c0de70a403487ec27eb4f2addc36f089 | |
parent | 0e5df8d9a74ccdcc0982de9af37f3287e6f1acda (diff) | |
download | mongo-afcc50b846742189d4250a8f2ac9786f66e70e05.tar.gz |
SERVER-20858 Reject creation of non-capped oplog collections.
(cherry picked from commit bee7144f59bc8782c3c8e76c45a9f9e0e39cb1e6)
-rw-r--r-- | jstests/noPassthrough/noncapped_oplog_creation.js | 38 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/jstests/noPassthrough/noncapped_oplog_creation.js b/jstests/noPassthrough/noncapped_oplog_creation.js new file mode 100644 index 00000000000..87dc37e6ed6 --- /dev/null +++ b/jstests/noPassthrough/noncapped_oplog_creation.js @@ -0,0 +1,38 @@ +/** + * Test that the server returns an error response for operations that attempt to create a non-capped + * oplog collection. + */ +(function() { + 'use strict'; + + var dbpath = MongoRunner.dataPath + 'noncapped_oplog_creation'; + resetDbpath(dbpath); + + var conn = MongoRunner.runMongod({ + dbpath: dbpath, + noCleanData: true, + }); + assert.neq(null, conn, 'mongod was unable to start up'); + + var localDB = conn.getDB('local'); + + // Test that explicitly creating a non-capped oplog collection fails. + assert.commandFailed(localDB.createCollection('oplog.fake', {capped: false})); + + // Test that inserting into the replica set oplog fails when implicitly creating a non-capped + // collection. + assert.writeError(localDB.oplog.rs.insert({})); + + // Test that inserting into the master-slave oplog fails when implicitly creating a non-capped + // collection. + assert.commandFailed(localDB.runCommand({godinsert: 'oplog.$main', obj: {}})); + + // Test that creating a non-capped oplog collection fails when using $out. + assert.writeOK(localDB.input.insert({})); + assert.commandFailed(localDB.runCommand({ + aggregate: 'input', + pipeline: [{$out: 'oplog.aggregation'}], + })); + + MongoRunner.stopMongod(conn); +})(); diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index 23775d859c4..0d6f0e9aef2 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -487,6 +487,7 @@ Collection* Database::createCollection(OperationContext* txn, NamespaceString nss(ns); uassert(17316, "cannot create a blank collection", nss.coll() > 0); + uassert(28838, "cannot create a non-capped oplog collection", options.capped || !nss.isOplog()); audit::logCreateCollection(currentClient.get(), ns); |