You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#. If the YAML file contains a ``data`` array, insert the documents in ``data``
137
142
into the test collection, using writeConcern "majority".
138
143
139
-
#. Set Command Monitoring listeners on the MongoClient.
144
+
#. Create a **new** MongoClient using ``clientOptions``.
145
+
146
+
#. If ``autoEncryptOpts`` includes ``aws`` as a KMS provider, pass in AWS credentials from the environment.
147
+
#. If ``autoEncryptOpts`` does not include ``keyVaultNamespace``, default it to ``admin.datakeys``.
148
+
140
149
#. For each element in ``operations``:
141
150
142
151
- Enter a "try" block or your programming language's closest equivalent.
@@ -204,7 +213,7 @@ Data key and double encryption
204
213
205
214
First, perform the setup.
206
215
207
-
#. Create a MongoClient without encryption enabled (referred to as ``client``).
216
+
#. Create a MongoClient without encryption enabled (referred to as ``client``). Enable command monitoring to listen for command_started events.
208
217
209
218
#. Using ``client``, drop the collections ``admin.datakeys`` and ``db.coll``.
210
219
@@ -243,13 +252,16 @@ First, perform the setup.
243
252
}
244
253
}
245
254
255
+
Configure ``client_encryption`` with the ``keyVaultClient`` of the previously created ``client``.
256
+
246
257
Then, test creating and using data keys from a ``local`` KMS provider:
247
258
248
259
#. Call ``client_encryption.createDataKey()`` with the ``local`` KMS provider and keyAltNames set to ``["local_altname"]``.
249
260
250
261
- Expect a BSON binary with subtype 4 to be returned, referred to as ``local_datakey_id``.
251
262
- Use ``client`` to run a ``find`` on ``admin.datakeys`` by querying with the ``_id`` set to the ``local_datakey_id``.
252
263
- Expect that exactly one document is returned with the "masterKey.provider" equal to "local".
264
+
- Check that ``client`` captured a command_started event for the ``insert`` command containing a majority writeConcern.
253
265
254
266
#. Call ``client_encryption.encrypt()`` with the value "hello local", the algorithm ``AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic``, and the ``key_id`` of ``local_datakey_id``.
255
267
@@ -276,6 +288,7 @@ Then, repeat the above tests with the ``aws`` KMS provider:
276
288
- Expect a BSON binary with subtype 4 to be returned, referred to as ``aws_datakey_id``.
277
289
- Use ``client`` to run a ``find`` on ``admin.datakeys`` by querying with the ``_id`` set to the ``aws_datakey_id``.
278
290
- Expect that exactly one document is returned with the "masterKey.provider" equal to "aws".
291
+
- Check that ``client`` captured a command_started event for the ``insert`` command containing a majority writeConcern.
279
292
280
293
#. Call ``client_encryption.encrypt()`` with the value "hello aws", the algorithm ``AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic``, and the ``key_id`` of ``aws_datakey_id``.
281
294
@@ -355,13 +368,9 @@ First, perform the setup.
355
368
356
369
Using ``client_encrypted`` perform the following operations:
357
370
358
-
#. Insert ``{ "_id": "no_encryption_under_2mib", "unencrypted": <the string "a" repeated (2097152 - 1000) times> }``. (Note 2097152 is 2^21 bytes, or 2 MiB).
Expect this to throw an exception due to exceeding the reduced maximum BSON document size.
373
+
Expect this to succeed since this is still under the ``maxBsonObjectSize`` limit.
365
374
366
375
#. Insert the document `limits/limits-doc.json <../limits/limits-doc.json>`_ concatenated with ``{ "_id": "encryption_exceeds_2mib", "unencrypted": < the string "a" repeated (2097152 - 2000) times > }``
367
376
Note: limits-doc.json is a 1005 byte BSON document that encrypts to a ~10,000 byte document.
@@ -371,9 +380,9 @@ Using ``client_encrypted`` perform the following operations:
Expect the bulk write to succeed and split after first doc (i.e. two inserts occur). This may be verified using `command monitoring <https://github.com/mongodb/specifications/tree/master/source/command-monitoring/command-monitoring.rst>`_.
379
388
@@ -383,7 +392,15 @@ Using ``client_encrypted`` perform the following operations:
383
392
384
393
- The document `limits/limits-doc.json <../limits/limits-doc.json>`_ concatenated with ``{ "_id": "encryption_exceeds_2mib_2", "unencrypted": < the string "a" repeated (2097152 - 2000) times > }``
385
394
386
-
Expect the bulk write to succeed and split after first doc (i.e. two inserts occur).
395
+
Expect the bulk write to succeed and split after first doc (i.e. two inserts occur). This may be verified using `command monitoring <https://github.com/mongodb/specifications/tree/master/source/command-monitoring/command-monitoring.rst>`_.
Expect this to succeed since this is still (just) under the ``maxBsonObjectSize`` limit.
400
+
401
+
#. Insert the document `limits/limits-doc.json <../limits/limits-doc.json>`_ concatenated with ``{ "_id": "encryption_exceeds_16mib", "unencrypted": < the string "a" repeated (16777216 - 2000) times > }``
402
+
403
+
Expect this to fail since encryption results in a document exceeding the ``maxBsonObjectSize`` limit.
387
404
388
405
Optionally, if it is possible to mock the maxWriteBatchSize (i.e. the maximum number of documents in a batch) test that setting maxWriteBatchSize=1 and inserting the two documents ``{ "_id": "a" }, { "_id": "b" }`` with ``client_encrypted`` splits the operation into two inserts.
389
406
@@ -487,5 +504,93 @@ The corpus test exhaustively enumerates all ways to encrypt all BSON value types
487
504
- If ``allowed`` is true, decrypt the value with ``client_encryption``. Decrypt the value of the corresponding field of ``corpus_encrypted`` and validate that they are both equal.
488
505
- If ``allowed`` is false, validate the value exactly equals the value of the corresponding field of ``corpus`` (neither was encrypted).
489
506
490
-
9. Repeat steps 1-8 with a local JSON schema. I.e. amend step 4 to configure the schema on ``client_encrypted`` and ``client_encryption`` with the ``schema_map`` option.
507
+
9. Repeat steps 1-8 with a local JSON schema. I.e. amend step 4 to configure the schema on ``client_encrypted`` with the ``schema_map`` option.
508
+
509
+
Custom Endpoint Test
510
+
====================
511
+
512
+
Data keys created with AWS KMS may specify a custom endpoint to contact (instead of the default endpoint derived from the AWS region).
513
+
514
+
1. Create a ``ClientEncryption`` object (referred to as ``client_encryption``)
515
+
516
+
Configure with ``aws`` KMS providers as follows:
517
+
518
+
.. code:: javascript
519
+
520
+
{
521
+
"aws": { <AWS credentials> }
522
+
}
523
+
524
+
Configure with ``keyVaultNamespace`` set to ``admin.datakeys``, and a default MongoClient as the ``keyVaultClient``.
525
+
526
+
2. Call `client_encryption.createDataKey()` with "aws" as the provider and the following masterKey:
0 commit comments