Skip to content

Commit 64cf83b

Browse files
Define additional error-checking cases for CreateEncryptedCollection (#1347)
- Test: `encryptedFields` is absent. - Test: `keyId` has an incorrect type.
1 parent 35b17b7 commit 64cf83b

File tree

1 file changed

+67
-16
lines changed

1 file changed

+67
-16
lines changed

source/client-side-encryption/tests/README.rst

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,19 @@ The following tests that a mongocryptd client is not created when shared library
24642464
21. Automatic Data Encryption Keys
24652465
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24662466

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+
24672480
Case 1: Simple Creation and Validation
24682481
``````````````````````````````````````
24692482

@@ -2477,17 +2490,7 @@ rejects an attempt to insert plaintext in an encrypted fields.
24772490
.. highlight:: typescript
24782491
.. default-role:: math
24792492

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::
24912494

24922495
{
24932496
encryptedFields: {
@@ -2499,16 +2502,64 @@ rejects an attempt to insert plaintext in an encrypted fields.
24992502
}
25002503
}
25012504

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)`
25042506
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`::
25062508

25072509
{
25082510
ssn: "123-45-6789"
25092511
}
25102512

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
25122514
failed validation. This error indicates that the server expects to receive an
25132515
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

Comments
 (0)