@@ -2464,6 +2464,19 @@ The following tests that a mongocryptd client is not created when shared library
2464
2464
21. Automatic Data Encryption Keys
2465
2465
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2466
2466
2467
+ For each of the following test cases, assume `DB ` is a valid open database
2468
+ handle, and assume a ClientEncryption _ object `CE ` created using the following
2469
+ options::
2470
+
2471
+ clientEncryptionOptions: {
2472
+ keyVaultClient: <new MongoClient>,
2473
+ keyVaultNamespace: "keyvault.datakeys",
2474
+ kmsProviders: {
2475
+ local: { key: base64Decode(LOCAL_MASTERKEY) },
2476
+ },
2477
+ }
2478
+
2479
+
2467
2480
Case 1: Simple Creation and Validation
2468
2481
``````````````````````````````````````
2469
2482
@@ -2477,17 +2490,7 @@ rejects an attempt to insert plaintext in an encrypted fields.
2477
2490
.. highlight :: typescript
2478
2491
.. default-role :: math
2479
2492
2480
- 1. Create a ClientEncryption _ object `CE ` with the following options::
2481
-
2482
- clientEncryptionOptions: {
2483
- keyVaultClient: <new MongoClient>,
2484
- keyVaultNamespace: "keyvault.datakeys",
2485
- kmsProviders: {
2486
- local: { key: base64Decode(LOCAL_MASTERKEY) },
2487
- },
2488
- }
2489
-
2490
- 2. Create a new create-collection options `Opts ` including the following::
2493
+ 1. Create a new create-collection options `Opts ` including the following::
2491
2494
2492
2495
{
2493
2496
encryptedFields: {
@@ -2499,16 +2502,64 @@ rejects an attempt to insert plaintext in an encrypted fields.
2499
2502
}
2500
2503
}
2501
2504
2502
- 3. Open a new database handle `DB `.
2503
- 4. Invoke `CreateEncryptedCollection(CE, DB, "testing1", Opts, "local", null) `
2505
+ 2. Invoke `CreateEncryptedCollection(CE, DB, "testing1", Opts, "local", null) `
2504
2506
to obtain a new collection `Coll `. Expect success.
2505
- 5 . Attempt to insert the following document into `Coll `::
2507
+ 3 . Attempt to insert the following document into `Coll `::
2506
2508
2507
2509
{
2508
2510
ssn: "123-45-6789"
2509
2511
}
2510
2512
2511
- 6 . Expect an error from the insert operation that indicates that the document
2513
+ 4 . Expect an error from the insert operation that indicates that the document
2512
2514
failed validation. This error indicates that the server expects to receive an
2513
2515
encrypted field for ``ssn ``, but we tried to insert a plaintext field via a
2514
- client that is unaware of the encryption requirements.
2516
+ client that is unaware of the encryption requirements.
2517
+
2518
+
2519
+ Case 2: Missing ``encryptedFields ``
2520
+ ```````````````````````````````````
2521
+
2522
+ The CreateEncryptedCollection _ helper should not create a regular collection if
2523
+ there are no ``encryptedFields `` for the collection being created. Instead, it
2524
+ should generate an error indicated that the ``encryptedFields `` option is
2525
+ missing.
2526
+
2527
+ 1. Create a new empty create-collection options `Opts `. (i.e. it must not
2528
+ contain any ``encryptedFields `` options.)
2529
+ 2. Invoke `CreateEncryptedCollection(CE, DB, "testing1", Opts, "local", null) `.
2530
+ 3. Expect the invocation to fail with an error indicating that
2531
+ ``encryptedFields `` is not defined for the collection, and expect that no
2532
+ collection was created within the database. It would be *incorrect * for
2533
+ CreateEncryptedCollection _ to create a regular collection without queryable
2534
+ encryption enabled.
2535
+
2536
+
2537
+ Case 3: Invalid ``keyId ``
2538
+ `````````````````````````
2539
+
2540
+ The CreateEncryptedCollection _ helper only inspects ``encryptedFields.fields ``
2541
+ for ``keyId `` of ``null ``. CreateEncryptedCollection _ should forward all other
2542
+ data as-is, even if it would be malformed. The server should generate an error
2543
+ when attempting to create a collection with such invalid settings.
2544
+
2545
+ .. note ::
2546
+
2547
+ This test is not required if the type system of the driver has a compile-time
2548
+ check that fields' ``keyId ``\ s are of the correct type.
2549
+
2550
+ 1. Create a new create-collection options `Opts ` including the following::
2551
+
2552
+ {
2553
+ encryptedFields: {
2554
+ fields: [{
2555
+ path: "ssn",
2556
+ bsonType: "string",
2557
+ keyId: false,
2558
+ }]
2559
+ }
2560
+ }
2561
+
2562
+ 2. Invoke `CreateEncryptedCollection(CE, DB, "testing1", Opts, "local", null) `.
2563
+ 3. Expect an error from the server indicating a validation error at
2564
+ ``create.encryptedFields.fields.keyId ``, which must be a UUID and not a
2565
+ boolean value.
0 commit comments