diff --git a/source/client-side-encryption/etc/data/encryptedFields-prefix-suffix-ci-di.json b/source/client-side-encryption/etc/data/encryptedFields-prefix-suffix-ci-di.json new file mode 100644 index 0000000000..c43bf9390d --- /dev/null +++ b/source/client-side-encryption/etc/data/encryptedFields-prefix-suffix-ci-di.json @@ -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 + } + ] + } + ] +} diff --git a/source/client-side-encryption/tests/README.md b/source/client-side-encryption/tests/README.md index 2b6d7b9933..624d920ffa 100644 --- a/source/client-side-encryption/tests/README.md +++ b/source/client-side-encryption/tests/README.md @@ -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) @@ -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": } }, +} +``` + +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 @@ -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 + +`"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 : , + 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: } } } +``` + +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 : , + 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: } } } +``` + +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": } }, +} +``` + +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 : , + 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: } } } +``` + +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 : , + 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: } } } +``` + +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 : , + 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": } +``` + +Use `clientEncryption.encrypt()` to encrypt the string `"bar"` with the following `EncryptOpts`: + +```typescript +class EncryptOpts { + keyId : , + 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: } } } +``` + +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 : , + 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": } +``` + +Use `clientEncryption.encrypt()` to encrypt the string `"cafe"` with the following `EncryptOpts`: + +```typescript +class EncryptOpts { + keyId : , + 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: } } } +``` + +Assert the following document is returned: + +```javascript +{ "encryptedText": "foocafébaz" } +```