@@ -10,7 +10,7 @@ import { inspect } from 'util';
10
10
import path from 'path' ;
11
11
12
12
describe ( 'FLE tests' , ( ) => {
13
- const testServer = startTestServer ( 'shared' ) ;
13
+ const testServer = startTestServer ( 'not- shared' , '--replicaset' , '--nodes' , '1 ') ;
14
14
skipIfServerVersion ( testServer , '< 4.2' ) ; // FLE only available on 4.2+
15
15
skipIfCommunityServer ( testServer ) ; // FLE is enterprise-only
16
16
useBinaryPath ( testServer ) ; // Get mongocryptd in the PATH for this test
@@ -204,10 +204,9 @@ describe('FLE tests', () => {
204
204
await shell . executeLine ( `autoMongo = Mongo(${ uri } , { \
205
205
keyVaultNamespace: '${ dbname } .keyVault', \
206
206
kmsProviders: { local }, \
207
- schemaMap: schemaMap \
207
+ schemaMap \
208
208
});` ) ;
209
209
210
-
211
210
await shell . executeLine ( `bypassMongo = Mongo(${ uri } , { \
212
211
keyVaultNamespace: '${ dbname } .keyVault', \
213
212
kmsProviders: { local }, \
@@ -237,6 +236,77 @@ describe('FLE tests', () => {
237
236
expect ( plainMongoResult ) . to . not . include ( "phoneNumber: '+12874627836445'" ) ;
238
237
} ) ;
239
238
239
+ context ( '6.0+' , ( ) => {
240
+ skipIfServerVersion ( testServer , '< 6.0' ) ; // FLE2 only available on 6.0+
241
+
242
+ it ( 'drops fle2 collection with all helper collections when encryptedFields options are in listCollections' , async ( ) => {
243
+ const shell = TestShell . start ( {
244
+ args : [ '--nodb' ] ,
245
+ env : {
246
+ ...process . env ,
247
+ MONGOSH_FLE2_SUPPORT : 'true'
248
+ } ,
249
+ } ) ;
250
+ const uri = JSON . stringify ( await testServer . connectionString ( ) ) ;
251
+
252
+ await shell . waitForPrompt ( ) ;
253
+
254
+ await shell . executeLine ( 'local = { key: BinData(0, "kh4Gv2N8qopZQMQYMEtww/AkPsIrXNmEMxTrs3tUoTQZbZu4msdRUaR8U5fXD7A7QXYHcEvuu4WctJLoT+NvvV3eeIg3MD+K8H9SR794m/safgRHdIfy6PD+rFpvmFbY") }' ) ;
255
+
256
+ await shell . executeLine ( `keyMongo = Mongo(${ uri } , { \
257
+ keyVaultNamespace: '${ dbname } .keyVault', \
258
+ kmsProviders: { local } \
259
+ });` ) ;
260
+
261
+ await shell . executeLine ( 'keyVault = keyMongo.getKeyVault();' ) ;
262
+ await shell . executeLine ( 'keyId = keyVault.createKey("local");' ) ;
263
+
264
+ await shell . executeLine ( `encryptedFieldsMap = { \
265
+ '${ dbname } .collfle2': { \
266
+ fields: [{ path: 'phoneNumber', keyId, bsonType: 'string' }] \
267
+ } \
268
+ };` ) ;
269
+
270
+ await shell . executeLine ( `autoMongo = Mongo(${ uri } , { \
271
+ keyVaultNamespace: '${ dbname } .keyVault', \
272
+ kmsProviders: { local }, \
273
+ encryptedFieldsMap \
274
+ });` ) ;
275
+
276
+ // Drivers will create the auxilliary FLE2 collections only when explicitly creating collections
277
+ // via the createCollection() command.
278
+ await shell . executeLine ( `autoMongo.getDB('${ dbname } ').createCollection('collfle2');` ) ;
279
+ await shell . executeLine ( `autoMongo.getDB('${ dbname } ').collfle2.insertOne({ \
280
+ phoneNumber: '+12874627836445' \
281
+ });` ) ;
282
+
283
+ const autoMongoResult = await shell . executeLine ( `autoMongo.getDB('${ dbname } ').collfle2.find()` ) ;
284
+ expect ( autoMongoResult ) . to . include ( "phoneNumber: '+12874627836445'" ) ;
285
+
286
+ await shell . executeLine ( `plainMongo = Mongo(${ uri } );` ) ;
287
+
288
+ const plainMongoResult = await shell . executeLine ( `plainMongo.getDB('${ dbname } ').collfle2.find()` ) ;
289
+ expect ( plainMongoResult ) . to . include ( 'phoneNumber: Binary(Buffer.from' ) ;
290
+ expect ( plainMongoResult ) . to . not . include ( "phoneNumber: '+12874627836445'" ) ;
291
+
292
+ let collections = await shell . executeLine ( `plainMongo.getDB('${ dbname } ').getCollectionNames()` ) ;
293
+
294
+ expect ( collections ) . to . include ( 'enxcol_.collfle2.ecc' ) ;
295
+ expect ( collections ) . to . include ( 'enxcol_.collfle2.esc' ) ;
296
+ expect ( collections ) . to . include ( 'enxcol_.collfle2.ecoc' ) ;
297
+ expect ( collections ) . to . include ( 'collfle2' ) ;
298
+
299
+ await shell . executeLine ( `plainMongo.getDB('${ dbname } ').collfle2.drop();` ) ;
300
+
301
+ collections = await shell . executeLine ( `plainMongo.getDB('${ dbname } ').getCollectionNames()` ) ;
302
+
303
+ expect ( collections ) . to . not . include ( 'enxcol_.collfle2.ecc' ) ;
304
+ expect ( collections ) . to . not . include ( 'enxcol_.collfle2.esc' ) ;
305
+ expect ( collections ) . to . not . include ( 'enxcol_.collfle2.ecoc' ) ;
306
+ expect ( collections ) . to . not . include ( 'collfle2' ) ;
307
+ } ) ;
308
+ } ) ;
309
+
240
310
it ( 'performs KeyVault data key management as expected' , async ( ) => {
241
311
const shell = TestShell . start ( {
242
312
args : [ await testServer . connectionString ( ) ]
0 commit comments