summaryrefslogtreecommitdiff
path: root/jstests/auth/auth_options.js
blob: 36a76449f4b1d1ed912e0992ff1559c40de37941 (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
68
var baseName = "jstests_auth_auth_options";

function removeOptionsAddedByFramework(getCmdLineOptsResult) {
    // Remove options that we are not interested in checking, but that get set by the test
    delete getCmdLineOptsResult.parsed.setParameter
    delete getCmdLineOptsResult.parsed.storage
    delete getCmdLineOptsResult.parsed.net
    delete getCmdLineOptsResult.parsed.fastsync
    return getCmdLineOptsResult;
}

function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {

    // Start mongod with options
    var mongod = MongoRunner.runMongod(mongoRunnerConfig);

    // Get the parsed options
    var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
    printjson(getCmdLineOptsResult);

    // Remove options added by the test framework
    getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);

    // Make sure the options are equal to what we expect
    assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);

    // Cleanup
    MongoRunner.stopMongod(mongod.port);
}

jsTest.log("Testing \"auth\" command line option");
var expectedResult = {
    "parsed" : {
        "security" : {
            "authorization" : "enabled"
        }
    }
};
testGetCmdLineOpts({ auth : "" }, expectedResult);

jsTest.log("Testing \"noauth\" command line option");
expectedResult = {
    "parsed" : {
        "security" : {
            "authorization" : "disabled"
        }
    }
};
testGetCmdLineOpts({ noauth : "" }, expectedResult);

jsTest.log("Testing \"security.authorization\" config file option");
expectedResult = {
    "parsed" : {
        "config" : "jstests/libs/config_files/enable_auth.json",
        "security" : {
            "authorization" : "enabled"
        }
    }
};
testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_auth.json" }, expectedResult);

jsTest.log("Testing with no explicit object check setting");
expectedResult = {
    "parsed" : { }
};
testGetCmdLineOpts({}, expectedResult);

print(baseName + " succeeded.");