@@ -1326,11 +1326,9 @@ describe('CSOT', function () {
13261326 } ) ;
13271327 } ) ;
13281328
1329- context ( 'when driver specific TLS options are provided with a secure context' , function ( ) {
1329+ context ( 'when driver TLS options are provided with a valid secure context' , function ( ) {
13301330 let client ;
13311331 let clientEncryption ;
1332- // Note we set tlsCAFile and tlsCertificateKeyFile to 'nofilename' to also
1333- // test that the driver does not attempt to read these files in this case.
13341332 const options = {
13351333 keyVaultNamespace,
13361334 kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
@@ -1374,6 +1372,59 @@ describe('CSOT', function () {
13741372 . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
13751373 } ) ;
13761374 } ) ;
1375+
1376+ context (
1377+ 'when invalid driver TLS options are provided with a valid secure context' ,
1378+ function ( ) {
1379+ let client ;
1380+ let clientEncryption ;
1381+ const options = {
1382+ keyVaultNamespace,
1383+ kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
1384+ tlsOptions : {
1385+ aws : {
1386+ secureContext : tls . createSecureContext ( secureContextOptions ) ,
1387+ tlsCAFile : 'invalid' ,
1388+ tlsCertificateKeyFile : 'invalid'
1389+ }
1390+ } ,
1391+ extraOptions : getEncryptExtraOptions ( )
1392+ } ;
1393+
1394+ beforeEach ( async function ( ) {
1395+ client = this . configuration . newClient (
1396+ { } ,
1397+ { autoEncryption : { ...options , schemaMap } }
1398+ ) ;
1399+ clientEncryption = new ClientEncryption ( client , options ) ;
1400+ await client . connect ( ) ;
1401+ } ) ;
1402+
1403+ afterEach ( async function ( ) {
1404+ await client . db ( keyVaultDbName ) . collection ( keyVaultCollName ) . deleteMany ( ) ;
1405+ await client . close ( ) ;
1406+ } ) ;
1407+
1408+ it ( 'successfully connects with TLS' , metadata , async function ( ) {
1409+ // Use client encryption to create a data key. If this succeeds, then TLS worked.
1410+ const awsDatakeyId = await clientEncryption . createDataKey ( 'aws' , {
1411+ masterKey,
1412+ keyAltNames : [ 'aws_altname' ]
1413+ } ) ;
1414+ expect ( awsDatakeyId ) . to . have . property ( 'sub_type' , 4 ) ;
1415+ // Use the client to get the data key. If this succeeds, then the TLS connection
1416+ // for auto encryption worked.
1417+ const results = await client
1418+ . db ( keyVaultDbName )
1419+ . collection ( keyVaultCollName )
1420+ . find ( { _id : awsDatakeyId } )
1421+ . toArray ( ) ;
1422+ expect ( results )
1423+ . to . have . a . lengthOf ( 1 )
1424+ . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
1425+ } ) ;
1426+ }
1427+ ) ;
13771428 } ) ;
13781429 } ) ;
13791430} ) ;
0 commit comments