summaryrefslogtreecommitdiff
path: root/jstests/sharding/auth_no_config_primary.js
blob: 5d79df932a5f998a594b8af91df8eca307cdcc61 (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
/**
 * Tests authorization when a config server has no primary.
 *
 * This test cannot be run on ephemeral storage engines because it requires the users to persist
 * across a restart.
 * @tags: [requires_persistence]
 */

// Checking UUID consistency involves talking to the config server primary, but there is no config
// server primary by the end of this test.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;
TestData.skipCheckDBHashes = true;

(function() {
    'use strict';

    var st = new ShardingTest({shards: 1, other: {keyFile: 'jstests/libs/key1'}});

    st.s.getDB('admin').createUser({user: 'root', pwd: 'pass', roles: ['root']});
    st.s.getDB('admin').auth('root', 'pass');
    var testDB = st.s.getDB('test');
    testDB.user.insert({hello: 'world'});

    // Kill all secondaries, forcing the current primary to step down.
    st.configRS.getSecondaries().forEach(function(secondaryConn) {
        MongoRunner.stopMongod(secondaryConn);
    });

    // Test authenticate through a fresh connection.
    var newConn = new Mongo(st.s.host);

    assert.commandFailedWithCode(newConn.getDB('test').runCommand({find: 'user'}),
                                 ErrorCodes.Unauthorized);

    newConn.getDB('admin').auth('root', 'pass');

    var res = newConn.getDB('test').user.findOne();
    assert.neq(null, res);
    assert.eq('world', res.hello);

    // Test authenticate through new mongos.
    var otherMongos =
        MongoRunner.runMongos({keyFile: "jstests/libs/key1", configdb: st.s.savedOptions.configdb});

    assert.commandFailedWithCode(otherMongos.getDB('test').runCommand({find: 'user'}),
                                 ErrorCodes.Unauthorized);

    otherMongos.getDB('admin').auth('root', 'pass');

    var res = otherMongos.getDB('test').user.findOne();
    assert.neq(null, res);
    assert.eq('world', res.hello);

    st.stop();
})();