summaryrefslogtreecommitdiff
path: root/jstests/core/type4.js
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-09-14 14:18:35 -0400
committerJason Carey <jcarey@argv.me>2015-09-17 19:59:38 -0400
commit8291bbb3a6ec192d177076b1fb0cd28995e48440 (patch)
tree5cfb11b9cc1752c9967473c71b957188499b4fce /jstests/core/type4.js
parent1b0e65b0ccd5725f97b0a679ac7f7476a242c66e (diff)
downloadmongo-8291bbb3a6ec192d177076b1fb0cd28995e48440.tar.gz
SERVER-20080 Constrain ctor calls for JS types
Several types shouldn't be called as a ctor: * NativeFunction * Cursor * CursorHandle * NativeFunction This prevents them from being called as such.
Diffstat (limited to 'jstests/core/type4.js')
-rw-r--r--jstests/core/type4.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/core/type4.js b/jstests/core/type4.js
new file mode 100644
index 00000000000..c35d7baecca
--- /dev/null
+++ b/jstests/core/type4.js
@@ -0,0 +1,42 @@
+(function(){
+ "use strict";
+
+ // Tests for SERVER-20080
+ //
+ // Verify that various types cannot be invoked as constructors
+
+ var t = db.jstests_type4;
+ t.drop();
+ t.insert({});
+ t.insert({});
+ t.insert({});
+
+ var oldReadMode = db.getMongo()._readMode;
+
+ assert.throws(function(){
+ (new _rand())();
+ }, [], "invoke constructor on natively injected function");
+
+ assert.throws(function(){
+ var doc = db.test.findOne();
+ new doc();
+ }, [], "invoke constructor on BSON");
+
+ assert.throws(function(){
+ db.getMongo()._readMode = "commands";
+ var cursor = t.find();
+ cursor.next();
+
+ new cursor._cursor._cursorHandle();
+ }, [], "invoke constructor on CursorHandle");
+
+ assert.throws(function(){
+ db.getMongo()._readMode = "compatibility";
+ var cursor = t.find();
+ cursor.next();
+
+ new cursor._cursor();
+ }, [], "invoke constructor on Cursor");
+
+ db.getMongo()._readMode = oldReadMode;
+})();