summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2021-05-14 22:36:56 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-14 22:57:11 +0000
commit99b2782aa296596714c348bd7b7efae21b76af68 (patch)
treea72b1bdd5fed777abdc99f4b88358d61de7f0340
parent68c231b5657ff128b773de115467245f52311d40 (diff)
downloadmongo-99b2782aa296596714c348bd7b7efae21b76af68.tar.gz
SERVER-56937 Restore authentication state before upgrading primary.
(cherry picked from commit 1ab98f5e384deca4eddacbfed26cc05e2c5e72d1)
-rw-r--r--jstests/multiVersion/libs/multi_rs.js29
1 files changed, 27 insertions, 2 deletions
diff --git a/jstests/multiVersion/libs/multi_rs.js b/jstests/multiVersion/libs/multi_rs.js
index 40448e7e424..5c41eeb05ee 100644
--- a/jstests/multiVersion/libs/multi_rs.js
+++ b/jstests/multiVersion/libs/multi_rs.js
@@ -51,6 +51,24 @@ ReplSetTest.prototype.upgradePrimary = function(primary, options, user, pwd) {
}
jsTest.authenticate(oldPrimary);
+ // waitForState() runs the logout command via asCluster() on either the current primary or the
+ // first node in the replica set so we re-authenticate on all connections before calling
+ // awaitNodesAgreeOnPrimary().
+ for (const node of this.nodes) {
+ const connStatus =
+ assert.commandWorked(node.adminCommand({connectionStatus: 1, showPrivileges: true}));
+
+ const connIsAuthenticated = connStatus.authInfo.authenticatedUsers.length > 0;
+ if (connIsAuthenticated) {
+ continue;
+ }
+
+ if (user != undefined) {
+ node.getDB('admin').auth(user, pwd);
+ }
+ jsTest.authenticate(node);
+ }
+
this.awaitNodesAgreeOnPrimary();
primary = this.getPrimary();
@@ -125,9 +143,16 @@ ReplSetTest.prototype.stepdown = function(nodeId) {
ReplSetTest.prototype.reconnect = function(node) {
var nodeId = this.getNodeId(node);
this.nodes[nodeId] = new Mongo(node.host);
- var except = {};
+ // Skip the 'authenticated' property because the new connection hasn't been authenticated even
+ // if the original one was. This ensures Mongo.prototype.getDB() will attempt to authenticate
+ // automatically if TestData is configured appropriately.
+ //
+ // Skip the '_defaultSession' property because the DriverSession object is bound to the original
+ // connection object. Copying the '_defaultSession' property would cause commands to go through
+ // the original connection despite methods being called on DB objects from the new connection.
+ const except = new Set(["authenticated", "_defaultSession"]);
for (var i in node) {
- if (typeof (node[i]) == "function")
+ if (typeof (node[i]) == "function" || except.has(i))
continue;
this.nodes[nodeId][i] = node[i];
}