summaryrefslogtreecommitdiff
path: root/jstests/slow1/large_role_chain.js
blob: 581db988be5e7651b23105cbe67f1b40619ca03f (plain)
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
// Tests SERVER-11475 - Make sure server does't crash when many user defined roles are created where
// each role is a member of the next, creating a large chain.

function runTest(conn) {

    var testdb = conn.getDB("rolechain");
    testdb.runCommand({dropAllRolesFromDatabase:1});
    var chainLen = 2000;


    jsTestLog("Generating a chain of " + chainLen + " linked roles");

    var roleNameBase = "chainRole";
    for (var i = 0; i < chainLen; i++) {
        var name = roleNameBase + i;
        if (i == 0) {
            testdb.runCommand({createRole: name, privileges: [], roles: []});
        }
        else {
            jsTestLog("Creating role " + i);
            var prevRole = roleNameBase + (i - 1);
            testdb.runCommand({createRole: name, privileges: [], roles: [ prevRole ]});
            var roleInfo = testdb.getRole(name);
        }
    }

}

// run all tests standalone
var conn = MongoRunner.runMongod();
runTest(conn);
MongoRunner.stopMongod(conn);

// run all tests sharded
conn = new ShardingTest({shards: 2, mongos: 1, config: 3});
runTest(conn);
conn.stop();