@@ -20,6 +20,7 @@ if (featureFlagRequireTenantId) {
20
20
* tenantId.
21
21
*/
22
22
function runFindOnPrefixedDb ( conn , prefixedDb , collName , expectedDocsReturned ) {
23
+ conn . _setSecurityToken ( undefined ) ;
23
24
const res =
24
25
assert . commandWorked ( conn . getDB ( prefixedDb ) . runCommand ( { find : collName , filter : { } } ) ) ;
25
26
assert ( arrayEq ( expectedDocsReturned , res . cursor . firstBatch ) , tojson ( res ) ) ;
@@ -31,34 +32,35 @@ function runFindOnPrefixedDb(conn, prefixedDb, collName, expectedDocsReturned) {
31
32
* Runs a findAndModify using a prefixed db.
32
33
*/
33
34
function runFindAndModOnPrefixedDb ( conn , prefixedDb , collName , query , update , expectedDocReturned ) {
35
+ conn . _setSecurityToken ( undefined ) ;
34
36
const res = assert . commandWorked (
35
37
conn . getDB ( prefixedDb ) . runCommand ( { findAndModify : collName , query : query , update : update } ) ) ;
36
38
assert . eq ( res . value , expectedDocReturned ) ;
37
39
}
38
40
39
41
/*
40
- * Runs a find using $tenant , and asserts the find returns 'expectedDocsReturned'. Also
41
- * checks that the "ns" returned in the cursor result is serialized as expected, without the
42
+ * Runs a find using unsigned security token , and asserts the find returns 'expectedDocsReturned'.
43
+ * Also checks that the "ns" returned in the cursor result is serialized as expected, without the
42
44
* tenantId.
43
45
*/
44
- function runFindUsingDollarTenant ( conn , db , collName , tenantId , expectedDocsReturned ) {
45
- const res = assert . commandWorked (
46
- conn . getDB ( db ) . runCommand ( { find : collName , filter : { } , $tenant : tenantId } ) ) ;
46
+ function runFindUsingSecurityToken ( conn , db , collName , token , expectedDocsReturned ) {
47
+ conn . _setSecurityToken ( token ) ;
48
+ const res = assert . commandWorked ( conn . getDB ( db ) . runCommand ( { find : collName , filter : { } } ) ) ;
47
49
assert ( arrayEq ( expectedDocsReturned , res . cursor . firstBatch ) , tojson ( res ) ) ;
48
50
const namespace = db + "." + collName ;
49
51
assert . eq ( res . cursor . ns , namespace ) ;
50
52
}
51
53
52
54
/*
53
- * Runs a find using $tenant and prefixed db, and asserts the find returns
55
+ * Runs a find using unsigned security token and prefixed db, and asserts the find returns
54
56
* 'expectedDocsReturned'. Also checks that the "ns" returned in the cursor result is serialized
55
57
* as expected, including the tenantId.
56
58
*/
57
- function runFindUsingDollarTenantAndPrefix (
58
- conn , prefixedDb , collName , tenantId , expectedDocsReturned ) {
59
+ function runFindUsingSecurityTokenAndPrefix (
60
+ conn , prefixedDb , collName , token , expectedDocsReturned ) {
61
+ conn . _setSecurityToken ( token ) ;
59
62
const res = assert . commandWorked (
60
- conn . getDB ( prefixedDb )
61
- . runCommand ( { find : collName , filter : { } , $tenant : tenantId , expectPrefix : true } ) ) ;
63
+ conn . getDB ( prefixedDb ) . runCommand ( { find : collName , filter : { } , expectPrefix : true } ) ) ;
62
64
assert ( arrayEq ( expectedDocsReturned , res . cursor . firstBatch ) , tojson ( res ) ) ;
63
65
const prefixedNamespace = prefixedDb + "." + collName ;
64
66
assert . eq ( res . cursor . ns , prefixedNamespace ) ;
@@ -78,15 +80,10 @@ function assertFindBothTenantsPrefixedDb(
78
80
* Runs a find for both tenants using a prefixed db, and asserts the find returns
79
81
* 'expectedDocsReturned'.
80
82
*/
81
- function assertFindBothTenantsUsingDollarTenant ( conn ,
82
- db ,
83
- collName ,
84
- tenantId1 ,
85
- tenantId2 ,
86
- expectedDocsReturnedTenant1 ,
87
- expectedDocsReturnedTenant2 ) {
88
- runFindUsingDollarTenant ( conn , db , collName , tenantId1 , expectedDocsReturnedTenant1 ) ;
89
- runFindUsingDollarTenant ( conn , db , collName , tenantId2 , expectedDocsReturnedTenant2 ) ;
83
+ function assertFindBothTenantsUsingSecurityToken (
84
+ conn , db , collName , token1 , token2 , expectedDocsReturnedTenant1 , expectedDocsReturnedTenant2 ) {
85
+ runFindUsingSecurityToken ( conn , db , collName , token1 , expectedDocsReturnedTenant1 ) ;
86
+ runFindUsingSecurityToken ( conn , db , collName , token2 , expectedDocsReturnedTenant2 ) ;
90
87
}
91
88
92
89
const rst = new ReplSetTest ( {
@@ -106,6 +103,9 @@ const kTenant2 = ObjectId();
106
103
const kDbName = "test" ;
107
104
const kCollName = "foo" ;
108
105
106
+ const kToken1 = _createTenantToken ( { tenant : kTenant1 } ) ;
107
+ const kToken2 = _createTenantToken ( { tenant : kTenant2 } ) ;
108
+
109
109
// Create a root user and login on both the primary and secondary.
110
110
const primaryAdminDb = originalPrimary . getDB ( 'admin' ) ;
111
111
let secondaryAdminDb = originalSecondary . getDB ( 'admin' ) ;
@@ -147,16 +147,16 @@ assertFindBothTenantsPrefixedDb(
147
147
originalSecondary , tenant1DbPrefixed , tenant2DbPrefixed , kCollName , tenant1Docs , tenant2Docs ) ;
148
148
149
149
// Now check that we find the docs for both tenants when reading from the secondary using
150
- // $tenant and a security token. The primary does not yet support $tenant or a security token
150
+ // a security token. The primary does not yet support a security token
151
151
// since it does not have multitenancySupport enabled.
152
- assertFindBothTenantsUsingDollarTenant (
153
- originalSecondary , kDbName , kCollName , kTenant1 , kTenant2 , tenant1Docs , tenant2Docs ) ;
152
+ assertFindBothTenantsUsingSecurityToken (
153
+ originalSecondary , kDbName , kCollName , kToken1 , kToken2 , tenant1Docs , tenant2Docs ) ;
154
154
155
- // Also assert both tenants find the new doc on the secondary using $tenant and a prefixed db.
156
- runFindUsingDollarTenantAndPrefix (
157
- originalSecondary , tenant1DbPrefixed , kCollName , kTenant1 , tenant1Docs ) ;
158
- runFindUsingDollarTenantAndPrefix (
159
- originalSecondary , tenant2DbPrefixed , kCollName , kTenant2 , tenant2Docs ) ;
155
+ // Also assert both tenants find the new doc on the secondary using token and a prefixed db.
156
+ runFindUsingSecurityTokenAndPrefix (
157
+ originalSecondary , tenant1DbPrefixed , kCollName , kToken1 , tenant1Docs ) ;
158
+ runFindUsingSecurityTokenAndPrefix (
159
+ originalSecondary , tenant2DbPrefixed , kCollName , kToken2 , tenant2Docs ) ;
160
160
161
161
// Now insert a new doc for both tenants using the prefixed db, and assert that we can find it
162
162
// on both the primary and secondary.
@@ -185,18 +185,18 @@ assertFindBothTenantsPrefixedDb(originalSecondary,
185
185
allTenant1Docs ,
186
186
allTenant2Docs ) ;
187
187
188
- // Assert both tenants find the new doc on the secondary using $tenant .
189
- assertFindBothTenantsUsingDollarTenant (
190
- originalSecondary , kDbName , kCollName , kTenant1 , kTenant2 , allTenant1Docs , allTenant2Docs ) ;
188
+ // Assert both tenants find the new doc on the secondary using token .
189
+ assertFindBothTenantsUsingSecurityToken (
190
+ originalSecondary , kDbName , kCollName , kToken1 , kToken2 , allTenant1Docs , allTenant2Docs ) ;
191
191
192
- // Assert both tenants find the new doc on the secondary using $tenant and a prefixed db.
193
- runFindUsingDollarTenantAndPrefix (
194
- originalSecondary , tenant1DbPrefixed , kCollName , kTenant1 , allTenant1Docs ) ;
195
- runFindUsingDollarTenantAndPrefix (
196
- originalSecondary , tenant2DbPrefixed , kCollName , kTenant2 , allTenant2Docs ) ;
192
+ // Assert both tenants find the new doc on the secondary using token and a prefixed db.
193
+ runFindUsingSecurityTokenAndPrefix (
194
+ originalSecondary , tenant1DbPrefixed , kCollName , kToken1 , allTenant1Docs ) ;
195
+ runFindUsingSecurityTokenAndPrefix (
196
+ originalSecondary , tenant2DbPrefixed , kCollName , kToken2 , allTenant2Docs ) ;
197
197
198
198
// Now run findAndModify on one doc using a prefixed db and check that we can read from the
199
- // secondary using just $tenant and $tenant and a prefix.
199
+ // secondary using just token and a prefix.
200
200
runFindAndModOnPrefixedDb ( originalPrimary ,
201
201
tenant1DbPrefixed ,
202
202
kCollName ,
@@ -212,18 +212,18 @@ runFindAndModOnPrefixedDb(originalPrimary,
212
212
213
213
const modifiedTenant1Docs = tenant1Docs . concat ( [ { _id : 2 , x : 4 } ] ) ;
214
214
const modifiedTenant2Docs = tenant2Docs . concat ( [ { _id : 12 , a : 40 } ] ) ;
215
- assertFindBothTenantsUsingDollarTenant ( originalSecondary ,
216
- kDbName ,
217
- kCollName ,
218
- kTenant1 ,
219
- kTenant2 ,
220
- modifiedTenant1Docs ,
221
- modifiedTenant2Docs ) ;
222
-
223
- runFindUsingDollarTenantAndPrefix (
224
- originalSecondary , tenant1DbPrefixed , kCollName , kTenant1 , modifiedTenant1Docs ) ;
225
- runFindUsingDollarTenantAndPrefix (
226
- originalSecondary , tenant2DbPrefixed , kCollName , kTenant2 , modifiedTenant2Docs ) ;
215
+ assertFindBothTenantsUsingSecurityToken ( originalSecondary ,
216
+ kDbName ,
217
+ kCollName ,
218
+ kToken1 ,
219
+ kToken2 ,
220
+ modifiedTenant1Docs ,
221
+ modifiedTenant2Docs ) ;
222
+
223
+ runFindUsingSecurityTokenAndPrefix (
224
+ originalSecondary , tenant1DbPrefixed , kCollName , kToken1 , modifiedTenant1Docs ) ;
225
+ runFindUsingSecurityTokenAndPrefix (
226
+ originalSecondary , tenant2DbPrefixed , kCollName , kToken2 , modifiedTenant2Docs ) ;
227
227
228
228
// Now, restart the primary and enable multitenancySupport. The secondary will step up to
229
229
// become primary.
@@ -250,31 +250,33 @@ assertFindBothTenantsPrefixedDb(originalSecondary,
250
250
modifiedTenant2Docs ) ;
251
251
252
252
// Now check that we find the docs for both tenants when reading from both the primary and
253
- // secondary using $tenant.
254
- assertFindBothTenantsUsingDollarTenant ( originalPrimary ,
255
- kDbName ,
256
- kCollName ,
257
- kTenant1 ,
258
- kTenant2 ,
259
- modifiedTenant1Docs ,
260
- modifiedTenant2Docs ) ;
261
- assertFindBothTenantsUsingDollarTenant ( originalSecondary ,
262
- kDbName ,
263
- kCollName ,
264
- kTenant1 ,
265
- kTenant2 ,
266
- modifiedTenant1Docs ,
267
- modifiedTenant2Docs ) ;
268
-
269
- // Also check that both tenants find the new doc on the primary and secondary using $tenant and
270
- // a prefixed db.
271
- runFindUsingDollarTenantAndPrefix (
272
- originalPrimary , tenant1DbPrefixed , kCollName , kTenant1 , modifiedTenant1Docs ) ;
273
- runFindUsingDollarTenantAndPrefix (
274
- originalSecondary , tenant2DbPrefixed , kCollName , kTenant2 , modifiedTenant2Docs ) ;
275
- runFindUsingDollarTenantAndPrefix (
276
- originalPrimary , tenant1DbPrefixed , kCollName , kTenant1 , modifiedTenant1Docs ) ;
277
- runFindUsingDollarTenantAndPrefix (
278
- originalSecondary , tenant2DbPrefixed , kCollName , kTenant2 , modifiedTenant2Docs ) ;
279
-
253
+ // secondary using token.
254
+ assertFindBothTenantsUsingSecurityToken ( originalPrimary ,
255
+ kDbName ,
256
+ kCollName ,
257
+ kToken1 ,
258
+ kToken2 ,
259
+ modifiedTenant1Docs ,
260
+ modifiedTenant2Docs ) ;
261
+ assertFindBothTenantsUsingSecurityToken ( originalSecondary ,
262
+ kDbName ,
263
+ kCollName ,
264
+ kToken1 ,
265
+ kToken2 ,
266
+ modifiedTenant1Docs ,
267
+ modifiedTenant2Docs ) ;
268
+
269
+ // Also check that both tenants find the new doc on the primary and secondary using token and a
270
+ // prefixed db.
271
+ runFindUsingSecurityTokenAndPrefix (
272
+ originalPrimary , tenant1DbPrefixed , kCollName , kToken1 , modifiedTenant1Docs ) ;
273
+ runFindUsingSecurityTokenAndPrefix (
274
+ originalSecondary , tenant2DbPrefixed , kCollName , kToken2 , modifiedTenant2Docs ) ;
275
+ runFindUsingSecurityTokenAndPrefix (
276
+ originalPrimary , tenant1DbPrefixed , kCollName , kToken1 , modifiedTenant1Docs ) ;
277
+ runFindUsingSecurityTokenAndPrefix (
278
+ originalSecondary , tenant2DbPrefixed , kCollName , kToken2 , modifiedTenant2Docs ) ;
279
+
280
+ originalPrimary . _setSecurityToken ( undefined ) ;
281
+ originalSecondary . _setSecurityToken ( undefined ) ;
280
282
rst . stopSet ( ) ;
0 commit comments