summaryrefslogtreecommitdiff
path: root/jstests/change_streams
diff options
context:
space:
mode:
authorDavis Haupt <davis.haupt@mongodb.com>2019-06-19 10:26:17 -0400
committerDavis Haupt <davis.haupt@mongodb.com>2019-06-21 13:46:21 -0400
commitbb20517d07add520c56606c4c33afd73dfc90d10 (patch)
tree25b6bfc74ca4d60a4cbd0a101678b97e44b50b7e /jstests/change_streams
parentd4dd277c49a860b64700ea8a11a83ae5571f560c (diff)
downloadmongo-bb20517d07add520c56606c4c33afd73dfc90d10.tar.gz
SERVER-41164 stop documents from leaking into unrelated changestreams when regex control characters are in db name
Diffstat (limited to 'jstests/change_streams')
-rw-r--r--jstests/change_streams/no_regex_leak.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/change_streams/no_regex_leak.js b/jstests/change_streams/no_regex_leak.js
new file mode 100644
index 00000000000..a0e1b3aae7d
--- /dev/null
+++ b/jstests/change_streams/no_regex_leak.js
@@ -0,0 +1,60 @@
+/*
+ * This test makes sure that regex control characters in the namespace of changestream targets don't
+ * affect what documents appear in a changestream, in response to SERVER-41164.
+ */
+(function() {
+ "use strict";
+
+ load("jstests/libs/change_stream_util.js");
+ load("jstests/libs/collection_drop_recreate.js");
+ function test_no_leak(
+ dbNameUnrelated, collNameUnrelated, dbNameProblematic, collNameProblematic) {
+ const dbUnrelated = db.getSiblingDB(dbNameUnrelated);
+ const cstUnrelated = new ChangeStreamTest(dbUnrelated);
+ assertDropAndRecreateCollection(dbUnrelated, collNameUnrelated);
+
+ const watchUnrelated = cstUnrelated.startWatchingChanges(
+ {pipeline: [{$changeStream: {}}], collection: collNameUnrelated});
+
+ const dbProblematic = db.getSiblingDB(dbNameProblematic);
+ const cstProblematic = new ChangeStreamTest(dbProblematic);
+ assertDropAndRecreateCollection(dbProblematic, collNameProblematic);
+
+ const watchProblematic = cstProblematic.startWatchingChanges(
+ {pipeline: [{$changeStream: {}}], collection: collNameProblematic});
+
+ assert.commandWorked(dbUnrelated.getCollection(collNameUnrelated).insert({_id: 2}));
+ let expected = {
+ documentKey: {_id: 2},
+ fullDocument: {_id: 2},
+ ns: {db: dbNameUnrelated, coll: collNameUnrelated},
+ operationType: "insert",
+ };
+ // Make sure that only the database which was inserted into reflects a change on its
+ // changestream.
+ cstUnrelated.assertNextChangesEqual({cursor: watchUnrelated, expectedChanges: [expected]});
+ // The other DB shouldn't have any changes.
+ cstProblematic.assertNoChange(watchProblematic);
+
+ assert.commandWorked(dbProblematic.getCollection(collNameProblematic).insert({_id: 3}));
+ expected = {
+ documentKey: {_id: 3},
+ fullDocument: {_id: 3},
+ ns: {db: dbNameProblematic, coll: collNameProblematic},
+ operationType: "insert",
+ };
+ cstProblematic.assertNextChangesEqual(
+ {cursor: watchProblematic, expectedChanges: [expected]});
+ cstUnrelated.assertNoChange(watchUnrelated);
+
+ cstUnrelated.cleanUp();
+ cstProblematic.cleanUp();
+ }
+
+ test_no_leak("has_no_pipe", "coll", "has_a_|pipe", "coll");
+ test_no_leak("has_[two]_brackets", "coll", "has_t_brackets", "coll");
+ test_no_leak("test", "dotted.collection", "testadotted", "collection");
+ test_no_leak("carat", "coll", "hasa^carat", "coll");
+ test_no_leak("starssss", "coll", "stars*", "coll");
+ test_no_leak("db1", "coll", "db1", "col*");
+}());