-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathinvalid_tenant_requests.js
89 lines (71 loc) · 2.54 KB
/
invalid_tenant_requests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {ReplSetTest} from "jstests/libs/replsettest.js";
const tenant = '636d957b2646ddfaf9b5e13f';
const kVTSKey = 'secret';
const insertCmd = {
insert: 'some_collection',
documents: [{_id: 0}]
};
function createnewReplSetTest(param) {
const rst = new ReplSetTest({nodes: 1, nodeOptions: {auth: '', setParameter: param}});
rst.startSet({keyFile: 'jstests/libs/key1'});
rst.initiate();
return rst;
}
function setupNewReplSetWithParam(param) {
let rst = createnewReplSetTest(param);
let primary = rst.getPrimary();
let adminDb = primary.getDB('admin');
assert.commandWorked(adminDb.runCommand({createUser: 'admin', pwd: 'pwd', roles: ['root']}));
assert(adminDb.auth('admin', 'pwd'));
return rst;
}
function createAndSetSecurityToken(primary) {
const kTenantID = ObjectId(tenant);
if (typeof primary._securityToken == 'undefined') {
const tenantToken = _createTenantToken({tenant: kTenantID, expectPrefix: true});
primary._setSecurityToken(tenantToken);
}
}
function securityTokenMissing(primary) {
const db = primary.getDB(tenant + "_SecTokenMissing");
assert.commandFailedWithCode(db.runCommand(insertCmd), 8233503);
}
function tenantPrefixMissing(primary) {
const db = primary.getDB("TenantPrefixMissing");
assert.commandFailedWithCode(db.runCommand(insertCmd), 8423386);
}
function unmatchedTenantInfo(primary) {
const unmatchingTenant = '636d957b2646ddfaf9b5e13a';
const db = primary.getDB(unmatchingTenant + "_UnmatchedTenantInfo");
assert.commandFailedWithCode(db.runCommand(insertCmd), 8423384);
}
function invalidTenantPrefix(primary) {
const invalidTenant = '636d95';
const db = primary.getDB(invalidTenant + "_InvalidTenantPrefix");
assert.commandFailedWithCode(db.runCommand(insertCmd), 8423386);
}
function tenantMustBeSet(primary) {
const db = primary.getDB("tenantMustBeSet");
assert.commandFailedWithCode(db.runCommand(insertCmd), 8423388);
}
function runTests() {
let rst = setupNewReplSetWithParam({
multitenancySupport: true,
featureFlagSecurityToken: true,
testOnlyValidatedTenancyScopeKey: kVTSKey,
});
let primary = rst.getPrimary();
securityTokenMissing(primary);
createAndSetSecurityToken(primary);
tenantPrefixMissing(primary);
unmatchedTenantInfo(primary);
invalidTenantPrefix(primary);
rst.stopSet();
rst = setupNewReplSetWithParam({
multitenancySupport: true,
});
primary = rst.getPrimary();
tenantMustBeSet(primary);
rst.stopSet();
}
runTests();