Skip to content

Commit 541c358

Browse files
committed
prefix and suffix tests
1 parent 10d34d7 commit 541c358

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

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

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,8 +3846,7 @@ This section lists the values to use for `TextOpts` for each query type.
38463846
}
38473847
```
38483848

3849-
Use `clientEncryption` to encrypt the string "foobarbaz". Ensure the type matches that of the encrypted field.
3850-
For example, if the encrypted field is `encryptedDoubleNoPrecision` encrypt the value 6.0.
3849+
Use `clientEncryption` to encrypt the string "foobarbaz".
38513850

38523851
Encrypt using the following `EncryptOpts`:
38533852

@@ -3871,3 +3870,58 @@ Use `encryptedClient` to insert the following document into `db.explicit_encrypt
38713870
{ "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
38723871
```
38733872

3873+
#### Case 1: can find a document by prefix
3874+
3875+
Use `clientEncryption.encryptExpression()` to encrypt this query:
3876+
```javascript
3877+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": "foo"}, } }
3878+
```
3879+
3880+
Store the result in `findPayload`.
3881+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3882+
3883+
Assert the following document is returned:
3884+
3885+
```javascript
3886+
{ "_id": 0, "encryptedText": "foobarbaz" }
3887+
```
3888+
3889+
#### Case 2: can find a document by suffix
3890+
3891+
Use `clientEncryption.encryptExpression()` to encrypt this query:
3892+
```javascript
3893+
{ "$expr": { "$encStrEndsWith": {"input": "encryptedText", "suffix": "baz"}, } }
3894+
```
3895+
3896+
Store the result in `findPayload`.
3897+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3898+
3899+
Assert the following document is returned:
3900+
3901+
```javascript
3902+
{ "_id": 0, "encryptedText": "foobarbaz" }
3903+
```
3904+
3905+
#### Case 3: assert no document found by prefix
3906+
3907+
Use `clientEncryption.encryptExpression()` to encrypt this query:
3908+
```javascript
3909+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": "baz"}, } }
3910+
```
3911+
3912+
Store the result in `findPayload`.
3913+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3914+
3915+
Assert that no documents are returned.
3916+
3917+
#### Case 4: assert no document found by suffix
3918+
3919+
Use `clientEncryption.encryptExpression()` to encrypt this query:
3920+
```javascript
3921+
{ "$expr": { "$encStrEndsWith": {"input": "encryptedText", "suffix": "baz"}, } }
3922+
```
3923+
3924+
Store the result in `findPayload`.
3925+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3926+
3927+
Assert that no documents are returned.

0 commit comments

Comments
 (0)