Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"fields": [
{
"keyId": {
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
"path": "encryptedText",
"bsonType": "string",
"queries": [
{
"queryType": "prefixPreview",
"strMinQueryLength": {
"$numberInt": "2"
},
"strMaxQueryLength": {
"$numberInt": "10"
},
"contention": 0,
"caseSensitive": false,
"diacriticSensitive": false
},
{
"queryType": "suffixPreview",
"strMinQueryLength": {
"$numberInt": "2"
},
"strMaxQueryLength": {
"$numberInt": "10"
},
"contention": 0,
"caseSensitive": false,
"diacriticSensitive": false
}
]
}
]
}
284 changes: 284 additions & 0 deletions source/client-side-encryption/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,9 @@ create the following collections with majority write concern:
- `db.prefix-suffix` using the `encryptedFields` option set to the contents of
[encryptedFields-prefix-suffix.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/encryptedFields-prefix-suffix.json).
Skip this step if testing server 9.0.0+.
- `db.prefix-suffix-ci-di` using the `encryptedFields` option set to the contents of
[encryptedFields-prefix-suffix-ci-di.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/encryptedFields-prefix-suffix-ci-di.json).
Skip this step if testing server 9.0.0+.
- `db.substring` using the `encryptedFields` option set to the contents of
[encryptedFields-substring.json](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/encryptedFields-substring.json)

Expand Down Expand Up @@ -3921,6 +3924,22 @@ class AutoEncryptionOpts {
}
```

Create a MongoClient with auto-encryption enabled (without `bypassQueryAnalysis`) using these `AutoEncryptionOpts`:

```typescript
class AutoEncryptionOpts {
keyVaultNamespace: "keyvault.datakeys",
kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } },
}
```

Use that client to insert the following document into `db.prefix-suffix-ci-di` with majority write concern. Skip this
step if testing server 9.0.0+.

```javascript
{ "encryptedText": "BingQiLin" }
```

Use `clientEncryption` to encrypt the string `"foobarbaz"` with the following `EncryptOpts`:

```typescript
Expand Down Expand Up @@ -4194,3 +4213,268 @@ class EncryptOpts {

Expect an error from libmongocrypt with a message containing the string: "contention factor is required for textPreview
algorithm".

#### Case 8: can find a case and diacritic-insensitively indexed document by prefix and suffix
Copy link
Copy Markdown
Contributor

@kevinAlbs kevinAlbs May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note: "Skip this test case if testing MongoDB server 9.0.0+." note (similar to Case 7) to cases 8 and 9 (requiring prefixPreview and suffixPreview).

And note that libmongocrypt 1.18.1 is required for test cases 8 and 9 since those are regression tests for MONGOCRYPT-903.


`"BingQiLin"` was inserted via auto-encryption in Test Setup, indexed under the
`caseSensitive: false, diacriticSensitive: false` prefix configuration and the
`caseSensitive: false, diacriticSensitive: false` suffix configuration of `db.prefix-suffix-ci-di`.

Use `clientEncryption.encrypt()` to encrypt the string `"bing"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "prefix",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: false,
diacriticSensitive: false,
prefix: PrefixOpts {
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix-ci-di` collection with the following filter:

```javascript
{ $expr: { $encStrStartsWith: {input: '$encryptedText', prefix: <encrypted 'bing'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "BingQiLin" }
```

Use `clientEncryption.encrypt()` to encrypt the string `"lin"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "suffix",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: false,
diacriticSensitive: true,
suffix: SuffixOpts {
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix-ci-di` collection with the following filter:

```javascript
{ $expr: { $encStrEndsWith: {input: '$encryptedText', suffix: <encrypted 'lin'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "BingQiLin" }
```

#### Case 9: can find a diacritic-insensitively indexed document by prefix and suffix

Create a MongoClient with auto-encryption enabled (without `bypassQueryAnalysis`) using these `AutoEncryptionOpts`:

```typescript
class AutoEncryptionOpts {
keyVaultNamespace: "keyvault.datakeys",
kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } },
}
```

Use that client to insert the following document into `db.prefix-suffix-ci-di` with majority write concern:

```javascript
{ "encryptedText": "cafébarbäz" }
```

Use `clientEncryption.encrypt()` to encrypt the string `"cafe"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "prefix",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: true,
diacriticSensitive: false,
prefix: PrefixOpts {
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix-ci-di` collection with the following filter:

```javascript
{ $expr: { $encStrStartsWith: {input: '$encryptedText', prefix: <encrypted 'cafe'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "cafébarbäz" }
```

Use `clientEncryption.encrypt()` to encrypt the string `"baz"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "suffix",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: true,
diacriticSensitive: false,
suffix: SuffixOpts {
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.prefix-suffix-ci-di` collection with the following filter:

```javascript
{ $expr: { $encStrEndsWith: {input: '$encryptedText', suffix: <encrypted 'baz'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "cafébarbäz" }
```

#### Case 10: can find a case-insensitively indexed document by substring

Use `clientEncryption.encrypt()` to encrypt the string `"FooBarBaz"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: false,
diacriticSensitive: true,
substring: SubstringOpts {
strMaxLength: 10,
strMaxQueryLength: 10,
strMinQueryLength: 2,
},
},
}
```

Use `encryptedClient` to insert the following document into `db.substring` with majority write concern:

```javascript
{ "encryptedText": <encrypted 'FooBarBaz'> }
```

Use `clientEncryption.encrypt()` to encrypt the string `"bar"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "substring",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: false,
diacriticSensitive: true,
substring: SubstringOpts {
strMaxLength: 10,
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.substring` collection with the following filter:

```javascript
{ $expr: { $encStrContains: {input: '$encryptedText', substring: <encrypted 'bar'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "FooBarBaz" }
```

#### Case 11: can find a diacritic-insensitively indexed document by substring

Use `clientEncryption.encrypt()` to encrypt the string `"foocafébaz"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: true,
diacriticSensitive: false,
substring: SubstringOpts {
strMaxLength: 10,
strMaxQueryLength: 10,
strMinQueryLength: 2,
},
},
}
```

Use `encryptedClient` to insert the following document into `db.substring` with majority write concern:

```javascript
{ "encryptedText": <encrypted 'foocafébaz'> }
```

Use `clientEncryption.encrypt()` to encrypt the string `"cafe"` with the following `EncryptOpts`:

```typescript
class EncryptOpts {
keyId : <key1ID>,
algorithm: "TextPreview",
queryType: "substring",
contentionFactor: 0,
textOpts: TextOpts {
caseSensitive: true,
diacriticSensitive: false,
substring: SubstringOpts {
strMaxLength: 10,
strMaxQueryLength: 10,
strMinQueryLength: 2,
}
},
}
```

Use `encryptedClient` to run a "find" operation on the `db.substring` collection with the following filter:

```javascript
{ $expr: { $encStrContains: {input: '$encryptedText', substring: <encrypted 'cafe'>} } }
```

Assert the following document is returned:

```javascript
{ "encryptedText": "foocafébaz" }
```
Loading