@@ -3,6 +3,7 @@ import { join } from 'node:path';
33
44import { type Binary , type Document , EJSON } from 'bson' ;
55import { expect } from 'chai' ;
6+ import * as semver from 'semver' ;
67
78import { getCSFLEKMSProviders } from '../../csfle-kms-providers' ;
89import { ClientEncryption , type MongoClient , MongoDBCollectionNamespace } from '../../mongodb' ;
@@ -14,6 +15,15 @@ const metadata: MongoDBMetadataUI = {
1415 libmongocrypt : '>=1.15.1'
1516 }
1617} ;
18+ // # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
19+ const metadataWithoutPreview : MongoDBMetadataUI = {
20+ requires : {
21+ clientSideEncryption : '>=6.4.0' ,
22+ mongodb : '>=8.2.0 <9.0.0' ,
23+ topology : '!single' ,
24+ libmongocrypt : '>=1.15.1'
25+ }
26+ } ;
1727
1828const loadFLEDataFile = async ( filename : string ) =>
1929 EJSON . parse (
@@ -33,9 +43,12 @@ describe('27. Text Explicit Encryption', function () {
3343
3444 beforeEach ( async function ( ) {
3545 utilClient = this . configuration . newClient ( ) ;
46+ const isServer9OrAbove = semver . satisfies ( this . configuration . version , '>=9.0.0' ) ;
47+ const shouldRunPrefixSuffixTests = ! isServer9OrAbove ;
3648
3749 // Using QE CreateCollection() and Collection.Drop(), drop and create the following collections with majority write concern:
3850 // - db.prefix-suffix using the encryptedFields option set to the contents of encryptedFields-prefix-suffix.json
51+ // Skip this step if testing server 9.0.0+.
3952 // - db.substring using the encryptedFields option set to the contents of encryptedFields-substring.json
4053 async function dropAndCreateCollection ( ns : string , encryptedFields ?: Document ) {
4154 const { db, collection } = MongoDBCollectionNamespace . fromString ( ns ) ;
@@ -49,10 +62,12 @@ describe('27. Text Explicit Encryption', function () {
4962 } ) ;
5063 }
5164
52- await dropAndCreateCollection (
53- 'db.prefix-suffix' ,
54- await loadFLEDataFile ( 'encryptedFields-prefix-suffix.json' )
55- ) ;
65+ if ( shouldRunPrefixSuffixTests ) {
66+ await dropAndCreateCollection (
67+ 'db.prefix-suffix' ,
68+ await loadFLEDataFile ( 'encryptedFields-prefix-suffix.json' )
69+ ) ;
70+ }
5671 await dropAndCreateCollection (
5772 'db.substring' ,
5873 await loadFLEDataFile ( 'encryptedFields-substring.json' )
@@ -144,18 +159,20 @@ describe('27. Text Explicit Encryption', function () {
144159 }
145160 } ) ;
146161
147- // Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern:
148- // { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> }
149- await encryptedClient
150- . db ( 'db' )
151- . collection < { _id : number ; encryptedText : Binary } > ( 'prefix-suffix' )
152- . insertOne (
153- {
154- _id : 0 ,
155- encryptedText
156- } ,
157- { writeConcern : { w : 'majority' } }
158- ) ;
162+ if ( shouldRunPrefixSuffixTests ) {
163+ // Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern:
164+ // { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> }
165+ await encryptedClient
166+ . db ( 'db' )
167+ . collection < { _id : number ; encryptedText : Binary } > ( 'prefix-suffix' )
168+ . insertOne (
169+ {
170+ _id : 0 ,
171+ encryptedText
172+ } ,
173+ { writeConcern : { w : 'majority' } }
174+ ) ;
175+ }
159176 }
160177
161178 {
@@ -208,7 +225,8 @@ describe('27. Text Explicit Encryption', function () {
208225 await Promise . allSettled ( [ utilClient . close ( ) , encryptedClient . close ( ) , keyVaultClient . close ( ) ] ) ;
209226 } ) ;
210227
211- it ( 'Case 1: can find a document by prefix' , metadata , async function ( ) {
228+ it ( 'Case 1: can find a document by prefix' , metadataWithoutPreview , async function ( ) {
229+ // Skip this test case if testing MongoDB server 9.0.0+.
212230 // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
213231 // class EncryptOpts {
214232 // keyId : <key1ID>,
@@ -260,7 +278,8 @@ describe('27. Text Explicit Encryption', function () {
260278 expect ( result ) . to . deep . equal ( { _id : 0 , encryptedText : 'foobarbaz' } ) ;
261279 } ) ;
262280
263- it ( 'Case 2: can find a document by suffix' , metadata , async function ( ) {
281+ it ( 'Case 2: can find a document by suffix' , metadataWithoutPreview , async function ( ) {
282+ // Skip this test case if testing MongoDB server 9.0.0+.
264283 // Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts:
265284 // class EncryptOpts {
266285 // keyId : <key1ID>,
@@ -311,7 +330,8 @@ describe('27. Text Explicit Encryption', function () {
311330 expect ( result ) . to . deep . equal ( { _id : 0 , encryptedText : 'foobarbaz' } ) ;
312331 } ) ;
313332
314- it ( 'Case 3: assert no document found by prefix' , metadata , async function ( ) {
333+ it ( 'Case 3: assert no document found by prefix' , metadataWithoutPreview , async function ( ) {
334+ // Skip this test case if testing MongoDB server 9.0.0+.
315335 // Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts:
316336 // class EncryptOpts {
317337 // keyId : <key1ID>,
@@ -351,7 +371,8 @@ describe('27. Text Explicit Encryption', function () {
351371 expect ( await encryptedClient . db ( 'db' ) . collection ( 'prefix-suffix' ) . findOne ( filter ) ) . to . be . null ;
352372 } ) ;
353373
354- it ( 'Case 4: assert no document found by suffix' , metadata , async function ( ) {
374+ it ( 'Case 4: assert no document found by suffix' , metadataWithoutPreview , async function ( ) {
375+ // Skip this test case if testing MongoDB server 9.0.0+.
355376 // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
356377 // class EncryptOpts {
357378 // keyId : <key1ID>,
@@ -497,7 +518,8 @@ describe('27. Text Explicit Encryption', function () {
497518 expect ( result ) . to . be . null ;
498519 } ) ;
499520
500- it ( 'Case 7: assert contentionFactor is required' , metadata , async function ( ) {
521+ it ( 'Case 7: assert contentionFactor is required' , metadataWithoutPreview , async function ( ) {
522+ // Skip this test case if testing MongoDB server 9.0.0+.
501523 // Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
502524 // class EncryptOpts {
503525 // keyId : <key1ID>,
0 commit comments