summaryrefslogtreecommitdiff
path: root/jstests/sharding/authConnectionHook.js
blob: 6655d4d5248983e0b0cf611af584fa8e4bcd2ffc (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
/**
 * Test for SERVER-8786 - if the first operation on an authenticated shard is moveChunk, it breaks
 * the cluster.
 *
 * Any tests that restart a shard mongod and send sharding requests to it after restart cannot make
 * the shard use an in-memory storage engine, since the shardIdentity document will be lost after
 * restart.
 *
 * @tags: [requires_persistence]
 */

// The UUID consistency check uses connections to shards cached on the ShardingTest object, but this
// test restarts a shard, so the cached connection is not usable.
TestData.skipCheckingUUIDsConsistentAcrossCluster = true;

(function() {
    'use strict';

    // TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
    var st = new ShardingTest({
        shards: 2,
        other: {
            keyFile: 'jstests/libs/key1',
            useHostname: true,
            chunkSize: 1,
            shardAsReplicaSet: false
        }
    });

    var mongos = st.s;
    var adminDB = mongos.getDB('admin');
    var db = mongos.getDB('test');

    adminDB.createUser({user: 'admin', pwd: 'password', roles: jsTest.adminUserRoles});

    adminDB.auth('admin', 'password');

    adminDB.runCommand({enableSharding: "test"});
    st.ensurePrimaryShard('test', 'shard0001');
    adminDB.runCommand({shardCollection: "test.foo", key: {x: 1}});

    for (var i = 0; i < 100; i++) {
        db.foo.insert({x: i});
    }

    adminDB.runCommand({split: "test.foo", middle: {x: 50}});
    var curShard = st.getShard("test.foo", {x: 75});
    var otherShard = st.getOther(curShard).name;
    adminDB.runCommand(
        {moveChunk: "test.foo", find: {x: 25}, to: otherShard, _waitForDelete: true});

    st.printShardingStatus();

    MongoRunner.stopMongod(st.shard0);
    st.shard0 = MongoRunner.runMongod({restart: st.shard0});

    // May fail the first couple times due to socket exceptions
    assert.soon(function() {
        var res = adminDB.runCommand({moveChunk: "test.foo", find: {x: 75}, to: otherShard});
        printjson(res);
        return res.ok;
    });

    printjson(db.foo.findOne({x: 25}));
    printjson(db.foo.findOne({x: 75}));

    st.stop();
})();