@@ -1148,26 +1148,35 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
11481148 ) ;
11491149 } ) ;
11501150
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 ( ) ;
11541157 }
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 ( ) ;
11551166 } ) ;
11561167
11571168 it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
11581169 // Use client_encrypted to insert the document {"encrypted": "test"} into db.coll.
11591170 // 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
11611172 . db ( dataDbName )
11621173 . collection ( dataCollName )
11631174 . insertOne ( { encrypted : 'test' } )
1164- . then (
1165- ( ) => 'Insert Succeeded' ,
1166- err => err
1167- ) ;
1175+ . catch ( e => e ) ;
11681176
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 / ) ;
11711180 } ) ;
11721181 } ) ;
11731182
@@ -1223,23 +1232,34 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
12231232 expect ( insertResult ) . to . have . property ( 'insertedId' ) ;
12241233 } ) ;
12251234
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+
12261248 afterEach ( async function ( ) {
1227- if ( clientEncrypted ) await clientEncrypted . close ( ) ;
1228- if ( client ) await client . close ( ) ;
1249+ await clientEncrypted ? .close ( ) ;
1250+ await client ? .close ( ) ;
12291251 } ) ;
12301252
12311253 // Validate that mongocryptd was not spawned. Create a MongoClient to localhost:27021
12321254 // (or whatever was passed via --port) with serverSelectionTimeoutMS=1000. Run a handshake
12331255 // command and ensure it fails with a server selection timeout.
12341256 it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
12351257 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 ) ;
12401259
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 / ) ;
12431263 } ) ;
12441264 } ) ;
12451265
0 commit comments