@@ -4,9 +4,43 @@ import * as process from 'process';
4
4
import { satisfies } from 'semver' ;
5
5
6
6
import { kmsCredentialsPresent } from '../../../csfle-kms-providers' ;
7
- import { type MongoClient } from '../../../mongodb' ;
7
+ import { AutoEncrypter , MongoClient } from '../../../mongodb' ;
8
8
import { Filter } from './filter' ;
9
9
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
+
10
44
/**
11
45
* Filter for whether or not a test needs / doesn't need Client Side Encryption
12
46
*
@@ -24,15 +58,18 @@ export class ClientSideEncryptionFilter extends Filter {
24
58
enabled : boolean ;
25
59
static version = null ;
26
60
static libmongocrypt : string | null = null ;
61
+ static cryptShared : AutoEncrypter [ 'cryptSharedLibVersionInfo' ] | null = null ;
27
62
28
63
override async initializeFilter ( client : MongoClient , context : Record < string , any > ) {
29
- let mongodbClientEncryption ;
64
+ let mongodbClientEncryption : typeof import ( 'mongodb-client-encryption' ) ;
30
65
try {
31
66
// eslint-disable-next-line @typescript-eslint/no-require-imports
32
67
mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
33
68
ClientSideEncryptionFilter . libmongocrypt = (
34
69
mongodbClientEncryption as typeof import ( 'mongodb-client-encryption' )
35
70
) . MongoCrypt . libmongocryptVersion ;
71
+
72
+ ClientSideEncryptionFilter . cryptShared = getCryptSharedVersion ( ) ;
36
73
} catch ( failedToGetFLELib ) {
37
74
if ( process . env . TEST_CSFLE ) {
38
75
console . error ( { failedToGetFLELib } ) ;
@@ -53,7 +90,8 @@ export class ClientSideEncryptionFilter extends Filter {
53
90
enabled : this . enabled ,
54
91
mongodbClientEncryption,
55
92
version : ClientSideEncryptionFilter . version ,
56
- libmongocrypt : ClientSideEncryptionFilter . libmongocrypt
93
+ libmongocrypt : ClientSideEncryptionFilter . libmongocrypt ,
94
+ cryptShared : ClientSideEncryptionFilter . cryptShared
57
95
} ;
58
96
}
59
97
0 commit comments