Files
mongo/jstests/replsets/auth_no_pri.js
Moustafa Maher 6849b3ff14 SERVER-96971 Prevent ReplSetTest.waitForState from returning stale data for SECONDARY state (#29585)
GitOrigin-RevId: 9d38b94afbd94ff5dffa63b7ec487ea54fa4a98d
2024-12-05 21:15:14 +00:00

29 lines
1.1 KiB
JavaScript

// Test that you can still authenticate a replset connection to a RS with no primary (SERVER-6665).
import {ReplSetTest} from "jstests/libs/replsettest.js";
var NODE_COUNT = 3;
const rs = new ReplSetTest({"nodes": NODE_COUNT, keyFile: "jstests/libs/key1"});
var nodes = rs.startSet();
rs.initiate();
// Add user
var primary = rs.getPrimary();
primary.getDB("admin").createUser({user: "admin", pwd: "pwd", roles: ["root"]}, {w: NODE_COUNT});
// Can authenticate replset connection when whole set is up.
var conn = new Mongo(rs.getURL());
assert(conn.getDB('admin').auth('admin', 'pwd'));
assert.commandWorked(conn.getDB('admin').foo.insert({a: 1}, {writeConcern: {w: NODE_COUNT}}));
// Make sure there is no primary
rs.stop(0);
rs.stop(1);
rs.awaitSecondaryNodes(null, [nodes[2]]);
// Make sure you can still authenticate a replset connection with no primary
var conn2 = new Mongo(rs.getURL());
conn2.setSecondaryOk();
assert(conn2.getDB('admin').auth({user: 'admin', pwd: 'pwd', mechanism: "SCRAM-SHA-1"}));
assert.eq(1, conn2.getDB('admin').foo.findOne().a);
rs.stopSet();