diff options
author | Ian Boros <ian.boros@10gen.com> | 2018-12-19 18:28:59 -0500 |
---|---|---|
committer | Ian Boros <ian.boros@10gen.com> | 2019-01-09 11:54:50 -0500 |
commit | 722f06f3217c029ef9c50062c8cc775966fd7ead (patch) | |
tree | bf5a58dd05c538de5679320cef5c450964c815da /jstests/core/explain_uuid.js | |
parent | 4b1afd3e3873b8b46804264e38bb39e0423f54dd (diff) | |
download | mongo-722f06f3217c029ef9c50062c8cc775966fd7ead.tar.gz |
SERVER-38275 ban find explain with UUID
Diffstat (limited to 'jstests/core/explain_uuid.js')
-rw-r--r-- | jstests/core/explain_uuid.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/jstests/core/explain_uuid.js b/jstests/core/explain_uuid.js new file mode 100644 index 00000000000..be5e9e01adb --- /dev/null +++ b/jstests/core/explain_uuid.js @@ -0,0 +1,56 @@ +/** + * Test that running explain() providing a collection UUID rather than collection name will fail + * cleanly. + */ +(function() { + "use strict"; + + // Use our own database so that we're guaranteed the only collection is this one. + const explainDB = db.getSiblingDB("explain_uuid_db"); + + assert.commandWorked(explainDB.dropDatabase()); + + const coll = explainDB.explain_uuid; + assert.commandWorked(coll.insert({a: 1})); + + const collInfos = explainDB.getCollectionInfos({name: coll.getName()}); + assert.eq(collInfos.length, 1, collInfos); + const uuid = collInfos[0].info.uuid; + + // Run a find explain looking up by UUID. + assert.commandFailedWithCode(explainDB.runCommand({explain: {find: uuid}}), + ErrorCodes.InvalidNamespace); + + // Do similar for other commands. + assert.commandFailedWithCode(explainDB.runCommand({explain: {aggregate: uuid, cursor: {}}}), + ErrorCodes.TypeMismatch); + + assert.commandFailedWithCode(explainDB.runCommand({explain: {count: uuid}}), + ErrorCodes.InvalidNamespace); + + assert.commandFailedWithCode(explainDB.runCommand({explain: {distinct: uuid, key: "x"}}), + ErrorCodes.InvalidNamespace); + + // When auth is enabled, running findAndModify with an invalid namespace will produce a special + // error during the auth check, rather than the generic 'InvalidNamespace' error. + const expectedCode = TestData.auth ? 17137 : ErrorCodes.InvalidNamespace; + assert.commandFailedWithCode( + explainDB.runCommand({explain: {findAndModify: uuid, query: {a: 1}, remove: true}}), + expectedCode); + + assert.commandFailedWithCode( + explainDB.runCommand({explain: {delete: uuid, deletes: [{q: {}, limit: 1}]}}), + ErrorCodes.BadValue); + + assert.commandFailedWithCode(explainDB.runCommand({ + explain: { + update: uuid, + updates: [{ + q: {a: 1}, + u: {$set: {b: 1}}, + }] + } + }), + ErrorCodes.BadValue); + +})(); |