summaryrefslogtreecommitdiff
path: root/jstests/replsets/reconfig_errors_on_improper_host_value.js
blob: a69b2c0652f60d6cd0591964e2bf3099bed3c954 (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
/**
 * ReplSetReconfig should error out if any of the members in the replica set have a
 * 'host' field that contains a connection string.
 */

(function() {
"use strict";

const rst = new ReplSetTest({nodes: 3});

rst.startSet();
rst.initiate();
const primary = rst.getPrimary();

// Achieve steady state replication.
assert.commandWorked(primary.getDB(jsTestName())["test"].insert({x: 1}, {writeConcern: {w: 3}}));
rst.awaitReplication();

// Store proper host values.
let config = primary.getDB("local").system.replset.findOne();
const memberZeroHostValue = config.members[0].host;
const memberOneHostValue = config.members[1].host;
const memberTwoHostValue = config.members[2].host;

// Populate host field with connection string and expect a reconfig failure.
config.members[2].host = "mongodb://host/?replicaSet=rs";
config.version++;
assert.commandFailedWithCode(primary.adminCommand({replSetReconfig: config}),
                             ErrorCodes.InvalidReplicaSetConfig,
                             "Reconfig Should Fail");

// Verify that using connection string for all members' host fields fails.
config.members[1].host = "mongodb://host/?replicaSet=rs";
config.members[0].host = "mongodb://host/?replicaSet=rs";
config.version++;
assert.commandFailedWithCode(primary.adminCommand({replSetReconfig: config}),
                             ErrorCodes.InvalidReplicaSetConfig,
                             "Reconfig Should Fail");

// Sanity check that resetting member's host fields to proper host value makes reconfig work.
config.members[0].host = memberZeroHostValue;
config.members[1].host = memberOneHostValue;
config.members[2].host = memberTwoHostValue;
config.version++;
assert.commandWorked(primary.adminCommand({replSetReconfig: config}));
rst.stopSet();
})();