diff options
author | David Storch <david.storch@10gen.com> | 2018-03-02 15:18:26 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2018-03-05 13:11:30 -0500 |
commit | 94db3aad060d11ddd799c9027f2bcbb342ddcccd (patch) | |
tree | d6e908b8160285e2e4e2ba37a87fa530e1fef50b /jstests | |
parent | 72ce569dd87b2eaf9d0a04ccb4c373037fd59fd4 (diff) | |
download | mongo-94db3aad060d11ddd799c9027f2bcbb342ddcccd.tar.gz |
SERVER-33624 Check for db mismatch when resolving UUIDs for read commands.
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/commands_with_uuid.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/jstests/core/commands_with_uuid.js b/jstests/core/commands_with_uuid.js index 817dc7a030b..2086d31cabb 100644 --- a/jstests/core/commands_with_uuid.js +++ b/jstests/core/commands_with_uuid.js @@ -5,8 +5,9 @@ (function() { 'use strict'; - let mainCollName = 'main_coll'; - let subCollName = 'sub_coll'; + const mainCollName = 'main_coll'; + const subCollName = 'sub_coll'; + const kOtherDbName = 'commands_with_uuid_db'; db.runCommand({drop: mainCollName}); db.runCommand({drop: subCollName}); assert.commandWorked(db.runCommand({create: mainCollName})); @@ -82,4 +83,26 @@ cmd = {parallelCollectionScan: uuid, numCursors: 1}; res = assert.commandWorked(db.runCommand(cmd), 'could not run ' + tojson(cmd)); assert.eq(res.cursors[0].cursor.ns, 'test.' + mainCollName); + + // Test that UUID resolution fails when the UUID belongs to a different database. First, we + // create a collection in another database. + const dbWithUUID = db.getSiblingDB(kOtherDbName); + dbWithUUID.getCollection(mainCollName).drop(); + assert.commandWorked(dbWithUUID.runCommand({create: mainCollName})); + collectionInfos = dbWithUUID.getCollectionInfos({name: mainCollName}); + uuid = collectionInfos[0].info.uuid; + assert.neq(null, uuid); + assert.commandWorked(dbWithUUID.runCommand({find: uuid})); + + // Run read commands supporting UUIDs against the original database, passing the UUID from a + // different database, and verify that the UUID resolution fails with the correct error code. We + // also test that the same command succeeds when there is no database mismatch. + for (cmd of[{count: uuid}, {distinct: uuid, key: "a"}, {find: uuid}, {listIndexes: uuid}, { + parallelCollectionScan: uuid, + numCursors: 1 + }]) { + assert.commandWorked(dbWithUUID.runCommand(cmd)); + assert.commandFailedWithCode( + db.runCommand(cmd), ErrorCodes.NamespaceNotFound, "command: " + tojson(cmd)); + } }()); |