2014-03-14 14:42:57 -04:00
|
|
|
// Test that you can still authenticate a replset connection to a RS with no primary (SERVER-6665).
|
2014-03-20 11:29:32 -04:00
|
|
|
(function () {
|
2015-12-10 10:21:51 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-03-20 11:29:32 -04:00
|
|
|
var NODE_COUNT = 3;
|
|
|
|
|
var rs = new ReplSetTest({"nodes" : NODE_COUNT, keyFile : "jstests/libs/key1"});
|
2015-01-15 08:57:37 -05:00
|
|
|
var nodes = rs.startSet();
|
2014-03-14 14:42:57 -04:00
|
|
|
rs.initiate();
|
|
|
|
|
|
|
|
|
|
// Add user
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = rs.getPrimary();
|
2014-03-20 11:29:32 -04:00
|
|
|
master.getDB("admin").createUser({user: "admin", pwd: "pwd", roles: ["root"]}, {w: NODE_COUNT});
|
2014-03-14 14:42:57 -04:00
|
|
|
|
|
|
|
|
// Can authenticate replset connection when whole set is up.
|
|
|
|
|
var conn = new Mongo(rs.getURL());
|
|
|
|
|
assert(conn.getDB('admin').auth('admin', 'pwd'));
|
2014-03-20 11:29:32 -04:00
|
|
|
assert.writeOK(conn.getDB('admin').foo.insert({a:1}, { writeConcern: { w: NODE_COUNT } }));
|
2014-03-14 14:42:57 -04:00
|
|
|
|
|
|
|
|
// Make sure there is no primary
|
|
|
|
|
rs.stop(0);
|
|
|
|
|
rs.stop(1);
|
2015-12-10 10:21:51 -05:00
|
|
|
rs.waitForState(nodes[2], ReplSetTest.State.SECONDARY);
|
2014-03-14 14:42:57 -04:00
|
|
|
|
|
|
|
|
// Make sure you can still authenticate a replset connection with no primary
|
|
|
|
|
var conn2 = new Mongo(rs.getURL());
|
|
|
|
|
conn2.setSlaveOk(true);
|
2014-12-08 17:41:31 -05:00
|
|
|
assert(conn2.getDB('admin').auth({user:'admin', pwd:'pwd', mechanism:"SCRAM-SHA-1"}));
|
2014-03-14 14:42:57 -04:00
|
|
|
assert.eq(1, conn2.getDB('admin').foo.findOne().a);
|
|
|
|
|
|
2014-03-20 11:29:32 -04:00
|
|
|
rs.stopSet();
|
2015-12-10 10:21:51 -05:00
|
|
|
|
2014-03-20 11:29:32 -04:00
|
|
|
}());
|