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
|
/**
* Ensure that authorization system collections' indexes are correctly generated.
*
* This test requires users to persist across a restart.
* @tags: [requires_persistence]
*/
(function() {
let conn = MongoRunner.runMongod();
let config = conn.getDB("config");
let db = conn.getDB("admin");
// TEST: User and role collections start off with no indexes
assert.eq(0, db.system.users.getIndexes().length);
assert.eq(0, db.system.roles.getIndexes().length);
// TEST: User and role creation generates indexes
db.createUser({user: "user", pwd: "pwd", roles: []});
assert.eq(2, db.system.users.getIndexes().length);
db.createRole({role: "role", privileges: [], roles: []});
assert.eq(2, db.system.roles.getIndexes().length);
// TEST: Destroying admin.system.users index and restarting will recreate it
assert.commandWorked(db.system.users.dropIndexes());
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: conn, cleanData: false});
db = conn.getDB("admin");
assert.eq(2, db.system.users.getIndexes().length);
assert.eq(2, db.system.roles.getIndexes().length);
// TEST: Destroying admin.system.roles index and restarting will recreate it
assert.commandWorked(db.system.roles.dropIndexes());
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: conn, cleanData: false});
db = conn.getDB("admin");
assert.eq(2, db.system.users.getIndexes().length);
assert.eq(2, db.system.roles.getIndexes().length);
// TEST: Destroying both authorization indexes and restarting will recreate them
assert.commandWorked(db.system.users.dropIndexes());
assert.commandWorked(db.system.roles.dropIndexes());
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: conn, cleanData: false});
db = conn.getDB("admin");
assert.eq(2, db.system.users.getIndexes().length);
assert.eq(2, db.system.roles.getIndexes().length);
// TEST: Destroying the admin.system.users index and restarting will recreate it, even if
// admin.system.roles does not exist
// Use _mergeAuthzCollections to clear admin.system.users and admin.system.roles.
assert.commandWorked(db.adminCommand({
_mergeAuthzCollections: 1,
tempUsersCollection: 'admin.tempusers',
tempRolesCollection: 'admin.temproles',
db: "",
drop: true
}));
db.createUser({user: "user", pwd: "pwd", roles: []});
assert.commandWorked(db.system.users.dropIndexes());
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: conn, cleanData: false});
db = conn.getDB("admin");
assert.eq(2, db.system.users.getIndexes().length);
// TEST: Destroying the admin.system.roles index and restarting will recreate it, even if
// admin.system.users does not exist
// Use _mergeAuthzCollections to clear admin.system.users and admin.system.roles.
assert.commandWorked(db.adminCommand({
_mergeAuthzCollections: 1,
tempUsersCollection: 'admin.tempusers',
tempRolesCollection: 'admin.temproles',
db: "",
drop: true
}));
db.createRole({role: "role", privileges: [], roles: []});
assert.commandWorked(db.system.roles.dropIndexes());
MongoRunner.stopMongod(conn);
conn = MongoRunner.runMongod({restart: conn, cleanData: false});
db = conn.getDB("admin");
assert.eq(2, db.system.roles.getIndexes().length);
MongoRunner.stopMongod(conn);
})();
|