@@ -1148,26 +1148,35 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1148
1148
) ;
1149
1149
} ) ;
1150
1150
1151
- afterEach ( async function ( ) {
1152
- if ( clientEncrypted ) {
1153
- await clientEncrypted . close ( ) ;
1151
+ beforeEach ( 'precondition: the shared library must NOT be loaded' , function ( ) {
1152
+ const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
1153
+ if ( cryptSharedLibPath ) {
1154
+ this . currentTest . skipReason =
1155
+ 'test requires that the shared library NOT is present, but CRYPT_SHARED_LIB_PATH is set.' ;
1156
+ this . skip ( ) ;
1154
1157
}
1158
+ // the presence of the shared library can only be reliably determine after
1159
+ // libmongocrypt has been initialized, and can be detected with the
1160
+ // cryptSharedLibVersionInfo getter on the autoEncrypter.
1161
+ expect ( ! ! clientEncrypted . autoEncrypter . cryptSharedLibVersionInfo ) . to . be . false ;
1162
+ } ) ;
1163
+
1164
+ afterEach ( async function ( ) {
1165
+ await clientEncrypted ?. close ( ) ;
1155
1166
} ) ;
1156
1167
1157
1168
it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
1158
1169
// Use client_encrypted to insert the document {"encrypted": "test"} into db.coll.
1159
1170
// Expect a server selection error propagated from the internal MongoClient failing to connect to mongocryptd on port 27021.
1160
- const insertResult = await clientEncrypted
1171
+ const insertError = await clientEncrypted
1161
1172
. db ( dataDbName )
1162
1173
. collection ( dataCollName )
1163
1174
. insertOne ( { encrypted : 'test' } )
1164
- . then (
1165
- ( ) => 'Insert Succeeded' ,
1166
- err => err
1167
- ) ;
1175
+ . catch ( e => e ) ;
1168
1176
1169
- expect ( insertResult ) . to . be . instanceOf ( Error ) ;
1170
- expect ( insertResult ) . to . have . property ( 'name' , 'MongoServerSelectionError' ) ;
1177
+ expect ( insertError )
1178
+ . to . be . instanceOf ( Error )
1179
+ . to . match ( / c o n n e c t E C O N N R E F U S E D 1 2 7 .0 .0 .1 : 2 7 0 2 1 / ) ;
1171
1180
} ) ;
1172
1181
} ) ;
1173
1182
@@ -1223,23 +1232,34 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1223
1232
expect ( insertResult ) . to . have . property ( 'insertedId' ) ;
1224
1233
} ) ;
1225
1234
1235
+ beforeEach ( 'precondition: the shared library must NOT be loaded' , function ( ) {
1236
+ const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
1237
+ if ( cryptSharedLibPath ) {
1238
+ this . currentTest . skipReason =
1239
+ 'test requires that the shared library NOT is present, but CRYPT_SHARED_LIB_PATH is set.' ;
1240
+ this . skip ( ) ;
1241
+ }
1242
+ // the presence of the shared library can only be reliably determine after
1243
+ // libmongocrypt has been initialized, and can be detected with the
1244
+ // cryptSharedLibVersionInfo getter on the autoEncrypter.
1245
+ expect ( ! ! clientEncrypted . autoEncrypter . cryptSharedLibVersionInfo ) . to . be . false ;
1246
+ } ) ;
1247
+
1226
1248
afterEach ( async function ( ) {
1227
- if ( clientEncrypted ) await clientEncrypted . close ( ) ;
1228
- if ( client ) await client . close ( ) ;
1249
+ await clientEncrypted ? .close ( ) ;
1250
+ await client ? .close ( ) ;
1229
1251
} ) ;
1230
1252
1231
1253
// Validate that mongocryptd was not spawned. Create a MongoClient to localhost:27021
1232
1254
// (or whatever was passed via --port) with serverSelectionTimeoutMS=1000. Run a handshake
1233
1255
// command and ensure it fails with a server selection timeout.
1234
1256
it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
1235
1257
client = new MongoClient ( 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000' ) ;
1236
- const error = await client . connect ( ) . then (
1237
- ( ) => null ,
1238
- err => err
1239
- ) ;
1258
+ const error = await client . connect ( ) . catch ( e => e ) ;
1240
1259
1241
- expect ( error ) . to . be . instanceOf ( MongoServerSelectionError ) ;
1242
- console . log ( error ) ;
1260
+ expect ( error )
1261
+ . to . be . instanceOf ( MongoServerSelectionError )
1262
+ . to . match ( / c o n n e c t E C O N N R E F U S E D 1 2 7 .0 .0 .1 : 2 7 0 2 1 / ) ;
1243
1263
} ) ;
1244
1264
} ) ;
1245
1265
0 commit comments