Skip to content

Commit 6b560e1

Browse files
committed
encrypt just the value, not query
1 parent 541c358 commit 6b560e1

File tree

3 files changed

+171
-20
lines changed

3 files changed

+171
-20
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encrypted-textPreview",
11+
"bsonType": "string",
12+
"queries": [
13+
{
14+
"queryType": "prefixPreview",
15+
"strMinQueryLength": {
16+
"$numberInt": "2"
17+
},
18+
"strMaxQueryLength": {
19+
"$numberInt": "10"
20+
},
21+
"caseSensitive": true,
22+
"diacriticSensitive": true
23+
},
24+
{
25+
"queryType": "suffixPreview",
26+
"strMinQueryLength": {
27+
"$numberInt": "2"
28+
},
29+
"strMaxQueryLength": {
30+
"$numberInt": "10"
31+
},
32+
"caseSensitive": true,
33+
"diacriticSensitive": true
34+
}
35+
]
36+
}
37+
]
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"fields": [
3+
{
4+
"keyId": {
5+
"$binary": {
6+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
7+
"subType": "04"
8+
}
9+
},
10+
"path": "encrypted-textPreview",
11+
"bsonType": "string",
12+
"queries": [
13+
{
14+
"queryType": "substringPreview",
15+
"strMaxLength": {
16+
"$numberInt": "10"
17+
},
18+
"strMinQueryLength": {
19+
"$numberInt": "2"
20+
},
21+
"strMaxQueryLength": {
22+
"$numberInt": "10"
23+
},
24+
"caseSensitive": true,
25+
"diacriticSensitive": true
26+
}
27+
]
28+
}
29+
]
30+
}

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

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

37753775
#### Test Setup
37763776

3777-
Load the file `encryptedFields-text.json` as `encryptedFields`.
3777+
Load the file `encryptedFields-prefix-suffix.json` as `encryptedFields`.
37783778

