Skip to content

Commit 8605a54

Browse files
committed
use separate collections for prefix/suffix and substring
1 parent eaa1d25 commit 8605a54

File tree

1 file changed

+49
-72
lines changed

1 file changed

+49
-72
lines changed

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

Lines changed: 49 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,15 +3774,20 @@ Before running each of the following test cases, perform the following Test Setu
37743774

37753775
#### Test Setup
37763776

3777-
Load the file `encryptedFields-prefix-suffix.json` as `encryptedFields`.
3777+
Load the file `encryptedFields-prefix-suffix.json` as `encryptedFields-prefix-suffix`.
3778+
3779+
Load the file `encryptedFields-substring.json` as `encryptedFields-substring`.
37783780

37793781
Load the file
37803782
[key1-document.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/keys/key1-document.json)
37813783
as `key1Document`.
37823784

37833785
Read the `"_id"` field of `key1Document` as `key1ID`.
37843786

3785-
Drop and create the collection `db.explicit_encryption` using `encryptedFields` as an option. See
3787+
Drop and create the collection `db.prefix-suffix` using `encryptedFields-prefix-suffix` as an option. See
3788+
[QE CreateCollection() and Collection.Drop()](../client-side-encryption.md#create-collection-helper).
3789+
3790+
Drop and create the collection `db.substring` using `encryptedFields-substring` as an option. See
37863791
[QE CreateCollection() and Collection.Drop()](../client-side-encryption.md#create-collection-helper).
37873792

37883793
Drop and create the collection `keyvault.datakeys`.
@@ -3829,7 +3834,30 @@ class EncryptOpts {
38293834
}
38303835
```
38313836

3832-
Use `encryptedClient` to insert the following document into `db.explicit_encryption`:
3837+
Use `encryptedClient` to insert the following document into `db.prefix-suffix`:
3838+
3839+
```javascript
3840+
{ "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
3841+
```
3842+
3843+
Use `clientEncryption` to encrypt the string `"foobarbaz"`.
3844+
3845+
Encrypt using the following `EncryptOpts`:
3846+
3847+
```typescript
3848+
class EncryptOpts {
3849+
keyId : <key1ID>,
3850+
algorithm: "TextPreview",
3851+
contentionFactor: 0,
3852+
textOpts: TextOpts {
3853+
caseSensitive: true,
3854+
diacriticSensitive: true,
3855+
substring: <SubstringOpts>
3856+
},
3857+
}
3858+
```
3859+
3860+
Use `encryptedClient` to insert the following document into `db.substring`:
38333861

38343862
```javascript
38353863
{ "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
@@ -3887,17 +3915,14 @@ class EncryptOpts {
38873915

38883916
#### Case 1: can find a document by prefix
38893917

3890-
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`:
3918+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
38913919

3892-
Store this query in `findPayload`.
3920+
Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix` collection with the following filter:
38933921

38943922
```javascript
3895-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <encrypted "foo">}, } }
3923+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
38963924
```
38973925

3898-
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter
3899-
`findPayload`.
3900-
39013926
Assert the following document is returned:
39023927

39033928
```javascript
@@ -3906,17 +3931,14 @@ Assert the following document is returned:
39063931

39073932
#### Case 2: can find a document by suffix
39083933

3909-
Use `clientEncryption.encrypt()` to encrypt the string `"baz"`:
3934+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
39103935

3911-
Store this query in `findPayload`.
3936+
Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix` collection with the following filter:
39123937

39133938
```javascript
3914-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <encrypted "baz">}, } }
3939+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
39153940
```
39163941

3917-
Store the result in `findPayload`. Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption`
3918-
collection with the filter `findPayload`.
3919-
39203942
Assert the following document is returned:
39213943

39223944
```javascript
@@ -3925,80 +3947,38 @@ Assert the following document is returned:
39253947

39263948
#### Case 3: assert no document found by prefix
39273949

3928-
Use `clientEncryption.encrypt()` to encrypt the string `"baz"`:
3950+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
39293951

3930-
Store this query in `findPayload`.
3952+
Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix` collection with the following filter:
39313953

39323954
```javascript
3933-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <encrypted "baz">}, } }
3955+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
39343956
```
39353957

3936-
Store the result in `findPayload`. Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption`
3937-
collection with the filter `findPayload`.
3938-
39393958
Assert that no documents are returned.
39403959

39413960
#### Case 4: assert no document found by suffix
39423961

3943-
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`:
3962+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
39443963

3945-
Store this query in `findPayload`.
3964+
Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix` collection with the following filter:
39463965

39473966
```javascript
3948-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "suffix": <encrypted "foo">}, } }
3967+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "suffix": <findPayload>}, } }
39493968
```
39503969

3951-
Store the result in `findPayload`. Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption`
3952-
collection with the filter `findPayload`.
3953-
39543970
Assert that no documents are returned.
39553971

3956-
#### Substring test setup
3957-
3958-
Load the file `encryptedFields-substring.json` as `encryptedFields`.
3959-
3960-
Load the file
3961-
[key1-document.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/keys/key1-document.json)
3962-
as `key1Document`.
3963-
3964-
Drop and create the collection `db.explicit_encryption` using `encryptedFields` as an option.
3965-
3966-
Use `clientEncryption` to encrypt the string `"foobarbaz"`.
3967-
3968-
Encrypt using the following `EncryptOpts`:
3969-
3970-
```typescript
3971-
class EncryptOpts {
3972-
keyId : <key1ID>,
3973-
algorithm: "TextPreview",
3974-
contentionFactor: 0,
3975-
textOpts: TextOpts {
3976-
caseSensitive: true,
3977-
diacriticSensitive: true,
3978-
substring: <SubstringOpts>
3979-
},
3980-
}
3981-
```
3982-
3983-
Use `encryptedClient` to insert the following document into `db.explicit_encryption`:
3984-
3985-
```javascript
3986-
{ "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
3987-
```
3988-
39893972
#### Case 5: can find a document by substring
39903973

3991-
Use `clientEncryption.encrypt()` to encrypt the string `"bar"`:
3974+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`. Store the resulting payload in `findPayload`.
39923975

3993-
Store this query in `findPayload`.
3976+
Use `encryptedClient` to run a "find" operation on the `db.substring` collection with the following filter:
39943977

39953978
```javascript
3996-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <encrypted "bar">}, } }
3979+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
39973980
```
39983981

3999-
Store the result in `findPayload`. Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption`
4000-
collection with the filter `findPayload`.
4001-
40023982
Assert the following document is returned:
40033983

40043984
```javascript
@@ -4007,15 +3987,12 @@ Assert the following document is returned:
40073987

40083988
#### Case 6: assert no document found by substring
40093989

4010-
Use `clientEncryption.encrypt()` to encrypt the string `"qux"`:
3990+
Use `clientEncryption.encrypt()` to encrypt the string `"qux"`. Store the resulting payload in `findPayload`.
40113991

4012-
Store this query in `findPayload`.
3992+
Use `encryptedClient` to run a "find" operation on the `db.substring` collection with the following filter:
40133993

40143994
```javascript
4015-
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <encrypted "qux">}, } }
3995+
{ "$expr": { "$encStrStartsWith": {"input": "$encryptedText", "prefix": <findPayload>}, } }
40163996
```
40173997

4018-
Store the result in `findPayload`. Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption`
4019-
collection with the filter `findPayload`.
4020-
40213998
Assert that no documents are returned.

0 commit comments

Comments
 (0)