summaryrefslogtreecommitdiff
path: root/jstests/libs
diff options
context:
space:
mode:
authorShane Harvey <shane.harvey@mongodb.com>2016-03-29 16:41:14 -0400
committerShane Harvey <shane.harvey@mongodb.com>2016-04-14 15:35:11 -0400
commit18a78da9e1b708341a50a8590b43832f848e40d7 (patch)
treeeb2b0619f6d7710d0e54fddd69e640805c2b7877 /jstests/libs
parent4b2a1960a08e4251fad7310db8501a3bf8e0444e (diff)
downloadmongo-18a78da9e1b708341a50a8590b43832f848e40d7.tar.gz
SERVER-23472 Enable JavaScript protection by default
Add mongo shell parameter --disableJavaScriptProtection.
Diffstat (limited to 'jstests/libs')
-rw-r--r--jstests/libs/parallelTester.js37
-rw-r--r--jstests/libs/test_background_ops.js3
2 files changed, 37 insertions, 3 deletions
diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js
index bbe2d19ee6c..fc34cb668f8 100644
--- a/jstests/libs/parallelTester.js
+++ b/jstests/libs/parallelTester.js
@@ -2,13 +2,46 @@
* The ParallelTester class is used to test more than one test concurrently
*/
if (typeof _threadInject != "undefined") {
+ // With --enableJavaScriptProtection functions are presented as Code objects.
+ // This function evals all the Code objects then calls the provided start function.
+ // arguments: [startFunction, startFunction args...]
+ function _threadStartWrapper() {
+ // Recursively evals all the Code objects present in arguments
+ // NOTE: This is a naive implementation that cannot handle cyclic objects.
+ function evalCodeArgs(arg) {
+ if (arg instanceof Code) {
+ return eval("(" + arg.code + ")");
+ } else if (arg !== null && isObject(arg)) {
+ var newArg = arg instanceof Array ? [] : {};
+ for (var prop in arg) {
+ if (arg.hasOwnProperty(prop)) {
+ newArg[prop] = evalCodeArgs(arg[prop]);
+ }
+ }
+ return newArg;
+ }
+ return arg;
+ }
+ var realStartFn;
+ var newArgs = [];
+ for (var i = 0, l = arguments.length; i < l; i++) {
+ newArgs.push(evalCodeArgs(arguments[i]));
+ }
+ realStartFn = newArgs.shift();
+ return realStartFn.apply(this, newArgs);
+ }
+
Thread = function() {
- this.init.apply(this, arguments);
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift(_threadStartWrapper);
+ this.init.apply(this, args);
};
_threadInject(Thread.prototype);
ScopedThread = function() {
- this.init.apply(this, arguments);
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift(_threadStartWrapper);
+ this.init.apply(this, args);
};
ScopedThread.prototype = new Thread(function() {});
_scopedThreadInject(ScopedThread.prototype);
diff --git a/jstests/libs/test_background_ops.js b/jstests/libs/test_background_ops.js
index ce21a636ff6..384e0bd5b64 100644
--- a/jstests/libs/test_background_ops.js
+++ b/jstests/libs/test_background_ops.js
@@ -138,6 +138,7 @@ startParallelOps = function(mongo, proc, args, context) {
var bootstrapper = function(stored) {
var procContext = stored.procContext;
+ eval("procContext = " + procContext);
procContext.setup(procContext, stored);
var contexts = stored.contexts;
@@ -177,7 +178,7 @@ startParallelOps = function(mongo, proc, args, context) {
bootstrapper: tojson(bootstrapper),
operation: tojson(proc),
args: tojson(args),
- procContext: procContext,
+ procContext: tojson(procContext),
contexts: tojson(contexts)
});