summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2021-05-15 00:47:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-15 01:00:16 +0000
commit38257810d14f182540d3d9cfd06bb73881b0632d (patch)
tree3e9eaf4cf563f0843e12be22c7d64d3411f5149c
parent6c37e83e56bf2ceea19a4de59a5aba38e28de65a (diff)
downloadmongo-38257810d14f182540d3d9cfd06bb73881b0632d.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 e9671baefd1..c7149599d4b 100644
--- a/jstests/multiVersion/libs/multi_rs.js
+++ b/jstests/multiVersion/libs/multi_rs.js
@@ -52,6 +52,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 (let 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();
@@ -126,9 +144,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];
}