@@ -4,9 +4,44 @@ import * as process from 'process';
44import { satisfies } from 'semver' ;
55
66import { kmsCredentialsPresent } from '../../../csfle-kms-providers' ;
7- import { type MongoClient } from '../../../mongodb' ;
7+ import { type 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 {
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+ // squash errors
39+ }
40+ }
41+
42+ return null ;
43+ }
44+
1045/**
1146 * Filter for whether or not a test needs / doesn't need Client Side Encryption
1247 *
@@ -24,15 +59,18 @@ export class ClientSideEncryptionFilter extends Filter {
2459 enabled : boolean ;
2560 static version = null ;
2661 static libmongocrypt : string | null = null ;
62+ static cryptShared : AutoEncrypter [ 'cryptSharedLibVersionInfo' ] | null = null ;
2763
2864 override async initializeFilter ( client : MongoClient , context : Record < string , any > ) {
29- let mongodbClientEncryption ;
65+ let mongodbClientEncryption : typeof import ( 'mongodb-client-encryption' ) ;
3066 try {
3167 // eslint-disable-next-line @typescript-eslint/no-require-imports
3268 mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
3369 ClientSideEncryptionFilter . libmongocrypt = (
3470 mongodbClientEncryption as typeof import ( 'mongodb-client-encryption' )
3571 ) . MongoCrypt . libmongocryptVersion ;
72+
73+ ClientSideEncryptionFilter . cryptShared = getCryptSharedVersion ( ) ;
3674 } catch ( failedToGetFLELib ) {
3775 if ( process . env . TEST_CSFLE ) {
3876 console . error ( { failedToGetFLELib } ) ;
@@ -53,7 +91,8 @@ export class ClientSideEncryptionFilter extends Filter {
5391 enabled : this . enabled ,
5492 mongodbClientEncryption,
5593 version : ClientSideEncryptionFilter . version ,
56- libmongocrypt : ClientSideEncryptionFilter . libmongocrypt
94+ libmongocrypt : ClientSideEncryptionFilter . libmongocrypt ,
95+ cryptShared : ClientSideEncryptionFilter . cryptShared
5796 } ;
5897 }
5998
0 commit comments