@@ -40,6 +40,7 @@ const getKmsProviders = (localKey, kmipEndpoint, azureEndpoint, gcpEndpoint) =>
4040} ;
4141
4242const noop = ( ) => { } ;
43+ /** @type { MongoDBMetadataUI } */
4344const metadata = {
4445 requires : {
4546 clientSideEncryption : true ,
@@ -1146,47 +1147,43 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
11461147 ) ;
11471148 } ) ;
11481149
1149- beforeEach ( 'precondition: the shared library must NOT be loaded' , function ( ) {
1150- const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
1151- if ( cryptSharedLibPath ) {
1152- this . currentTest . skipReason =
1153- 'test requires that the shared library NOT is present, but CRYPT_SHARED_LIB_PATH is set.' ;
1154- this . skip ( ) ;
1155- }
1156- // the presence of the shared library can only be reliably determine after
1157- // libmongocrypt has been initialized, and can be detected with the
1158- // cryptSharedLibVersionInfo getter on the autoEncrypter.
1159- expect ( ! ! clientEncrypted . autoEncrypter . cryptSharedLibVersionInfo ) . to . be . false ;
1160- } ) ;
1161-
11621150 afterEach ( async function ( ) {
11631151 await clientEncrypted ?. close ( ) ;
11641152 } ) ;
11651153
1166- it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
1167- // Use client_encrypted to insert the document {"encrypted": "test"} into db.coll.
1168- // Expect a server selection error propagated from the internal MongoClient failing to connect to mongocryptd on port 27021.
1169- const insertError = await clientEncrypted
1170- . db ( dataDbName )
1171- . collection ( dataCollName )
1172- . insertOne ( { encrypted : 'test' } )
1173- . catch ( e => e ) ;
1154+ it (
1155+ 'does not spawn mongocryptd' ,
1156+ {
1157+ requires : {
1158+ ...metadata . requires ,
1159+ crypt_shared : 'enabled'
1160+ }
1161+ } ,
1162+ async function ( ) {
1163+ // Use client_encrypted to insert the document {"encrypted": "test"} into db.coll.
1164+ // Expect a server selection error propagated from the internal MongoClient failing to connect to mongocryptd on port 27021.
1165+ const insertError = await clientEncrypted
1166+ . db ( dataDbName )
1167+ . collection ( dataCollName )
1168+ . insertOne ( { encrypted : 'test' } )
1169+ . catch ( e => e ) ;
11741170
1175- expect ( insertError )
1176- . to . be . instanceOf ( MongoRuntimeError )
1177- . to . match (
1178- / U n a b l e t o c o n n e c t t o ` m o n g o c r y p t d ` , p l e a s e m a k e s u r e i t i s r u n n i n g o r i n y o u r P A T H f o r a u t o - s p a w n /
1179- ) ;
1171+ expect ( insertError )
1172+ . to . be . instanceOf ( MongoRuntimeError )
1173+ . to . match (
1174+ / U n a b l e t o c o n n e c t t o ` m o n g o c r y p t d ` , p l e a s e m a k e s u r e i t i s r u n n i n g o r i n y o u r P A T H f o r a u t o - s p a w n /
1175+ ) ;
11801176
1181- const { cause } = insertError ;
1177+ const { cause } = insertError ;
11821178
1183- expect ( cause ) . to . be . instanceOf ( MongoServerSelectionError ) ;
1184- expect ( cause , 'Error must contain ECONNREFUSED' ) . to . satisfy (
1185- error =>
1186- / E C O N N R E F U S E D / . test ( error . message ) ||
1187- ! ! error . cause ?. cause ?. errors ?. every ( e => e . code === 'ECONNREFUSED' )
1188- ) ;
1189- } ) ;
1179+ expect ( cause ) . to . be . instanceOf ( MongoServerSelectionError ) ;
1180+ expect ( cause , 'Error must contain ECONNREFUSED' ) . to . satisfy (
1181+ error =>
1182+ / E C O N N R E F U S E D / . test ( error . message ) ||
1183+ ! ! error . cause ?. cause ?. errors ?. every ( e => e . code === 'ECONNREFUSED' )
1184+ ) ;
1185+ }
1186+ ) ;
11901187 } ) ;
11911188
11921189 describe ( 'via bypassAutoEncryption' , function ( ) {
@@ -1241,19 +1238,6 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
12411238 expect ( insertResult ) . to . have . property ( 'insertedId' ) ;
12421239 } ) ;
12431240
1244- beforeEach ( 'precondition: the shared library must NOT be loaded' , function ( ) {
1245- const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
1246- if ( cryptSharedLibPath ) {
1247- this . currentTest . skipReason =
1248- 'test requires that the shared library NOT is present, but CRYPT_SHARED_LIB_PATH is set.' ;
1249- this . skip ( ) ;
1250- }
1251- // the presence of the shared library can only be reliably determine after
1252- // libmongocrypt has been initialized, and can be detected with the
1253- // cryptSharedLibVersionInfo getter on the autoEncrypter.
1254- expect ( ! ! clientEncrypted . autoEncrypter . cryptSharedLibVersionInfo ) . to . be . false ;
1255- } ) ;
1256-
12571241 afterEach ( async function ( ) {
12581242 await clientEncrypted ?. close ( ) ;
12591243 await client ?. close ( ) ;
@@ -1262,34 +1246,34 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
12621246 // Validate that mongocryptd was not spawned. Create a MongoClient to localhost:27021
12631247 // (or whatever was passed via --port) with serverSelectionTimeoutMS=1000. Run a handshake
12641248 // command and ensure it fails with a server selection timeout.
1265- it ( 'does not spawn mongocryptd' , metadata , async function ( ) {
1266- client = new MongoClient ( 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000' ) ;
1267- const error = await client . connect ( ) . catch ( e => e ) ;
1249+ it (
1250+ 'does not spawn mongocryptd' ,
1251+ {
1252+ requires : {
1253+ ...metadata . requires ,
1254+ crypt_shared : 'enabled'
1255+ }
1256+ } ,
1257+ async function ( ) {
1258+ client = new MongoClient ( 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000' ) ;
1259+ const error = await client . connect ( ) . catch ( e => e ) ;
12681260
1269- expect ( error , 'Error MUST be a MongoServerSelectionError error' ) . to . be . instanceOf (
1270- MongoServerSelectionError
1271- ) ;
1272- expect ( error , 'Error MUST contain ECONNREFUSED information' ) . to . satisfy (
1273- error =>
1274- / E C O N N R E F U S E D / . test ( error . message ) ||
1275- ! ! error . cause ?. cause ?. errors ?. every ( e => e . code === 'ECONNREFUSED' )
1276- ) ;
1277- } ) ;
1261+ expect ( error , 'Error MUST be a MongoServerSelectionError error' ) . to . be . instanceOf (
1262+ MongoServerSelectionError
1263+ ) ;
1264+ expect ( error , 'Error MUST contain ECONNREFUSED information' ) . to . satisfy (
1265+ error =>
1266+ / E C O N N R E F U S E D / . test ( error . message ) ||
1267+ ! ! error . cause ?. cause ?. errors ?. every ( e => e . code === 'ECONNREFUSED' )
1268+ ) ;
1269+ }
1270+ ) ;
12781271 } ) ;
12791272
12801273 describe ( 'via loading shared library' , function ( ) {
12811274 let clientEncrypted ;
12821275 let client ;
12831276
1284- beforeEach ( function ( ) {
1285- const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
1286- if ( ! cryptSharedLibPath ) {
1287- this . currentTest . skipReason =
1288- 'test requires that the shared library is present, but CRYPT_SHARED_LIB_PATH is unset.' ;
1289- this . skip ( ) ;
1290- }
1291- } ) ;
1292-
12931277 // Setup
12941278 beforeEach ( async function ( ) {
12951279 const { cryptSharedLibPath } = getEncryptExtraOptions ( ) ;
@@ -1345,11 +1329,23 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
13451329 // 4. Validate that mongocryptd was not spawned. Create a MongoClient to localhost:27021 (or
13461330 // whatever was passed via `--port` with serverSelectionTimeoutMS=1000.) Run a handshake
13471331 // command and ensure it fails with a server selection timeout
1348- it ( 'should not spawn mongocryptd' , metadata , async function ( ) {
1349- client = new MongoClient ( 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000' ) ;
1350- const error = await client . connect ( ) . catch ( e => e ) ;
1351- expect ( error ) . to . be . instanceOf ( MongoServerSelectionError , / ' S e r v e r s e l e c t i o n t i m e d o u t ' / i) ;
1352- } ) ;
1332+ it (
1333+ 'should not spawn mongocryptd' ,
1334+ {
1335+ requires : {
1336+ ...metadata . requires ,
1337+ crypt_shared : 'enabled'
1338+ }
1339+ } ,
1340+ async function ( ) {
1341+ client = new MongoClient ( 'mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000' ) ;
1342+ const error = await client . connect ( ) . catch ( e => e ) ;
1343+ expect ( error ) . to . be . instanceOf (
1344+ MongoServerSelectionError ,
1345+ / ' S e r v e r s e l e c t i o n t i m e d o u t ' / i
1346+ ) ;
1347+ }
1348+ ) ;
13531349 } ) ;
13541350 } ) ;
13551351
0 commit comments