Skip to content

Instantly share code, notes, and snippets.

@kevinAlbs
Created April 10, 2022 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinAlbs/198ec9c8784b7297a76d966f2ca785ec to your computer and use it in GitHub Desktop.
Save kevinAlbs/198ec9c8784b7297a76d966f2ca785ec to your computer and use it in GitHub Desktop.
Reproduce the expected error from the badQueries test "an update that would produce an array on an encrypted field errors"
/* Q: What error does mongocryptd return when encrypting an array?
* A: See "Sample outputs" below.
*
* Run this script with: mongo --port 27020 run-badQuery.js
*/
reply = db.runCommand({
update: "coll",
updates: [
{q: { }, u: { $set : { "encrypted_string": [1,2] }}}
],
jsonSchema: {'properties': {'encrypted_string': {'encrypt': {'keyId': [UUID()], 'bsonType': 'string', 'algorithm': 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'}}}, 'bsonType': 'object'},
isRemoteSchema: true
})
printjson (reply)
/*
Sample outputs:
% mongo run-badQuery.js --port 27020
MongoDB shell version v6.0.0-alpha-825-g57b670b
connecting to: mongodb://127.0.0.1:27020/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("ddf804aa-5ee3-40cf-be44-7e936e63d27a") }
MongoDB server version: 6.0.0-alpha-825-g57b670b
{
"ok" : 0,
"errmsg" : "Cannot encrypt element of type array because schema requires that type is one of: [ string ]",
"code" : 31118,
"codeName" : "Location31118"
}
% mongo run-badQuery.js --port 27020
MongoDB shell version v6.0.0-alpha-1179-gdc27194
connecting to: mongodb://127.0.0.1:27020/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("ddf804aa-5ee3-40cf-be44-7e936e63d27a") }
MongoDB server version: 6.0.0-alpha-1179-gdc27194
{
"ok" : 0,
"errmsg" : "Cannot encrypt element of type: array",
"code" : 31041,
"codeName" : "Location31041"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment