2015-11-19 14:01:59 -05:00
|
|
|
// Tests that the creation of a user replicates to secondaries, and survives a restart of all
|
|
|
|
|
// data-bearing nodes.
|
|
|
|
|
//
|
|
|
|
|
// If all data-bearing nodes in a replica set are using an ephemeral storage engine, the set will
|
|
|
|
|
// not be able to survive a scenario where all data-bearing nodes are down simultaneously. In such a
|
|
|
|
|
// scenario, none of the members will have any data, and upon restart will each look for a member to
|
|
|
|
|
// inital sync from, so no primary will be elected. This test induces such a scenario, so cannot be
|
|
|
|
|
// run on ephemeral storage engines.
|
|
|
|
|
// @tags: [requires_persistence]
|
|
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
(function () {
|
|
|
|
|
"use strict";
|
|
|
|
|
var keyfile = "jstests/libs/key1";
|
|
|
|
|
var master;
|
|
|
|
|
var rs = new ReplSetTest({
|
|
|
|
|
nodes : { node0 : {}, node1 : {}, arbiter : {}},
|
|
|
|
|
keyFile : keyfile
|
2011-10-25 11:41:38 -04:00
|
|
|
});
|
2014-10-15 10:50:05 -04:00
|
|
|
rs.startSet();
|
|
|
|
|
rs.initiate();
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
master = rs.getPrimary();
|
2014-10-15 10:50:05 -04:00
|
|
|
jsTest.log("adding user");
|
|
|
|
|
master.getDB("admin").createUser({user: "foo", pwd: "bar", roles: jsTest.adminUserRoles},
|
|
|
|
|
{w: 2, wtimeout: 30000});
|
|
|
|
|
|
|
|
|
|
var safeInsert = function() {
|
2015-11-25 11:20:43 -05:00
|
|
|
master = rs.getPrimary();
|
2014-10-15 10:50:05 -04:00
|
|
|
master.getDB("admin").auth("foo", "bar");
|
|
|
|
|
assert.writeOK(master.getDB("foo").bar.insert({ x: 1 }));
|
2015-11-19 14:01:59 -05:00
|
|
|
};
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
jsTest.log("authing");
|
2012-04-09 16:31:30 -04:00
|
|
|
for (var i=0; i<2; i++) {
|
2014-10-15 10:50:05 -04:00
|
|
|
assert(rs.nodes[i].getDB("admin").auth("foo", "bar"),
|
|
|
|
|
"could not log into " + rs.nodes[i].host);
|
2012-04-09 16:31:30 -04:00
|
|
|
}
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
jsTest.log("make common point");
|
|
|
|
|
|
|
|
|
|
safeInsert();
|
|
|
|
|
authutil.asCluster(rs.nodes, keyfile, function() { rs.awaitReplication(); });
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2015-11-19 14:01:59 -05:00
|
|
|
jsTest.log("write stuff to 0&2");
|
2014-10-15 10:50:05 -04:00
|
|
|
rs.stop(1);
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
master = rs.getPrimary();
|
2014-10-15 10:50:05 -04:00
|
|
|
master.getDB("admin").auth("foo", "bar");
|
|
|
|
|
master.getDB("foo").bar.drop();
|
|
|
|
|
jsTest.log("last op: " +
|
|
|
|
|
tojson(master.getDB("local").oplog.rs.find().sort({$natural:-1}).limit(1).next()));
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2015-11-19 14:01:59 -05:00
|
|
|
jsTest.log("write stuff to 1&2");
|
2014-10-15 10:50:05 -04:00
|
|
|
rs.stop(0);
|
|
|
|
|
rs.restart(1);
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
safeInsert();
|
|
|
|
|
jsTest.log("last op: " +
|
|
|
|
|
tojson(master.getDB("local").oplog.rs.find().sort({$natural:-1}).limit(1).next()));
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
rs.restart(0);
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
jsTest.log("doing rollback!");
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
authutil.asCluster(rs.nodes, keyfile, function () { rs.awaitSecondaryNodes(); });
|
2011-10-25 11:41:38 -04:00
|
|
|
|
2014-10-15 10:50:05 -04:00
|
|
|
}());
|