summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/js_protection_roundtrip.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/js_protection_roundtrip.js')
-rw-r--r--jstests/noPassthrough/js_protection_roundtrip.js78
1 files changed, 39 insertions, 39 deletions
diff --git a/jstests/noPassthrough/js_protection_roundtrip.js b/jstests/noPassthrough/js_protection_roundtrip.js
index 59a1623419b..5c0c0b4da10 100644
--- a/jstests/noPassthrough/js_protection_roundtrip.js
+++ b/jstests/noPassthrough/js_protection_roundtrip.js
@@ -8,50 +8,50 @@
* 'CodeWScope'.
*/
(function() {
- "use strict";
+"use strict";
- var testServer = MongoRunner.runMongod();
- assert.neq(null, testServer, "failed to start mongod");
- var db = testServer.getDB("test");
- var t = db.js_protection_roundtrip;
+var testServer = MongoRunner.runMongod();
+assert.neq(null, testServer, "failed to start mongod");
+var db = testServer.getDB("test");
+var t = db.js_protection_roundtrip;
- function withoutJavaScriptProtection() {
- var doc = db.js_protection_roundtrip.findOne({_id: 0});
- assert.neq(doc, null);
- assert.eq(typeof doc.myFunc, "function", "myFunc should have been presented as a function");
- assert.eq(doc.myFunc(), "yes");
- }
+function withoutJavaScriptProtection() {
+ var doc = db.js_protection_roundtrip.findOne({_id: 0});
+ assert.neq(doc, null);
+ assert.eq(typeof doc.myFunc, "function", "myFunc should have been presented as a function");
+ assert.eq(doc.myFunc(), "yes");
+}
- function withJavaScriptProtection() {
- var doc = db.js_protection_roundtrip.findOne({_id: 0});
- assert.neq(doc, null);
- assert(doc.myFunc instanceof Code, "myFunc should have been a Code object");
- doc.myFunc = eval("(" + doc.myFunc.code + ")");
- assert.eq(doc.myFunc(), "yes");
- }
+function withJavaScriptProtection() {
+ var doc = db.js_protection_roundtrip.findOne({_id: 0});
+ assert.neq(doc, null);
+ assert(doc.myFunc instanceof Code, "myFunc should have been a Code object");
+ doc.myFunc = eval("(" + doc.myFunc.code + ")");
+ assert.eq(doc.myFunc(), "yes");
+}
- function testFunctionUnmarshall(jsProtection, evalFunc) {
- var evalString = "(" + tojson(evalFunc) + ")();";
- var protectionFlag =
- jsProtection ? "--enableJavaScriptProtection" : "--disableJavaScriptProtection";
- var exitCode = runMongoProgram(
- "mongo", "--port", testServer.port, protectionFlag, "--eval", evalString);
- assert.eq(exitCode, 0);
- }
+function testFunctionUnmarshall(jsProtection, evalFunc) {
+ var evalString = "(" + tojson(evalFunc) + ")();";
+ var protectionFlag =
+ jsProtection ? "--enableJavaScriptProtection" : "--disableJavaScriptProtection";
+ var exitCode =
+ runMongoProgram("mongo", "--port", testServer.port, protectionFlag, "--eval", evalString);
+ assert.eq(exitCode, 0);
+}
- /**
- * ACTUAL TEST
- */
- var result = t.insert({
- _id: 0,
- myFunc: function() {
- return "yes";
- }
- });
- assert.writeOK(result);
+/**
+ * ACTUAL TEST
+ */
+var result = t.insert({
+ _id: 0,
+ myFunc: function() {
+ return "yes";
+ }
+});
+assert.writeOK(result);
- testFunctionUnmarshall(true, withJavaScriptProtection);
- testFunctionUnmarshall(false, withoutJavaScriptProtection);
+testFunctionUnmarshall(true, withJavaScriptProtection);
+testFunctionUnmarshall(false, withoutJavaScriptProtection);
- MongoRunner.stopMongod(testServer);
+MongoRunner.stopMongod(testServer);
})();