summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-02-15 05:53:54 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-15 06:20:36 +0000
commitd02536f48aee7593077c12b1e60829b9441a7c08 (patch)
tree3e07a27328b7d2191e02159c44ef18b9ca6e3d68 /jstests/aggregation
parent9e354a640fd52d5ecfbaabb305eea25d21956a38 (diff)
downloadmongo-d02536f48aee7593077c12b1e60829b9441a7c08.tar.gz
SERVER-63528 Use db and collection instead of namespace in CollectionUUIDMismatch error response
Diffstat (limited to 'jstests/aggregation')
-rw-r--r--jstests/aggregation/aggregation_with_uuids.js16
-rw-r--r--jstests/aggregation/collection_uuid_coll_stats_index_stats.js29
2 files changed, 30 insertions, 15 deletions
diff --git a/jstests/aggregation/aggregation_with_uuids.js b/jstests/aggregation/aggregation_with_uuids.js
index 52bcc99545f..b5f70c54c89 100644
--- a/jstests/aggregation/aggregation_with_uuids.js
+++ b/jstests/aggregation/aggregation_with_uuids.js
@@ -16,10 +16,12 @@ const collName = "foo";
const testDB = db.getSiblingDB(dbName);
const testColl = testDB.getCollection(collName);
-const validateErrorResponse = function(res, collectionUUID, expectedNamespace, actualNamespace) {
+const validateErrorResponse = function(
+ res, db, collectionUUID, expectedCollection, actualCollection) {
+ assert.eq(res.db, db);
assert.eq(res.collectionUUID, collectionUUID);
- assert.eq(res.expectedNamespace, expectedNamespace);
- assert.eq(res.actualNamespace, actualNamespace);
+ assert.eq(res.expectedCollection, expectedCollection);
+ assert.eq(res.actualCollection, actualCollection);
};
// On mongos, collectionUUID is only supported for $collStats and $indexStats aggregations.
@@ -69,7 +71,7 @@ let res = assert.commandFailedWithCode(
testDB.runCommand(
{aggregate: "doesNotExist", collectionUUID: uuid, pipeline: [{$match: {}}], cursor: {}}),
ErrorCodes.CollectionUUIDMismatch);
-validateErrorResponse(res, uuid, testDB.getName() + '.doesNotExist', testColl.getFullName());
+validateErrorResponse(res, dbName, uuid, 'doesNotExist', testColl.getName());
// Drop the collection.
testColl.drop({writeConcern: {w: "majority"}});
@@ -79,7 +81,7 @@ res = assert.commandFailedWithCode(
testDB.runCommand(
{aggregate: collName, collectionUUID: uuid, pipeline: [{$match: {}}], cursor: {}}),
ErrorCodes.CollectionUUIDMismatch);
-validateErrorResponse(res, uuid, testColl.getFullName(), null);
+validateErrorResponse(res, dbName, uuid, testColl.getName(), null);
// Now recreate the collection.
assert.commandWorked(testColl.insert(docs));
@@ -89,7 +91,7 @@ res = assert.commandFailedWithCode(
testDB.runCommand(
{aggregate: collName, collectionUUID: uuid, pipeline: [{$match: {}}], cursor: {}}),
ErrorCodes.CollectionUUIDMismatch);
-validateErrorResponse(res, uuid, testColl.getFullName(), null);
+validateErrorResponse(res, dbName, uuid, testColl.getName(), null);
collNameRes = assert.commandWorked(
testDB.runCommand({aggregate: collName, pipeline: [{$match: {}}], cursor: {}}));
@@ -106,7 +108,7 @@ res = assert.commandFailedWithCode(
testDB.runCommand(
{aggregate: "viewCollection", collectionUUID: uuid, pipeline: [{$match: {}}], cursor: {}}),
ErrorCodes.CollectionUUIDMismatch);
-validateErrorResponse(res, uuid, testDB.getName() + '.viewCollection', null);
+validateErrorResponse(res, dbName, uuid, 'viewCollection', null);
//
// Tests for rejecting invalid collectionUUIDs and cases where collectionUUID is not allowed.
diff --git a/jstests/aggregation/collection_uuid_coll_stats_index_stats.js b/jstests/aggregation/collection_uuid_coll_stats_index_stats.js
index 3ad76a86a5b..5aa92524652 100644
--- a/jstests/aggregation/collection_uuid_coll_stats_index_stats.js
+++ b/jstests/aggregation/collection_uuid_coll_stats_index_stats.js
@@ -5,10 +5,12 @@
(function() {
'use strict';
-const validateErrorResponse = function(res, collectionUUID, expectedNamespace, actualNamespace) {
+const validateErrorResponse = function(
+ res, db, collectionUUID, expectedCollection, actualCollection) {
+ assert.eq(res.db, db);
assert.eq(res.collectionUUID, collectionUUID);
- assert.eq(res.expectedNamespace, expectedNamespace);
- assert.eq(res.actualNamespace, actualNamespace);
+ assert.eq(res.expectedCollection, expectedCollection);
+ assert.eq(res.actualCollection, actualCollection);
};
const testCommand = function(cmd, cmdObj) {
@@ -32,7 +34,7 @@ const testCommand = function(cmd, cmdObj) {
cmdObj["collectionUUID"] = nonexistentUUID;
let res =
assert.commandFailedWithCode(testDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
- validateErrorResponse(res, nonexistentUUID, coll.getFullName(), null);
+ validateErrorResponse(res, testDB.getName(), nonexistentUUID, coll.getName(), null);
jsTestLog("The command '" + cmd +
"' fails when the provided UUID corresponds to a different collection.");
@@ -42,7 +44,7 @@ const testCommand = function(cmd, cmdObj) {
cmdObj["collectionUUID"] = uuid;
res =
assert.commandFailedWithCode(testDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
- validateErrorResponse(res, uuid, coll2.getFullName(), coll.getFullName());
+ validateErrorResponse(res, testDB.getName(), uuid, coll2.getName(), coll.getName());
jsTestLog("The command '" + cmd +
"' fails when the provided UUID corresponds to a different collection, even if the " +
@@ -50,7 +52,7 @@ const testCommand = function(cmd, cmdObj) {
coll2.drop();
res =
assert.commandFailedWithCode(testDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
- validateErrorResponse(res, uuid, coll2.getFullName(), coll.getFullName());
+ validateErrorResponse(res, testDB.getName(), uuid, coll2.getName(), coll.getName());
jsTestLog("The command '" + cmd + "' succeeds on view when no UUID is provided.");
const viewName = "view";
@@ -67,7 +69,7 @@ const testCommand = function(cmd, cmdObj) {
cmdObj["collectionUUID"] = uuid;
res =
assert.commandFailedWithCode(testDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
- validateErrorResponse(res, uuid, testDB.getName() + '.' + viewName, coll.getFullName());
+ validateErrorResponse(res, testDB.getName(), uuid, viewName, coll.getName());
assert.commandWorked(testDB.runCommand({drop: viewName, writeConcern: {w: "majority"}}));
jsTestLog("The command '" + cmd +
@@ -85,8 +87,19 @@ const testCommand = function(cmd, cmdObj) {
cmdObj["collectionUUID"] = uuid;
res =
assert.commandFailedWithCode(testDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
- validateErrorResponse(res, uuid, testDB.getName() + '.' + tsCollName, coll.getFullName());
+ validateErrorResponse(res, testDB.getName(), uuid, tsCollName, coll.getName());
assert.commandWorked(testDB.runCommand({drop: tsCollName, writeConcern: {w: "majority"}}));
+
+ jsTestLog("Only collections in the same database are specified by actualCollection.");
+ const otherDB = testDB.getSiblingDB(testDB.getName() + '_2');
+ assert.commandWorked(otherDB.dropDatabase());
+ assert.commandWorked(otherDB.dropDatabase());
+ const coll3 = otherDB['coll_3'];
+ assert.commandWorked(coll3.insert({_id: 2}));
+ cmdObj[cmd] = coll3.getName();
+ res =
+ assert.commandFailedWithCode(otherDB.runCommand(cmdObj), ErrorCodes.CollectionUUIDMismatch);
+ validateErrorResponse(res, otherDB.getName(), uuid, coll3.getName(), null);
};
testCommand("aggregate", {aggregate: "", pipeline: [{$indexStats: {}}], cursor: {}});