37793779
Load the file
37803780
[key1-document.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/keys/key1-document.json)
@@ -3812,27 +3812,41 @@ class AutoEncryptionOpts {
38123812
```
38133813

38143814
The remaining tasks require setting `TextOpts`. [Test Setup: TextOpts](#test-setup-textopts) lists the values to use
3815-
for `RangeOpts` for each of the supported data types.
3815+
for `TextOpts` for each of the supported data types.
38163816

38173817
#### Test Setup: TextOpts
38183818

3819-
This section lists the values to use for `TextOpts` for each query type.
3819+
This section lists the values to use for `TextOpts` for each query type. Include the matching options in the following
3820+
`EncryptOpts` for each query:
3821+
3822+
```typescript
3823+
class EncryptOpts {
3824+
keyId : <key1ID>,
3825+
algorithm: "TextPreview",
3826+
contentionFactor: 0,
3827+
textOpts: TextOpts {
3828+
caseSensitive: true,
3829+
diacriticSensitive: true,
3830+
<prefix/suffix/substring>: <matching opts>
3831+
},
3832+
}
3833+
```
38203834

38213835
1. Prefix
38223836

38233837
```typescript
38243838
class PrefixOpts {
3825-
strMaxQueryLength: 3,
3826-
strMinQueryLength: 1,
3839+
strMaxQueryLength: 10,
3840+
strMinQueryLength: 2,
38273841
}
38283842
```
38293843

38303844
2. Suffix
38313845

38323846
```typescript
38333847
class SuffixOpts {
3834-
strMaxQueryLength: 3,
3835-
strMinQueryLength: 1,
3848+
strMaxQueryLength: 10,
3849+
strMinQueryLength: 2,
38363850
}
38373851
```
38383852

@@ -3841,12 +3855,12 @@ This section lists the values to use for `TextOpts` for each query type.
38413855
```typescript
38423856
class SubstringOpts {
38433857
strMaxLength: 10,
3844-
strMaxQueryLength: 3,
3845-
strMinQueryLength: 1,
3858+
strMaxQueryLength: 10,
3859+
strMinQueryLength: 2,
38463860
}
38473861
```
38483862

3849-
Use `clientEncryption` to encrypt the string "foobarbaz".
3863+
Use `clientEncryption` to encrypt the string `"foobarbaz"`.
38503864

38513865
Encrypt using the following `EncryptOpts`:
38523866

@@ -3872,12 +3886,12 @@ Use `encryptedClient` to insert the following document into `db.explicit_encrypt
38723886

38733887
#### Case 1: can find a document by prefix
38743888

3875-
Use `clientEncryption.encryptExpression()` to encrypt this query:
3889+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`:
3890+
3891+
Store this query in `findPayload`.
38763892
```javascript
3877-
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": "foo"}, } }
3893+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": <encrypted "foo">}, } }
38783894
```
3879-
3880-
Store the result in `findPayload`.
38813895
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
38823896

38833897
Assert the following document is returned:
@@ -3888,9 +3902,11 @@ Assert the following document is returned:
38883902

38893903
#### Case 2: can find a document by suffix
38903904

3891-
Use `clientEncryption.encryptExpression()` to encrypt this query:
3905+
Use `clientEncryption.encrypt()` to encrypt the string `"baz"`:
3906+
3907+
Store this query in `findPayload`.
38923908
```javascript
3893-
{ "$expr": { "$encStrEndsWith": {"input": "encryptedText", "suffix": "baz"}, } }
3909+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": <encrypted "baz">}, } }
38943910
```
38953911

38963912
Store the result in `findPayload`.
@@ -3904,9 +3920,11 @@ Assert the following document is returned:
39043920

39053921
#### Case 3: assert no document found by prefix
39063922

3907-
Use `clientEncryption.encryptExpression()` to encrypt this query:
3923+
Use `clientEncryption.encrypt()` to encrypt the string `"baz"`:
3924+
3925+
Store this query in `findPayload`.
39083926
```javascript
3909-
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": "baz"}, } }
3927+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": <encrypted "baz">}, } }
39103928
```
39113929

39123930
Store the result in `findPayload`.
@@ -3916,9 +3934,74 @@ Assert that no documents are returned.
39163934

39173935
#### Case 4: assert no document found by suffix
39183936

3919-
Use `clientEncryption.encryptExpression()` to encrypt this query:
3937+
Use `clientEncryption.encrypt()` to encrypt the string `"foo"`:
3938+
3939+
Store this query in `findPayload`.
3940+
```javascript
3941+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "suffix": <encrypted "foo">}, } }
3942+
```
3943+
3944+
Store the result in `findPayload`.
3945+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3946+
3947+
Assert that no documents are returned.
3948+
3949+
#### Substring test setup
3950+
Load the file `encryptedFields-substring.json` as `encryptedFields`.
3951+
3952+
Load the file
3953+
[key1-document.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/keys/key1-document.json)
3954+
as `key1Document`.
3955+
3956+
Drop and create the collection `db.explicit_encryption` using `encryptedFields` as an option.
3957+
3958+
Use `clientEncryption` to encrypt the string `"foobarbaz"`.
3959+
3960+
Encrypt using the following `EncryptOpts`:
3961+
3962+
```typescript
3963+
class EncryptOpts {
3964+
keyId : <key1ID>,
3965+
algorithm: "TextPreview",
3966+
contentionFactor: 0,
3967+
textOpts: TextOpts {
3968+
caseSensitive: true,
3969+
diacriticSensitive: true,
3970+
substring: <SubstringOpts>
3971+
},
3972+
}
3973+
```
3974+
3975+
Use `encryptedClient` to insert the following document into `db.explicit_encryption`:
3976+
3977+
```javascript
3978+
{ "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
3979+
```
3980+
3981+
#### Case 5: can find a document by substring
3982+
Use `clientEncryption.encrypt()` to encrypt the string `"bar"`:
3983+
3984+
Store this query in `findPayload`.
3985+
```javascript
3986+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": <encrypted "bar">}, } }
3987+
```
3988+
3989+
Store the result in `findPayload`.
3990+
Use `encryptedClient` to run a "find" operation on the `db.explicit_encryption` collection with the filter `findPayload`.
3991+
3992+
Assert the following document is returned:
3993+
3994+
```javascript
3995+
{ "_id": 0, "encryptedText": "foobarbaz" }
3996+
```
3997+
3998+
#### Case 6: assert no document found by substring
3999+
4000+
Use `clientEncryption.encrypt()` to encrypt the string `"qux"`:
4001+
4002+
Store this query in `findPayload`.
39204003
```javascript
3921-
{ "$expr": { "$encStrEndsWith": {"input": "encryptedText", "suffix": "baz"}, } }
4004+
{ "$expr": { "$encStrStartsWith": {"input": "encryptedText", "prefix": <encrypted "qux">}, } }
39224005
```
39234006

39244007
Store the result in `findPayload`.

0 commit comments

Comments
 (0)