summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/auth_role_consistency.js
blob: 4ce7d3300f6974bb8717da75a066cecfe837cfd2 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';

/**
 * auth_role_consistency.js
 *
 * Add/revoke roles to/from other roles checking for cycles.
 * @tags: [incompatible_with_concurrency_simultaneous]
 */
load('jstests/concurrency/fsm_workload_helpers/drop_utils.js');  // for dropRoles

var $config = (function() {
    const kRoleNamePrefix = 'auth_role_consistency';

    const states = (function() {
        let roleA = kRoleNamePrefix + '_A_';
        let roleB = kRoleNamePrefix + '_B_';
        let roleAwDB = {};
        let roleBwDB = {};

        // Initial empty A/B roles.
        function init(db, collName) {
            roleA += this.tid;
            roleB += this.tid;
            roleAwDB = {role: roleA, db: db.getName()};
            roleBwDB = {role: roleB, db: db.getName()};

            db.createRole({role: roleA, privileges: [], roles: []});
            db.createRole({role: roleB, privileges: [], roles: []});
        }

        function shuffle(db, collName) {
            // Add A to B, then revoke it.
            db.grantRolesToRole(roleB, [roleAwDB]);
            db.revokeRolesFromRole(roleB, [roleAwDB]);

            // Add B to A, then revoke it.
            // Misordered applications will fassert.
            db.grantRolesToRole(roleA, [roleBwDB]);
            db.revokeRolesFromRole(roleA, [roleBwDB]);
        }

        return {init: init, shuffle: shuffle};
    })();

    function teardown(db, collName, cluster) {
        const pattern = new RegExp('^' + kRoleNamePrefix + '_[AB]_\\d+$');
        dropRoles(db, pattern);
    }

    return {
        threadCount: 50,
        iterations: 10,
        data: {},
        states: states,
        transitions: {init: {shuffle: 1}, shuffle: {shuffle: 1}},
        teardown: teardown,
    };
})();