@@ -3764,3 +3764,110 @@ class AutoEncryptionOpts {
3764
3764
` ` `
3765
3765
3766
3766
Assert that an error is thrown .
3767
+
3768
+ ### 27. Text Explicit Encryption
3769
+
3770
+ The Text Explicit Encryption tests utilize Queryable Encryption (QE ) range protocol V2 and require MongoDB server
3771
+ 8.2 .0 + and libmongocrypt 1.15 .0 + . The tests must not run against a standalone .
3772
+
3773
+ Before running each of the following test cases , perform the following Test Setup .
3774
+
3775
+ #### Test Setup
3776
+
3777
+ Load the file ` encryptedFields-text.json ` as ` encryptedFields ` .
3778
+
3779
+ Load the file
3780
+ [key1 - document .json ](https :// github.com/mongodb/specifications/tree/master/source/client-side-encryption/etc/data/keys/key1-document.json)
3781
+ as ` key1Document ` .
3782
+
3783
+ Read the ` "_id" ` field of ` key1Document ` as ` key1ID ` .
3784
+
3785
+ Drop and create the collection ` db.explicit_encryption ` using ` encryptedFields ` as an option . See
3786
+ [FLE 2 CreateCollection () and Collection .Drop ()](../ client - side - encryption .md #create - collection - helper ).
3787
+
3788
+ Drop and create the collection ` keyvault.datakeys ` .
3789
+
3790
+ Insert ` key1Document ` in ` keyvault.datakeys ` with majority write concern .
3791
+
3792
+ Create a MongoClient named ` keyVaultClient ` .
3793
+
3794
+ Create a ClientEncryption object named ` clientEncryption ` with these options :
3795
+
3796
+ ` ` ` typescript
3797
+ class ClientEncryptionOpts {
3798
+ keyVaultClient: <keyVaultClient>,
3799
+ keyVaultNamespace: "keyvault.datakeys",
3800
+ kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } },
3801
+ }
3802
+ ` ` `
3803
+
3804
+ Create a MongoClient named ` encryptedClient ` with these ` AutoEncryptionOpts ` :
3805
+
3806
+ ` ` ` typescript
3807
+ class AutoEncryptionOpts {
3808
+ keyVaultNamespace: "keyvault.datakeys",
3809
+ kmsProviders: { "local": { "key": <base64 decoding of LOCAL_MASTERKEY> } },
3810
+ bypassQueryAnalysis: true,
3811
+ }
3812
+ ` ` `
3813
+
3814
+ 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 .
3816
+
3817
+ #### Test Setup : TextOpts
3818
+
3819
+ This section lists the values to use for ` TextOpts ` for each query type .
3820
+
3821
+ 1. Prefix
3822
+
3823
+ ` ` ` typescript
3824
+ class PrefixOpts {
3825
+ strMaxQueryLength: 3,
3826
+ strMinQueryLength: 1,
3827
+ }
3828
+ ` ` `
3829
+
3830
+ 2. Suffix
3831
+
3832
+ ` ` ` typescript
3833
+ class SuffixOpts {
3834
+ strMaxQueryLength: 3,
3835
+ strMinQueryLength: 1,
3836
+ }
3837
+ ` ` `
3838
+
3839
+ 3. Substring
3840
+
3841
+ ` ` ` typescript
3842
+ class SubstringOpts {
3843
+ strMaxLength: 10,
3844
+ strMaxQueryLength: 3,
3845
+ strMinQueryLength: 1,
3846
+ }
3847
+ ` ` `
3848
+
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 .
3851
+
3852
+ Encrypt using the following ` EncryptOpts ` :
3853
+
3854
+ ` ` ` typescript
3855
+ class EncryptOpts {
3856
+ keyId : <key1ID>,
3857
+ algorithm: "TextPreview",
3858
+ contentionFactor: 0,
3859
+ textOpts: TextOpts {
3860
+ caseSensitive: true,
3861
+ diacriticSensitive: true,
3862
+ prefix: <PrefixOpts>,
3863
+ suffix: <SuffixOpts>
3864
+ },
3865
+ }
3866
+ ` ` `
3867
+
3868
+ Use ` encryptedClient ` to insert the following document into ` db.explicit_encryption ` :
3869
+
3870
+ ` ` ` javascript
3871
+ { "_id": 0, "encryptedText": <encrypted "foobarbaz"> }
3872
+ ` ` `
3873
+
0 commit comments