summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-11-11 17:39:13 -0500
committerBenety Goh <benety@mongodb.com>2014-11-12 14:36:03 -0500
commit546bf9a6d7b2c53e81d6a31b652cef15ec103570 (patch)
tree881b84fbe5ad23354d1f5386d67892c8c7307c6e /jstests/core
parente7091e53396d7c9ea0b9a74af253a68ac0c0d234 (diff)
downloadmongo-546bf9a6d7b2c53e81d6a31b652cef15ec103570.tar.gz
SERVER-16069 Input validation on the arguments to createCollection
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/apitest_db.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/jstests/core/apitest_db.js b/jstests/core/apitest_db.js
index 932a206a802..066f80115a9 100644
--- a/jstests/core/apitest_db.js
+++ b/jstests/core/apitest_db.js
@@ -38,9 +38,23 @@ var found = false;
db.getCollectionNames().forEach( function(x) { if (x == "test") found = true; });
assert(found, "found test.test in system.namespaces");
+// storageEngine in collection options must:
+// - be a document
+// - contains a single field of document type with the name of the current storage engine.
+db.getCollection('test').drop();
+var storageEngineName = db.serverStatus().storageEngine.name;
+assert.commandFailed(db.createCollection('test', {storageEngine: {}}));
+assert.commandFailed(db.createCollection('test', {storageEngine: {unknownStorageEngine: {}}}));
+var invalidStorageEngineOptions = {}
+invalidStorageEngineOptions[storageEngineName] = 12345;
+assert.commandFailed(db.createCollection('test', {storageEngine: invalidStorageEngineOptions}));
+
// Test round trip of storageEngine in collection options.
+// Assume that empty document for storageEngine-specific options is acceptable.
+var validStorageEngineOptions = {}
+validStorageEngineOptions[storageEngineName] = {};
db.getCollection('test').drop();
-assert.commandWorked(db.createCollection('test', {storageEngine: {storageEngine1: {x: 1}}}));
+assert.commandWorked(db.createCollection('test', {storageEngine: validStorageEngineOptions}));
var result = assert.commandWorked(db.runCommand('listCollections'));
found = false;
for (var i = 0; i < result.collections.length; ++i) {
@@ -49,7 +63,7 @@ for (var i = 0; i < result.collections.length; ++i) {
continue;
}
found = true;
- assert.docEq({storageEngine1: {x: 1}}, collection.options.storageEngine,
+ assert.docEq(validStorageEngineOptions, collection.options.storageEngine,
'storage engine options not found in listCommands result');
}
assert(found, "'test' collection not created");