diff options
author | Randolph Tan <randolph@10gen.com> | 2014-06-19 18:12:10 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-06-30 13:21:53 -0400 |
commit | 09d2bf2a43cbf6e7ac10d4dc89934528001d0b69 (patch) | |
tree | 62e86cf1fbb35106407e8251693e5052b6920fb1 /jstests/auth | |
parent | 5d4b3fe40cfe91857850d89a7a99a07d41b1d48d (diff) | |
download | mongo-09d2bf2a43cbf6e7ac10d4dc89934528001d0b69.tar.gz |
SERVER-9788 mongos does not respect secondary preferred after temporarily unavailable secondary
Diffstat (limited to 'jstests/auth')
-rw-r--r-- | jstests/auth/repl_auth.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/auth/repl_auth.js b/jstests/auth/repl_auth.js new file mode 100644 index 00000000000..d3791274be0 --- /dev/null +++ b/jstests/auth/repl_auth.js @@ -0,0 +1,68 @@ +/** + * Test that the replica set connections to the secondaries will have the right auth credentials + * even when these connections are shared within the same connection pool. + */ + +var NUM_NODES = 3; +var rsTest = new ReplSetTest({ nodes: NUM_NODES }); +rsTest.startSet({ oplogSize: 10, keyFile: 'jstests/libs/key1' }); +rsTest.initiate(); +rsTest.awaitSecondaryNodes(); + +var setupConn = rsTest.getPrimary(); +var admin = setupConn.getDB('admin'); + +// Setup initial data +admin.createUser({ user:'admin', pwd: 'password', roles: jsTest.adminUserRoles }); +admin.auth('admin', 'password'); + +setupConn.getDB('foo').createUser({ user: 'foo', pwd: 'foopwd', roles: jsTest.basicUserRoles }, + { w: NUM_NODES }); +setupConn.getDB('foo').logout(); +setupConn.getDB('bar').createUser({ user: 'bar', pwd: 'barpwd', roles: jsTest.basicUserRoles }, + { w: NUM_NODES }); +setupConn.getDB('bar').logout(); + +var replConn0 = new Mongo(rsTest.getURL()); +var replConn1 = new Mongo(rsTest.getURL()); +var fooDB0 = replConn0.getDB('foo'); +var barDB0 = replConn0.getDB('bar'); +var fooDB1 = replConn1.getDB('foo'); +var barDB1 = replConn1.getDB('bar'); + +fooDB0.auth('foo', 'foopwd'); +barDB1.auth('bar', 'barpwd'); + +assert.writeOK(fooDB0.user.insert({ x: 1 }, { writeConcern: { w: NUM_NODES }})); +assert.writeError(barDB0.user.insert({ x: 1 }, { writeConcern: { w: NUM_NODES }})); + +assert.writeError(fooDB1.user.insert({ x: 2 }, { writeConcern: { w: NUM_NODES }})); +assert.writeOK(barDB1.user.insert({ x: 2 }, { writeConcern: { w: NUM_NODES }})); + +// Make sure replica set connection in the shell is ready. +_awaitRSHostViaRSMonitor(rsTest.getPrimary().name, { ok: true, ismaster: true }, rsTest.name); +rsTest.getSecondaries().forEach(function(sec) { + _awaitRSHostViaRSMonitor(sec.name, { ok: true, secondary: true }, rsTest.name); +}); + +// Note: secondary nodes are selected randomly and connections will only be returned to the +// pool if a different secondary is selected from the previous one so we have to iterate +// a couple of times. +for (var x = 0; x < 20; x++) { + var explain = fooDB0.user.find().readPref('secondary').explain(); + assert.eq(1, explain.n); + + assert.throws(function() { + explain = barDB0.user.find().readPref('secondary').explain(); + }); + + assert.throws(function() { + explain = fooDB1.user.find().readPref('secondary').explain(); + }); + + explain = barDB1.user.find().readPref('secondary').explain(); + assert.eq(1, explain.n); +} + +rsTest.stopSet(); + |