summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/libs
diff options
context:
space:
mode:
authorMax Hirschhorn <max.hirschhorn@mongodb.com>2021-05-14 18:52:56 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-14 19:28:56 +0000
commit1ab98f5e384deca4eddacbfed26cc05e2c5e72d1 (patch)
treea9fe9bef788e8c424acb7383f0785957a9e1540f /jstests/multiVersion/libs
parentc51f7e9c15db0e4c508d8856a495ad278135a07d (diff)
downloadmongo-1ab98f5e384deca4eddacbfed26cc05e2c5e72d1.tar.gz
SERVER-56937 Restore authentication state before upgrading primary.
Diffstat (limited to 'jstests/multiVersion/libs')
-rw-r--r--jstests/multiVersion/libs/multi_rs.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/jstests/multiVersion/libs/multi_rs.js b/jstests/multiVersion/libs/multi_rs.js
index 868d133b40e..68ccef51f7e 100644
--- a/jstests/multiVersion/libs/multi_rs.js
+++ b/jstests/multiVersion/libs/multi_rs.js
@@ -90,6 +90,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();
@@ -162,8 +180,16 @@ ReplSetTest.prototype.stepdown = function(nodeId) {
ReplSetTest.prototype.reconnect = function(node) {
var nodeId = this.getNodeId(node);
this.nodes[nodeId] = new Mongo(node.host);
+ // 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];
}