@@ -4,9 +4,43 @@ import * as process from 'process';
44import { satisfies } from 'semver' ;
55
66import { kmsCredentialsPresent } from '../../../csfle-kms-providers' ;
7- import { type MongoClient } from '../../../mongodb' ;
7+ import { AutoEncrypter , MongoClient } from '../../../mongodb' ;
88import { Filter } from './filter' ;
99
10+ function getCryptSharedVersion ( ) : AutoEncrypter [ 'cryptSharedLibVersionInfo' ] | null {
11+ try {
12+ const mc = new MongoClient ( 'mongodb://localhost:27017' , {
13+ autoEncryption : {
14+ kmsProviders : {
15+ local : {
16+ key : Buffer . alloc ( 96 )
17+ }
18+ } ,
19+ extraOptions : {
20+ cryptSharedLibPath : process . env . CRYPT_SHARED_LIB_PATH
21+ }
22+ }
23+ } ) ;
24+ return mc . autoEncrypter . cryptSharedLibVersionInfo ;
25+ } catch ( error ) {
26+ try {
27+ const mc = new MongoClient ( 'mongodb://localhost:27017' , {
28+ autoEncryption : {
29+ kmsProviders : {
30+ local : {
31+ key : Buffer . alloc ( 96 )
32+ }
33+ }
34+ }
35+ } ) ;
36+ return mc . autoEncrypter . cryptSharedLibVersionInfo ;
37+ } catch {
38+ }
39+ }
40+
41+ return null ;
42+ }
43+
1044/**
1145 * Filter for whether or not a test needs / doesn't need Client Side Encryption
1246 *
@@ -24,15 +58,18 @@ export class ClientSideEncryptionFilter extends Filter {
2458 enabled : boolean ;
2559 static version = null ;
2660 static libmongocrypt : string | null = null ;
61+ static cryptShared : AutoEncrypter [ 'cryptSharedLibVersionInfo' ] | null = null ;
2762
2863 override async initializeFilter ( client : MongoClient , context : Record < string , any > ) {
29- let mongodbClientEncryption ;
64+ let mongodbClientEncryption : typeof import ( 'mongodb-client-encryption' ) ;
3065 try {
3166 // eslint-disable-next-line @typescript-eslint/no-require-imports
3267 mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
3368 ClientSideEncryptionFilter . libmongocrypt = (
3469 mongodbClientEncryption as typeof import ( 'mongodb-client-encryption' )
3570 ) . MongoCrypt . libmongocryptVersion ;
71+
72+ ClientSideEncryptionFilter . cryptShared = getCryptSharedVersion ( ) ;
3673 } catch ( failedToGetFLELib ) {
3774 if ( process . env . TEST_CSFLE ) {
3875 console . error ( { failedToGetFLELib } ) ;
@@ -53,7 +90,8 @@ export class ClientSideEncryptionFilter extends Filter {
5390 enabled : this . enabled ,
5491 mongodbClientEncryption,
5592 version : ClientSideEncryptionFilter . version ,
56- libmongocrypt : ClientSideEncryptionFilter . libmongocrypt
93+ libmongocrypt : ClientSideEncryptionFilter . libmongocrypt ,
94+ cryptShared : ClientSideEncryptionFilter . cryptShared
5795 } ;
5896 }
5997
0 commit comments