diff options
author | Sophia Tan <sophia_tll@hotmail.com> | 2022-07-13 04:19:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-13 05:16:02 +0000 |
commit | 79b17eb848026e2b9d5ea3c5b99212ecc56157b9 (patch) | |
tree | d9ea90c3409b514420efc1be79556e7f821ca799 /jstests/serverless | |
parent | e9a3976b333ddecda7dd9c0f2f6f889699ca2706 (diff) | |
download | mongo-79b17eb848026e2b9d5ea3c5b99212ecc56157b9.tar.gz |
SERVER-65459 Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands
Diffstat (limited to 'jstests/serverless')
-rw-r--r-- | jstests/serverless/native_tenant_data_isolation_basic_cmds.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/jstests/serverless/native_tenant_data_isolation_basic_cmds.js b/jstests/serverless/native_tenant_data_isolation_basic_cmds.js new file mode 100644 index 00000000000..07103a71bf8 --- /dev/null +++ b/jstests/serverless/native_tenant_data_isolation_basic_cmds.js @@ -0,0 +1,43 @@ +// Test basic db operations in multitenancy. + +(function() { +"use strict"; + +let mongod = MongoRunner.runMongod( + {auth: '', setParameter: {multitenancySupport: true, featureFlagMongoStore: true}}); +let adminDb = mongod.getDB('admin'); + +// Prepare a user for testing pass tenant via $tenant. +// Must be authenticated as a user with ActionType::useTenant in order to use $tenant. +assert.commandWorked(adminDb.runCommand({createUser: 'admin', pwd: 'pwd', roles: ['root']})); +assert(adminDb.auth('admin', 'pwd')); + +{ + // Test the IDL defined commands with $tenant. + const kTenant = ObjectId(); + let testDb = mongod.getDB('myDb0'); + let testColl = testDb.getCollection('myColl0'); + + // Create a collection for the tenant kTenant. + assert.commandWorked( + testColl.getDB().createCollection(testColl.getName(), {'$tenant': kTenant})); + + // Insert a document to the collection. + assert.commandWorked(testDb.runCommand( + {insert: 'myColl0', documents: [{_id: 0, a: 1, b: 1}], '$tenant': kTenant})); + + // Find and modify the document. + let fad = assert.commandWorked(testDb.runCommand( + {findAndModify: "myColl0", query: {a: 1}, update: {$inc: {a: 10}}, '$tenant': kTenant})); + assert.eq({_id: 0, a: 1, b: 1}, fad.value); + fad = assert.commandWorked(testDb.runCommand( + {findAndModify: "myColl0", query: {a: 11}, update: {$inc: {a: 10}}, '$tenant': kTenant})); + assert.eq({_id: 0, a: 11, b: 1}, fad.value); + // This document should not be accessed with a different tenant. + fad = assert.commandWorked(testDb.runCommand( + {findAndModify: "myColl0", query: {b: 1}, update: {$inc: {b: 10}}, '$tenant': ObjectId()})); + assert.eq(null, fad.value); +} + +MongoRunner.stopMongod(mongod); +})(); |