summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2022-12-05 21:51:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-05 22:46:07 +0000
commitdca926506ac48399abba8a764328c43d08b010a6 (patch)
tree686e2bf0bcd6ef01fbdaeff01301e1f36f1582b4
parent4b9a2fb18fc3e9ead1678c991468f1a125a8e100 (diff)
downloadmongo-dca926506ac48399abba8a764328c43d08b010a6.tar.gz
SERVER-69724 Test that all commands that return namespaces behave correctly in multitenant environment
-rw-r--r--jstests/serverless/native_tenant_data_isolation_basic_security_token.js25
-rw-r--r--src/mongo/db/query/explain.cpp2
2 files changed, 22 insertions, 5 deletions
diff --git a/jstests/serverless/native_tenant_data_isolation_basic_security_token.js b/jstests/serverless/native_tenant_data_isolation_basic_security_token.js
index db12b53591e..0a482d0c7cb 100644
--- a/jstests/serverless/native_tenant_data_isolation_basic_security_token.js
+++ b/jstests/serverless/native_tenant_data_isolation_basic_security_token.js
@@ -10,12 +10,13 @@ function checkNsSerializedCorrectly(
if (featureFlagRequireTenantId) {
// This case represents the upgraded state where we will not include the tenantId as the
// db prefix.
- const nss = kDbName + "." + kCollectionName;
+ const nss = kDbName + (kCollectionName == "" ? "" : "." + kCollectionName);
assert.eq(nsField, nss);
} else {
// This case represents the downgraded state where we will continue to prefix namespaces.
- const prefixedDb = kTenant + "_" + kDbName;
- assert.eq(nsField, prefixedDb + "." + kCollectionName);
+ const prefixedNss =
+ kTenant + "_" + kDbName + (kCollectionName == "" ? "" : "." + kCollectionName);
+ assert.eq(nsField, prefixedNss);
}
}
@@ -134,6 +135,11 @@ function runTest(featureFlagRequireTenantId) {
];
assert(arrayEq(expectedColls, colls.cursor.firstBatch),
tojson(colls.cursor.firstBatch));
+ checkNsSerializedCorrectly(featureFlagRequireTenantId,
+ kTenant,
+ kDbName,
+ "$cmd.listCollections",
+ colls.cursor.ns);
const prefixedDbName = kTenant + '_' + tokenDB.getName();
const targetDb = featureFlagRequireTenantId ? tokenDB.getName() : prefixedDbName;
@@ -173,6 +179,11 @@ function runTest(featureFlagRequireTenantId) {
{
const cmdRes = tokenDB.runCommand({explain: {find: kCollName, filter: {a: 1}}});
assert.eq(1, cmdRes.executionStats.nReturned, tojson(cmdRes));
+ checkNsSerializedCorrectly(featureFlagRequireTenantId,
+ kTenant,
+ kDbName,
+ kCollName,
+ cmdRes.queryPlanner.namespace);
}
// Test count and distinct command.
@@ -231,7 +242,11 @@ function runTest(featureFlagRequireTenantId) {
// Drop the collection, and then the database. Check that listCollections no longer returns
// the 3 collections.
{
- assert.commandWorked(tokenDB.runCommand({drop: kCollName}));
+ // Drop the collection, and check that the "ns" returned is serialized correctly.
+ const dropRes = assert.commandWorked(tokenDB.runCommand({drop: kCollName}));
+ checkNsSerializedCorrectly(
+ featureFlagRequireTenantId, kTenant, kDbName, kCollName, dropRes.ns);
+
const collsAfterDropColl = assert.commandWorked(tokenDB.runCommand(
{listCollections: 1, nameOnly: true, filter: {name: kCollName}}));
assert.eq(0,
@@ -296,6 +311,8 @@ function runTest(featureFlagRequireTenantId) {
{key: {b: 1}, name: "indexB"}
],
getIndexesKeyAndName(res.cursor.firstBatch)));
+ checkNsSerializedCorrectly(
+ featureFlagRequireTenantId, kTenant, kDbName, kCollName, res.cursor.ns);
// Drop those new created indexes.
res = assert.commandWorked(
diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp
index 9a460447ba8..545ec8553f4 100644
--- a/src/mongo/db/query/explain.cpp
+++ b/src/mongo/db/query/explain.cpp
@@ -86,7 +86,7 @@ void generatePlannerInfo(PlanExecutor* exec,
BSONObjBuilder* out) {
BSONObjBuilder plannerBob(out->subobjStart("queryPlanner"));
- plannerBob.append("namespace", exec->nss().ns());
+ plannerBob.append("namespace", NamespaceStringUtil::serialize(exec->nss()));
// Find whether there is an index filter set for the query shape. The 'indexFilterSet' field
// will always be false in the case of EOF or idhack plans.