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
Configure both objects with ``keyVaultNamespace`` set to ``admin.datakeys``.
322
+
323
+
Configure ``client_encrypted`` to use the schema `external/external-schema.json <../external/external-schema.json>`_ for ``db.coll`` by setting a schema map like: ``{ "db.coll": <contents of external-schema.json>}``
324
+
325
+
If ``withExternalKeyVault == true``, configure both objects with an external key vault client. The external client MUST connect to the same
326
+
MongoDB cluster that is being tested against, except it MUST use the username ``fake-user`` and password ``fake-pwd``.
327
+
328
+
#. Use ``client_encrypted`` to insert the document ``{"encrypted": "test"}`` into ``db.coll``.
329
+
If ``withExternalKeyVault == true``, expect an authentication exception to be thrown. Otherwise, expect the insert to succeed.
330
+
331
+
#. Use ``client_encryption`` to explicitly encrypt the string ``"test"`` with key ID ``LOCALAAAAAAAAAAAAAAAAA==`` and deterministic algorithm.
332
+
If ``withExternalKeyVault == true``, expect an authentication exception to be thrown. Otherwise, expect the insert to succeed.
333
+
334
+
335
+
BSON size limits and batch splitting
336
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
337
+
338
+
First, perform the setup.
339
+
340
+
#. Create a MongoClient without encryption enabled (referred to as ``client``).
341
+
342
+
#. Using ``client``, drop and create the collection ``db.coll`` configured with the included JSON schema `limits/limits-schema.json <../limits/limits-schema.json>`_.
343
+
344
+
#. Using ``client``, drop the collection ``admin.datakeys``. Insert the document `limits/limits-key.json <../limits/limits-key.json>`_
345
+
346
+
#. Create a MongoClient configured with auto encryption (referred to as ``client_encrypted``)
347
+
348
+
Configure with the ``local`` KMS provider as follows:
Expect this to throw an exception due to exceeding the reduced maximum BSON document size.
365
+
366
+
#. 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
+
Note: limits-doc.json is a 1005 byte BSON document that encrypts to a ~10,000 byte document.
368
+
369
+
Expect this to succeed since after encryption this still is below the normal maximum BSON document size.
370
+
Note, before auto encryption this document is under the 2 MiB limit. After encryption it exceeds the 2 MiB limit, but does NOT exceed the 16 MiB limit.
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
+
380
+
#. Bulk insert the following:
381
+
382
+
- The document `limits/limits-doc.json <../limits/limits-doc.json>`_ concatenated with ``{ "_id": "encryption_exceeds_2mib_1", "unencrypted": < the string "a" repeated (2097152 - 2000) times > }``
383
+
384
+
- 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
+
386
+
Expect the bulk write to succeed and split after first doc (i.e. two inserts occur).
387
+
388
+
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
+
390
+
391
+
Views are prohibited
392
+
~~~~~~~~~~~~~~~~~~~~
393
+
394
+
#. Create a MongoClient without encryption enabled (referred to as ``client``).
395
+
396
+
#. Using ``client``, drop and create a view named ``db.view`` with an empty pipeline. E.g. using the command ``{ "create": "view", "viewOn": "coll" }``.
397
+
398
+
#. Create a MongoClient configured with auto encryption (referred to as ``client_encrypted``)
399
+
400
+
Configure with the ``local`` KMS provider as follows:
Configure with the ``keyVaultNamespace`` set to ``admin.datakeys``.
407
+
408
+
#. Using ``client_encrypted``, attempt to insert a document into ``db.view``. Expect an exception to be thrown containing the message: "cannot auto encrypt a view".
409
+
410
+
296
411
Corpus Test
297
412
===========
298
413
299
414
The corpus test exhaustively enumerates all ways to encrypt all BSON value types. Note, the test data includes BSON binary subtype 4 (or standard UUID), which MUST be decoded and encoded as subtype 4. Run the test as follows.
300
415
301
416
1. Create a MongoClient without encryption enabled (referred to as ``client``).
302
417
303
-
2. Using ``client``, drop and create the collection ``db.coll`` configured with the included JSON schema `corpus/corpus-schema.json <corpus/corpus-schema.json>`_.
418
+
2. Using ``client``, drop and create the collection ``db.coll`` configured with the included JSON schema `corpus/corpus-schema.json <../corpus/corpus-schema.json>`_.
304
419
305
-
3. Using ``client``, drop the collection ``admin.datakeys``. Insert the documents `corpus/corpus-key-local.json <corpus/corpus-key-local.json>`_ and `corpus/corpus-key-aws.json <corpus/corpus-key-aws.json>`_.
420
+
3. Using ``client``, drop the collection ``admin.datakeys``. Insert the documents `corpus/corpus-key-local.json <../corpus/corpus-key-local.json>`_ and `corpus/corpus-key-aws.json <../corpus/corpus-key-aws.json>`_.
306
421
307
422
4. Create the following:
308
423
@@ -319,14 +434,14 @@ The corpus test exhaustively enumerates all ways to encrypt all BSON value types
Configure both objects with ``keyVaultNamespace`` set to ``admin.datakeys``.
328
443
329
-
5. Load `corpus/corpus.json <corpus/corpus.json>`_ to a variable named ``corpus``. The corpus contains subdocuments with the following fields:
444
+
5. Load `corpus/corpus.json <../corpus/corpus.json>`_ to a variable named ``corpus``. The corpus contains subdocuments with the following fields:
330
445
331
446
- ``kms`` is either ``aws`` or ``local``
332
447
- ``type`` is a BSON type string `names coming from here <https://docs.mongodb.com/manual/reference/operator/query/type/>`_)
@@ -342,15 +457,18 @@ The corpus test exhaustively enumerates all ways to encrypt all BSON value types
342
457
- If the field name is ``_id``, ``altname_aws`` and ``altname_local``, copy the field to ``corpus_copied``.
343
458
- If ``method`` is ``auto``, copy the field to ``corpus_copied``.
344
459
- If ``method`` is ``explicit``, use ``client_encryption`` to explicitly encrypt the value.
345
-
460
+
346
461
- Encrypt with the algorithm described by ``algo``.
347
462
- If ``identifier`` is ``id``
348
-
- If ``kms`` is ``local`` set the key_id to the UUID with base64 value ``LOCALAAAAAAAAAAAAAAAAA==``.
349
-
- If ``kms`` is ``aws`` set the key_id to the UUID with base64 value ``AWSAAAAAAAAAAAAAAAAAAA==``.
463
+
464
+
- If ``kms`` is ``local`` set the key_id to the UUID with base64 value ``LOCALAAAAAAAAAAAAAAAAA==``.
465
+
- If ``kms`` is ``aws`` set the key_id to the UUID with base64 value ``AWSAAAAAAAAAAAAAAAAAAA==``.
466
+
350
467
- If ``identifier`` is ``altname``
351
-
- If ``kms`` is ``local`` set the key_alt_name to "local".
352
-
- If ``kms`` is ``aws`` set the key_alt_name to "aws".
353
-
468
+
469
+
- If ``kms`` is ``local`` set the key_alt_name to "local".
470
+
- If ``kms`` is ``aws`` set the key_alt_name to "aws".
471
+
354
472
If ``allowed`` is true, copy the field and encrypted value to ``corpus_copied``.
355
473
If ``allowed`` is false. verify that an exception is thrown. Copy the unencrypted value to to ``corpus_copied``.
356
474
@@ -359,16 +477,15 @@ The corpus test exhaustively enumerates all ways to encrypt all BSON value types
359
477
360
478
7. Using ``client_encrypted``, find the inserted document from ``db.coll`` to a variable named ``corpus_decrypted``. Since it should have been automatically decrypted, assert the document exactly matches ``corpus``.
361
479
362
-
8. Load `corpus/corpus_encrypted.json <corpus/corpus-encrypted.json>`_ to a variable named ``corpus_encrypted_expected``.
480
+
8. Load `corpus/corpus_encrypted.json <../corpus/corpus-encrypted.json>`_ to a variable named ``corpus_encrypted_expected``.
363
481
Using ``client`` find the inserted document from ``db.coll`` to a variable named ``corpus_encrypted_actual``.
364
482
365
483
Iterate over each field of ``corpus_encrypted_expected`` and check the following:
366
484
367
-
- If the ``algo`` is ``det``, that the value exactly matches all fields in ``corpus_encrypted_actual`` with the same ``kms``, ``type``, and ``algo``.
368
-
- If the ``algo`` is ``rand`` and ``allowed`` is true, that the value does not match any fields in ``corpus_encrypted_actual`` with the same ``kms`` and ``type``.
369
-
- If the ``method`` is ``auto`` or ``explicit``, decrypt the value with ``client_encryption`` and validate the value exactly matches the corresponding field of ``corpus``.
370
-
- If the ``allowed`` is false, validate the value exactly matches the corresponding field of ``corpus``.
485
+
- If the ``algo`` is ``det``, that the value equals the value of the corresponding field in ``corpus_encrypted_actual``.
486
+
- If the ``algo`` is ``rand`` and ``allowed`` is true, that the value does not equal the value of the corresponding field in ``corpus_encrypted_actual``.
487
+
- 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
+
- If ``allowed`` is false, validate the value exactly equals the value of the corresponding field of ``corpus`` (neither was encrypted).
371
489
372
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.
0 commit comments