summaryrefslogtreecommitdiff
path: root/jstests/change_streams
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2017-12-01 23:04:58 +0000
committerBernard Gorman <bernard.gorman@gmail.com>2017-12-05 18:48:50 +0000
commitf9c698b67e6e08c05f4667d222a053f8f612d350 (patch)
tree9be97bf70016848b0da88f04a8d9512015f177e7 /jstests/change_streams
parent84b68e8459df1b795fa25eeaee05b76967eb9406 (diff)
downloadmongo-f9c698b67e6e08c05f4667d222a053f8f612d350.tar.gz
SERVER-31885 Prohibit $changeStream from running on a non-existent database
Diffstat (limited to 'jstests/change_streams')
-rw-r--r--jstests/change_streams/change_stream.js10
-rw-r--r--jstests/change_streams/change_stream_collation.js4
2 files changed, 13 insertions, 1 deletions
diff --git a/jstests/change_streams/change_stream.js b/jstests/change_streams/change_stream.js
index 80356aa3b48..59e8df872f1 100644
--- a/jstests/change_streams/change_stream.js
+++ b/jstests/change_streams/change_stream.js
@@ -6,10 +6,18 @@
load("jstests/libs/change_stream_util.js");
load('jstests/libs/uuid_util.js');
+ jsTestLog("Testing $changeStream on non-existent database");
+ const dbDoesNotExist = db.getSiblingDB("database-does-not-exist");
+ assert.commandWorked(dbDoesNotExist.dropDatabase());
+ assert.commandFailedWithCode(
+ dbDoesNotExist.runCommand(
+ {aggregate: dbDoesNotExist.getName(), pipeline: [{$changeStream: {}}], cursor: {}}),
+ ErrorCodes.NamespaceNotFound);
+
let cst = new ChangeStreamTest(db);
jsTestLog("Testing single insert");
- assertDropCollection(db, "t1");
+ assertDropAndRecreateCollection(db, "t1");
let cursor = cst.startWatchingChanges({pipeline: [{$changeStream: {}}], collection: db.t1});
// Test that if there are no changes, we return an empty batch.
assert.eq(0, cursor.firstBatch.length, "Cursor had changes: " + tojson(cursor));
diff --git a/jstests/change_streams/change_stream_collation.js b/jstests/change_streams/change_stream_collation.js
index 314e7b08954..b20d33e1981 100644
--- a/jstests/change_streams/change_stream_collation.js
+++ b/jstests/change_streams/change_stream_collation.js
@@ -11,6 +11,10 @@
const caseInsensitive = {locale: "en_US", strength: 2};
+ // $changeStream cannot run on a non-existent database. Create an unrelated collection to ensure
+ // that the database is present before testing.
+ assertDropAndRecreateCollection(db, "change_stream_ensure_db_exists");
+
let caseInsensitiveCollection = "change_stream_case_insensitive";
assertDropCollection(db, caseInsensitiveCollection);