summaryrefslogtreecommitdiff
path: root/jstests/change_streams/whitelist.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/change_streams/whitelist.js')
-rw-r--r--jstests/change_streams/whitelist.js64
1 files changed, 32 insertions, 32 deletions
diff --git a/jstests/change_streams/whitelist.js b/jstests/change_streams/whitelist.js
index 6b86604f8a8..cd5716b9073 100644
--- a/jstests/change_streams/whitelist.js
+++ b/jstests/change_streams/whitelist.js
@@ -3,31 +3,31 @@
*/
(function() {
- "use strict";
+"use strict";
- load('jstests/aggregation/extras/utils.js'); // For assertErrorCode.
- load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection.
+load('jstests/aggregation/extras/utils.js'); // For assertErrorCode.
+load("jstests/libs/collection_drop_recreate.js"); // For assert[Drop|Create]Collection.
- const coll = assertDropAndRecreateCollection(db, "change_stream_whitelist");
+const coll = assertDropAndRecreateCollection(db, "change_stream_whitelist");
- // Bare-bones $changeStream pipeline which will be augmented during tests.
- const changeStream = [{$changeStream: {}}];
+// Bare-bones $changeStream pipeline which will be augmented during tests.
+const changeStream = [{$changeStream: {}}];
- // List of non-$changeStream stages which are explicitly whitelisted.
- const whitelist = [
- {$match: {_id: {$exists: true}}},
- {$project: {_id: 1}},
- {$addFields: {newField: 1}},
- {$set: {newField: 1}},
- {$replaceRoot: {newRoot: {_id: "$_id"}}},
- {$replaceWith: {_id: "$_id"}},
- {$redact: "$$DESCEND"}
- ];
+// List of non-$changeStream stages which are explicitly whitelisted.
+const whitelist = [
+ {$match: {_id: {$exists: true}}},
+ {$project: {_id: 1}},
+ {$addFields: {newField: 1}},
+ {$set: {newField: 1}},
+ {$replaceRoot: {newRoot: {_id: "$_id"}}},
+ {$replaceWith: {_id: "$_id"}},
+ {$redact: "$$DESCEND"}
+];
- // List of stages which the whitelist mechanism will prevent from running in a $changeStream.
- // Does not include stages which are blacklisted but already implicitly prohibited, e.g. both
- // $currentOp and $changeStream must be the first stage in a pipeline.
- const blacklist = [
+// List of stages which the whitelist mechanism will prevent from running in a $changeStream.
+// Does not include stages which are blacklisted but already implicitly prohibited, e.g. both
+// $currentOp and $changeStream must be the first stage in a pipeline.
+const blacklist = [
{$group: {_id: "$_id"}},
{$sort: {_id: 1}},
{$skip: 100},
@@ -48,18 +48,18 @@
{$facet: {facetPipe: [{$match: {_id: {$exists: true}}}]}}
];
- // Verify that each of the whitelisted stages are permitted to run in a $changeStream.
- for (let allowedStage of whitelist) {
- assert.commandWorked(db.runCommand(
- {aggregate: coll.getName(), pipeline: changeStream.concat(allowedStage), cursor: {}}));
- }
-
- // Verify that all of the whitelisted stages are able to run in a $changeStream together.
+// Verify that each of the whitelisted stages are permitted to run in a $changeStream.
+for (let allowedStage of whitelist) {
assert.commandWorked(db.runCommand(
- {aggregate: coll.getName(), pipeline: changeStream.concat(whitelist), cursor: {}}));
+ {aggregate: coll.getName(), pipeline: changeStream.concat(allowedStage), cursor: {}}));
+}
+
+// Verify that all of the whitelisted stages are able to run in a $changeStream together.
+assert.commandWorked(db.runCommand(
+ {aggregate: coll.getName(), pipeline: changeStream.concat(whitelist), cursor: {}}));
- // Verify that a $changeStream pipeline fails to validate if a blacklisted stage is present.
- for (let bannedStage of blacklist) {
- assertErrorCode(coll, changeStream.concat(bannedStage), ErrorCodes.IllegalOperation);
- }
+// Verify that a $changeStream pipeline fails to validate if a blacklisted stage is present.
+for (let bannedStage of blacklist) {
+ assertErrorCode(coll, changeStream.concat(bannedStage), ErrorCodes.IllegalOperation);
+}
}());