summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorKatherine Wu <katherine.wu@mongodb.com>2020-05-14 13:47:20 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-02 20:08:49 +0000
commitbecc8e5ecca4260e844725fa71f4ed1164647e4a (patch)
tree6945818b345b2e5bf943b89a2ec11cb0f40b387f /jstests/core
parent1468dbb72e5384c58c8dfc19003beed84befecfd (diff)
downloadmongo-becc8e5ecca4260e844725fa71f4ed1164647e4a.tar.gz
SERVER-46625 Improve diagnostics when mongocryptd requests are sent to non-mongocryptd daemon
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/command_json_schema_field.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/core/command_json_schema_field.js b/jstests/core/command_json_schema_field.js
new file mode 100644
index 00000000000..5c7a60f3309
--- /dev/null
+++ b/jstests/core/command_json_schema_field.js
@@ -0,0 +1,52 @@
+/*
+ * FLE-supported commands that contain an invalid 'jsonSchema' field should return to the user a
+ * more specific error message for diagnostic purposes.
+ *
+ * @tags: [requires_fcv_46, requires_non_retryable_writes]
+ */
+(function() {
+'use strict';
+
+const coll = db.command_json_schema_field;
+coll.drop();
+assert.commandWorked(coll.insert({a: 1}));
+assert.commandWorked(coll.insert({a: 2}));
+
+function assertCommandFailsWithCorrectError(command, code) {
+ let res = db.runCommand(command);
+ assert.commandFailedWithCode(res, code);
+ assert(res.errmsg.includes("This command may be meant for a mongocryptd process"));
+}
+
+// Aggregate
+assertCommandFailsWithCorrectError(
+ {aggregate: coll.getName(), pipeline: [], cursor: {}, jsonSchema: {}},
+ ErrorCodes.FailedToParse);
+
+// Find
+assertCommandFailsWithCorrectError({find: coll.getName(), jsonSchema: {}},
+ ErrorCodes.FailedToParse);
+
+// FindAndModify
+assertCommandFailsWithCorrectError(
+ {findAndModify: coll.getName(), query: {_id: 0}, remove: true, jsonSchema: {}},
+ ErrorCodes.FailedToParse);
+
+// Count
+assertCommandFailsWithCorrectError({count: coll.getName(), jsonSchema: {}}, 4662500);
+
+// Distinct
+assertCommandFailsWithCorrectError({distinct: coll.getName(), key: "a", jsonSchema: {}}, 4662500);
+
+// Write Commands
+assertCommandFailsWithCorrectError({insert: coll.getName(), documents: [{}], jsonSchema: {}},
+ 4662500);
+assertCommandFailsWithCorrectError(
+ {update: coll.getName(), updates: [{q: {}, u: {$inc: {a: 1}}}], jsonSchema: {}}, 4662500);
+assertCommandFailsWithCorrectError(
+ {delete: coll.getName(), deletes: [{q: {}, limit: 0}], jsonSchema: {}}, 4662500);
+
+// Explain
+assertCommandFailsWithCorrectError({explain: {count: coll.getName()}, jsonSchema: {}},
+ ErrorCodes.FailedToParse);
+}()); \ No newline at end of file