@@ -2,9 +2,11 @@ import * as fs from 'node:fs/promises';
22import * as path from 'node:path' ;
33
44import { expect } from 'chai' ;
5+ import { type MongoCryptOptions } from 'mongodb-client-encryption' ;
6+ import * as sinon from 'sinon' ;
57
68import { getCSFLEKMSProviders } from '../../csfle-kms-providers' ;
7- import { BSON , type Document , type MongoClient } from '../../mongodb' ;
9+ import { AutoEncrypter , BSON , type Document , type MongoClient } from '../../mongodb' ;
810import { type TestConfiguration } from '../../tools/runner/config' ;
911import { getEncryptExtraOptions } from '../../tools/utils' ;
1012
@@ -342,4 +344,70 @@ describe.only('$lookup support', function () {
342344 new Error ( 'Upgrade' ) ,
343345 { requires : { ...defaultMetadata . requires , mongodb : '<8.1.0' } }
344346 ) ;
347+
348+ describe ( 'Node.js custom test' , function ( ) {
349+ describe ( 'when enableMultipleCollinfo is off and a $lookup is run' , function ( ) {
350+ let client : MongoClient ;
351+
352+ beforeEach ( async function ( ) {
353+ const getMongoCrypt = sinon . stub ( AutoEncrypter , 'getMongoCrypt' ) . callsFake ( function ( ) {
354+ const MongoCrypt = getMongoCrypt . wrappedMethod . call ( this ) ;
355+ return class extends MongoCrypt {
356+ constructor ( options : MongoCryptOptions ) {
357+ //@ts -expect-error: not yet in the defs
358+ options . enableMultipleCollinfo = false ;
359+ super ( options ) ;
360+ }
361+ } ;
362+ } ) ;
363+
364+ client = this . configuration . newClient (
365+ { } ,
366+ {
367+ autoEncryption : {
368+ keyVaultNamespace : 'db.keyvault' ,
369+ kmsProviders : { local : getCSFLEKMSProviders ( ) . local } ,
370+ extraOptions : {
371+ cryptSharedLibPath : getEncryptExtraOptions ( ) . cryptSharedLibPath ,
372+ mongocryptdBypassSpawn : true ,
373+ cryptSharedLibRequired : true
374+ }
375+ }
376+ }
377+ ) ;
378+ } ) ;
379+
380+ afterEach ( async function ( ) {
381+ sinon . restore ( ) ;
382+ await client . close ( ) ;
383+ } ) ;
384+
385+ it (
386+ 'throws a TypeError about libmongocrypt not enabled to support multiple collections' ,
387+ defaultMetadata ,
388+ async ( ) => {
389+ const collection = client . db ( 'db' ) . collection ( 'csfle' ) ;
390+ const actual = await collection
391+ . aggregate ( [
392+ { $match : { csfle : 'csfle' } } ,
393+ {
394+ $lookup : {
395+ from : 'csfle2' ,
396+ as : 'matched' ,
397+ pipeline : [ { $match : { csfle2 : 'csfle2' } } , { $project : { _id : 0 } } ]
398+ }
399+ } ,
400+ { $project : { _id : 0 } }
401+ ] )
402+ . toArray ( )
403+ . catch ( error => error ) ;
404+
405+ expect ( actual ) . to . be . instanceOf ( TypeError ) ;
406+ expect ( actual . message ) . to . match (
407+ / l i b m o n g o c r y p t i s n o t c o n f i g u r e d t o s u p p o r t e n c r y p t i n g a c o m m a n d w i t h m u l t i p l e c o l l e c t i o n s / i
408+ ) ;
409+ }
410+ ) ;
411+ } ) ;
412+ } ) ;
345413} ) ;
0 commit comments