diff options
author | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-03-06 11:44:54 -0500 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-03-06 11:47:29 -0500 |
commit | c2b3178e0cae20a24bc9cc39a750bb864def17e3 (patch) | |
tree | ccdb4f78916cb4f07880d447042d77a20b5691d6 /jstests/noPassthrough/max_bson_depth_parameter.js | |
parent | b88ca5a851f4e24084da7b75b118f66430cb4421 (diff) | |
download | mongo-c2b3178e0cae20a24bc9cc39a750bb864def17e3.tar.gz |
SERVER-26703 reject commands exceeding the BSON depth limit
Any command sent to the server that exceeds the depth limit will fail. This also prevents users from
inserting documents that exceed the depth limit.
Diffstat (limited to 'jstests/noPassthrough/max_bson_depth_parameter.js')
-rw-r--r-- | jstests/noPassthrough/max_bson_depth_parameter.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/noPassthrough/max_bson_depth_parameter.js b/jstests/noPassthrough/max_bson_depth_parameter.js new file mode 100644 index 00000000000..337205d3134 --- /dev/null +++ b/jstests/noPassthrough/max_bson_depth_parameter.js @@ -0,0 +1,28 @@ +/** + * Tests that the server properly respects the maxBSONDepth parameter, and will fail to start up if + * given an invalid depth. + */ +(function() { + "use strict"; + + const kTestName = "max_bson_depth_parameter"; + + // Start mongod with a valid BSON depth, then test that it accepts and rejects command + // appropriately based on the depth. + let conn = MongoRunner.runMongod({setParameter: "maxBSONDepth=5"}); + assert.neq(null, conn, "Failed to start mongod"); + let testDB = conn.getDB("test"); + assert.commandWorked(testDB.runCommand({ping: 1}), "Failed to run a command on the server"); + assert.commandFailedWithCode( + testDB.runCommand({find: "coll", filter: {x: {x: {x: {x: {x: {x: 1}}}}}}}), + ErrorCodes.Overflow, + "Expected server to reject command for exceeding the nesting depth limit"); + + // Restart mongod with a negative maximum BSON depth and test that it fails to start. + MongoRunner.stopMongod(conn); + conn = MongoRunner.runMongod({setParameter: "maxBSONDepth=-4"}); + assert.eq(null, conn, "Expected mongod to fail at startup because depth was negative"); + + conn = MongoRunner.runMongod({setParameter: "maxBSONDepth=1"}); + assert.eq(null, conn, "Expected mongod to fail at startup because depth was too low"); +}()); |