Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-6117 SlaveOk Query fails with auth error even after logging in
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var replTest = new ReplSetTest({ nodes: 3 }); | ||
replTest.startSet({ oplogSize: 10, keyFile: 'jstests/libs/key1' }); | ||
replTest.initiate(); | ||
replTest.awaitSecondaryNodes(); | ||
|
||
var nodeCount = replTest.nodes.length; | ||
var primary = replTest.getPrimary(); | ||
|
||
// Setup the database using replSet connection before setting the authentication | ||
var conn = new Mongo(replTest.getURL()); | ||
var testDB = conn.getDB('test'); | ||
var testColl = testDB.user; | ||
|
||
testColl.insert({ x: 1 }); | ||
testDB.runCommand({ getLastError: 1, w: nodeCount }); | ||
|
||
// Setup the cached connection for primary and secondary in DBClientReplicaSet | ||
// before setting up authentication | ||
var doc = testColl.findOne(); | ||
assert(doc != null); | ||
|
||
conn.setSlaveOk(); | ||
|
||
doc = testColl.findOne(); | ||
assert(doc != null); | ||
|
||
// Add admin user using direct connection to primary to simulate connection from remote host | ||
var adminDB = primary.getDB('admin'); | ||
adminDB.addUser('user', 'user', false, nodeCount); | ||
adminDB.auth('user', 'user'); | ||
|
||
var priTestDB = primary.getDB('test'); | ||
priTestDB.addUser('a', 'a', false, nodeCount); | ||
|
||
// Authenticate the replSet connection | ||
assert.eq(1, testDB.auth('a', 'a')); | ||
|
||
jsTest.log('Sending an authorized query that should be ok'); | ||
conn.setSlaveOk(true); | ||
doc = testColl.findOne(); | ||
assert(doc != null); | ||
|
||
doc = testColl.find().readPref('secondary').next(); | ||
assert(doc != null); | ||
|
||
conn.setSlaveOk(false); | ||
doc = testColl.findOne(); | ||
assert(doc != null); | ||
|
||
replTest.stopSet(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters