summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavis Haupt <davis.haupt@mongodb.com>2021-11-30 18:07:27 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-02 19:43:08 +0000
commit7f120e5dbf538ce29b637c5caa2d175a58e1afad (patch)
tree93defef80f9c3325fde5eed559b8717422d6a677
parent75ff1441ee21d4d5a213eb0e1d89ceffdca46ae1 (diff)
downloadmongo-7f120e5dbf538ce29b637c5caa2d175a58e1afad.tar.gz
SERVER-59909 make ShardingTest and ReplSetTest option objects immutable
-rw-r--r--jstests/sharding/sharding_test_options_immutable.js25
-rw-r--r--src/mongo/shell/replsettest.js6
-rw-r--r--src/mongo/shell/shardingtest.js3
3 files changed, 32 insertions, 2 deletions
diff --git a/jstests/sharding/sharding_test_options_immutable.js b/jstests/sharding/sharding_test_options_immutable.js
new file mode 100644
index 00000000000..fb904afe6ac
--- /dev/null
+++ b/jstests/sharding/sharding_test_options_immutable.js
@@ -0,0 +1,25 @@
+/*
+ * Ensure options object passed to ShardingTest is not mutated.
+ */
+
+(function() {
+'use strict';
+
+const opts = {
+ setParameter: {},
+};
+
+try {
+ const st = new ShardingTest({
+ mongos: [opts],
+ config: [opts],
+ rs: {nodes: [opts]},
+ shards: 1,
+ });
+ st.stop();
+} catch (e) {
+ assert(false, `ShardingTest threw an error: ${tojson(e)}`);
+} finally {
+ assert.eq(opts, {setParameter: {}});
+}
+})();
diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js
index bd1f5a58ba5..a3a3e081b1e 100644
--- a/src/mongo/shell/replsettest.js
+++ b/src/mongo/shell/replsettest.js
@@ -3336,6 +3336,8 @@ var ReplSetTest = function(opts) {
self.nodeOptions = nodeOptions;
}
+ // If opts is passed in as a string, let it pass unmodified since strings are pass-by-value.
+ // if it is an object, though, pass in a deep copy.
if (typeof opts === 'string' || opts instanceof String) {
retryOnNetworkError(function() {
// The primary may unexpectedly step down during startup if under heavy load
@@ -3344,9 +3346,9 @@ var ReplSetTest = function(opts) {
_constructFromExistingSeedNode(opts);
}, ReplSetTest.kDefaultRetries);
} else if (typeof opts.rstArgs === "object") {
- _constructFromExistingNodes(opts.rstArgs);
+ _constructFromExistingNodes(Object.extend({}, opts.rstArgs, true));
} else {
- _constructStartNewInstances(opts);
+ _constructStartNewInstances(Object.extend({}, opts, true));
}
/**
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index b2f2d8ee70e..35cf6ecec4d 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -113,6 +113,9 @@ var ShardingTest = function(params) {
// concern (5 minutes)
var kDefaultWTimeoutMs = 5 * 60 * 1000;
+ // Ensure we don't mutate the passed-in parameters.
+ params = Object.extend({}, params, true);
+
// Publicly exposed variables
/**