summaryrefslogtreecommitdiff
path: root/jstests/core/list_commands.js
blob: a636e4861df7a2f8113c39e74cdd6c46ce1e830c (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
// Test for listCommands.
// @tags: [multiversion_incompatible]

(function() {
"use strict";

var commands = db.runCommand({listCommands: 1});
assert.commandWorked(commands);

// Test that result is sorted.
function isSorted(obj) {
    var previousProperty;
    for (var property in obj["commands"]) {
        if (previousProperty && (previousProperty > property)) {
            return false;
        }
        previousProperty = property;
    }
    return true;
}
assert(isSorted(commands));

// Test that result contains basic commands.
assert(commands.hasOwnProperty("commands"));
assert(commands["commands"].hasOwnProperty("hello"));
assert(commands["commands"].hasOwnProperty("isMaster"));
assert(commands["commands"].hasOwnProperty("insert"));
assert(commands["commands"].hasOwnProperty("ping"));

// Test that commands listed have required properties
const hello = commands["commands"]["hello"];
assert(hello.hasOwnProperty("help"));
assert(hello.hasOwnProperty("secondaryOk"));
assert(hello.hasOwnProperty("adminOnly"));
assert(hello.hasOwnProperty("requiresAuth"));

// Test that commands listed have required properties
const isMaster = commands["commands"]["isMaster"];
assert(isMaster.hasOwnProperty("help"));
assert(isMaster.hasOwnProperty("secondaryOk"));
assert(isMaster.hasOwnProperty("adminOnly"));
assert(isMaster.hasOwnProperty("requiresAuth"));

// Test that requiresAuth outputs correct value
const insert = commands["commands"]["insert"];
assert(hello["requiresAuth"] === false);
assert(isMaster["requiresAuth"] === false);
assert(insert["requiresAuth"] === true);
})();