summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/auth_drop_role.js
blob: d41066dbc63ebdf42cbba9ab66a9996ba6f06797 (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
59
60
61
62
63
64
65
66
67
'use strict';

/**
 * auth_drop_role.js
 *
 * Repeatedly creates a new role on a database, and subsequently
 * drops it from the database.
 */
load('jstests/concurrency/fsm_workload_helpers/drop_utils.js');  // for dropRoles

var $config = (function() {

    var data = {
        // Use the workload name as a prefix for the role name,
        // since the workload name is assumed to be unique.
        prefix: 'auth_drop_role'
    };

    var states = (function() {

        function uniqueRoleName(prefix, tid, num) {
            return prefix + tid + '_' + num;
        }

        function init(db, collName) {
            this.num = 0;
        }

        function createAndDropRole(db, collName) {
            var roleName = uniqueRoleName(this.prefix, this.tid, this.num++);
            db.createRole({
                role: roleName,
                privileges:
                    [{resource: {db: db.getName(), collection: collName}, actions: ['remove']}],
                roles: [{role: 'read', db: db.getName()}]
            });

            var res = db.getRole(roleName);
            assertAlways(res !== null, "role '" + roleName + "' should exist");
            assertAlways.eq(roleName, res.role);
            assertAlways(!res.isBuiltin, 'role should be user-defined');

            assertAlways(db.dropRole(roleName));
            assertAlways.isnull(db.getRole(roleName), "role '" + roleName + "' should not exist");
        }

        return {
            init: init,
            createAndDropRole: createAndDropRole
        };

    })();

    var transitions = {
        init: {createAndDropRole: 1},
        createAndDropRole: {createAndDropRole: 1}
    };

    return {
        threadCount: 10,
        iterations: 20,
        data: data,
        states: states,
        transitions: transitions
    };

})();