summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-04-25 12:19:01 -0400
committerIan Boros <ian.boros@10gen.com>2018-04-26 17:04:59 -0400
commitd881559e5c847bb422687a72ce10c263f1ef68cc (patch)
treee1c29fa44089f7b8b6f7825debd0cce5a5849070 /jstests
parenta1601dd85764e1aac6128057b5681107931c64b8 (diff)
downloadmongo-d881559e5c847bb422687a72ce10c263f1ef68cc.tar.gz
SERVER-34662 fix $changeStream parsing to check that its argument is an object
Diffstat (limited to 'jstests')
-rw-r--r--jstests/change_streams/change_stream.js11
-rw-r--r--jstests/libs/override_methods/implicit_whole_db_changestreams.js3
2 files changed, 13 insertions, 1 deletions
diff --git a/jstests/change_streams/change_stream.js b/jstests/change_streams/change_stream.js
index d0f3755bc17..0d392b99bcc 100644
--- a/jstests/change_streams/change_stream.js
+++ b/jstests/change_streams/change_stream.js
@@ -16,6 +16,17 @@
assertDropAndRecreateCollection(db, "t1");
assertDropAndRecreateCollection(db, "t2");
+ // Test that $changeStream only accepts an object as its argument.
+ function checkArgFails(arg) {
+ assert.commandFailedWithCode(
+ db.runCommand({aggregate: "t1", pipeline: [{$changeStream: arg}], cursor: {}}), 50808);
+ }
+
+ checkArgFails(1);
+ checkArgFails("invalid");
+ checkArgFails(false);
+ checkArgFails([1, 2, "invalid", {x: 1}]);
+
// Test that a change stream cannot be opened on collections in the "admin", "config", or
// "local" databases.
assertInvalidChangeStreamNss("admin", "testColl");
diff --git a/jstests/libs/override_methods/implicit_whole_db_changestreams.js b/jstests/libs/override_methods/implicit_whole_db_changestreams.js
index ae4ed192033..f88af373263 100644
--- a/jstests/libs/override_methods/implicit_whole_db_changestreams.js
+++ b/jstests/libs/override_methods/implicit_whole_db_changestreams.js
@@ -25,7 +25,8 @@ const ChangeStreamPassthroughHelpers = {
// Determine whether this command is a valid $changeStream aggregation on a single
// collection or database.
if (!(cmdObj && cmdObj.aggregate && Array.isArray(cmdObj.pipeline) &&
- cmdObj.pipeline.length > 0 && cmdObj.pipeline[0].$changeStream)) {
+ cmdObj.pipeline.length > 0 && typeof cmdObj.pipeline[0].$changeStream == "object" &&
+ cmdObj.pipeline[0].$changeStream.constructor === Object)) {
return false;
}
// Single-collection and whole-db streams cannot be opened on internal databases.