@@ -242,7 +242,6 @@ describe('Client Side Encryption Functional', function () {
242242 Object . freeze ( [ '1' , 1 ] as const ) ,
243243 Object . freeze ( [ '0' , 1 ] as const )
244244 ] ) ;
245- // @ts -expect-error: Our findOne API does not accept readonly input
246245 await collection . findOne ( { } , { sort } ) ;
247246 const findEvent = events . find ( event => ! ! event . command . find ) ;
248247 expect ( findEvent ) . to . have . property ( 'commandName' , 'find' ) ;
@@ -258,7 +257,6 @@ describe('Client Side Encryption Functional', function () {
258257 Object . freeze ( [ '1' , 1 ] as const ) ,
259258 Object . freeze ( [ '0' , 1 ] as const )
260259 ] ) ;
261- // @ts -expect-error: Our findOneAndUpdate API does not accept readonly input
262260 await collection . findOneAndUpdate ( { } , { $setOnInsert : { a : 1 } } , { sort } ) ;
263261 const findAndModifyEvent = events . find ( event => ! ! event . command . findAndModify ) ;
264262 expect ( findAndModifyEvent ) . to . have . property ( 'commandName' , 'findAndModify' ) ;
@@ -1245,134 +1243,141 @@ describe('CSOT', function () {
12451243 } ) ;
12461244 } ) ;
12471245
1248- context ( 'when providing node specific TLS options' , function ( ) {
1249- const dataDbName = 'db' ;
1250- const dataCollName = 'coll' ;
1251- const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
1252- const keyVaultDbName = 'keyvault' ;
1253- const keyVaultCollName = 'datakeys' ;
1254- const keyVaultNamespace = `${ keyVaultDbName } .${ keyVaultCollName } ` ;
1255- const masterKey = {
1256- region : 'us-east-1' ,
1257- key : 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0'
1258- } ;
1259- const schemaMap = {
1260- [ dataNamespace ] : {
1261- bsonType : 'object' ,
1262- properties : {
1263- encrypted_placeholder : {
1264- encrypt : {
1265- keyId : '/placeholder' ,
1266- bsonType : 'string' ,
1267- algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
1246+ describe ( 'TLS Authentication with Client Encryption and Auto Encryption' , function ( ) {
1247+ context ( 'when providing node specific secureContext TLS option' , function ( ) {
1248+ const dataDbName = 'db' ;
1249+ const dataCollName = 'coll' ;
1250+ const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
1251+ const keyVaultDbName = 'keyvault' ;
1252+ const keyVaultCollName = 'datakeys' ;
1253+ const keyVaultNamespace = `${ keyVaultDbName } .${ keyVaultCollName } ` ;
1254+ const masterKey = {
1255+ region : 'us-east-1' ,
1256+ key : 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0'
1257+ } ;
1258+ const schemaMap = {
1259+ [ dataNamespace ] : {
1260+ bsonType : 'object' ,
1261+ properties : {
1262+ encrypted_placeholder : {
1263+ encrypt : {
1264+ keyId : '/placeholder' ,
1265+ bsonType : 'string' ,
1266+ algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'
1267+ }
12681268 }
12691269 }
12701270 }
1271- }
1272- } ;
1273- let secureContextOptions ;
1274-
1275- beforeEach ( async function ( ) {
1276- const caFile = await fs . readFile ( process . env . CSFLE_TLS_CA_FILE ) ;
1277- const certFile = await fs . readFile ( process . env . CSFLE_TLS_CLIENT_CERT_FILE ) ;
1278- secureContextOptions = {
1279- ca : caFile ,
1280- key : certFile ,
1281- cert : certFile
1282- } ;
1283- } ) ;
1284-
1285- context ( 'when no driver specific TLS options are provided' , function ( ) {
1286- let client ;
1287- let clientEncryption ;
1288- const options = {
1289- keyVaultNamespace,
1290- kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
1291- tlsOptions : {
1292- aws : {
1293- secureContext : tls . createSecureContext ( secureContextOptions )
1294- }
1295- } ,
1296- extraOptions : getEncryptExtraOptions ( )
12971271 } ;
1272+ let secureContextOptions ;
12981273
12991274 beforeEach ( async function ( ) {
1300- client = this . configuration . newClient ( { } , { autoEncryption : { ...options , schemaMap } } ) ;
1301- clientEncryption = new ClientEncryption ( client , options ) ;
1302- await client . connect ( ) ;
1275+ const caFile = await fs . readFile ( process . env . CSFLE_TLS_CA_FILE ) ;
1276+ const certFile = await fs . readFile ( process . env . CSFLE_TLS_CLIENT_CERT_FILE ) ;
1277+ secureContextOptions = {
1278+ ca : caFile ,
1279+ key : certFile ,
1280+ cert : certFile
1281+ } ;
13031282 } ) ;
13041283
1305- afterEach ( async function ( ) {
1306- await client . db ( keyVaultDbName ) . collection ( keyVaultCollName ) . deleteMany ( ) ;
1307- await client . close ( ) ;
1308- } ) ;
1284+ context ( 'when no driver specific TLS options are provided' , function ( ) {
1285+ let client ;
1286+ let clientEncryption ;
1287+ const options = {
1288+ keyVaultNamespace,
1289+ kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
1290+ tlsOptions : {
1291+ aws : {
1292+ secureContext : tls . createSecureContext ( secureContextOptions )
1293+ }
1294+ } ,
1295+ extraOptions : getEncryptExtraOptions ( )
1296+ } ;
13091297
1310- it ( 'succeeds to connect' , metadata , async function ( ) {
1311- // Use client encryption to create a data key. If this succeeds, then TLS worked.
1312- const awsDatakeyId = await clientEncryption . createDataKey ( 'aws' , {
1313- masterKey,
1314- keyAltNames : [ 'aws_altname' ]
1298+ beforeEach ( async function ( ) {
1299+ client = this . configuration . newClient ( { } , { autoEncryption : { ...options , schemaMap } } ) ;
1300+ clientEncryption = new ClientEncryption ( client , options ) ;
1301+ await client . connect ( ) ;
13151302 } ) ;
1316- expect ( awsDatakeyId ) . to . have . property ( 'sub_type' , 4 ) ;
1317- // Use the client to get the data key. If this succeeds, then the TLS connection
1318- // for auto encryption worked.
1319- const results = await client
1320- . db ( keyVaultDbName )
1321- . collection ( keyVaultCollName )
1322- . find ( { _id : awsDatakeyId } )
1323- . toArray ( ) ;
1324- expect ( results )
1325- . to . have . a . lengthOf ( 1 )
1326- . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
1327- } ) ;
1328- } ) ;
13291303
1330- context ( 'when driver specific TLS options are provided' , function ( ) {
1331- let client ;
1332- let clientEncryption ;
1333- // Note we set tlsCAFile and tlsCertificateKeyFile to 'nofilename' to also
1334- // test that the driver does not attempt to read these files in this case.
1335- const options = {
1336- keyVaultNamespace,
1337- kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
1338- tlsOptions : {
1339- aws : {
1340- secureContext : tls . createSecureContext ( secureContextOptions ) ,
1341- tlsCAFile : 'nofilename' ,
1342- tlsCertificateKeyFile : 'nofilename'
1343- }
1344- } ,
1345- extraOptions : getEncryptExtraOptions ( )
1346- } ;
1304+ afterEach ( async function ( ) {
1305+ await client . db ( keyVaultDbName ) . collection ( keyVaultCollName ) . deleteMany ( ) ;
1306+ await client . close ( ) ;
1307+ } ) ;
13471308
1348- beforeEach ( async function ( ) {
1349- client = this . configuration . newClient ( { } , { autoEncryption : { ...options , schemaMap } } ) ;
1350- clientEncryption = new ClientEncryption ( client , options ) ;
1351- await client . connect ( ) ;
1309+ it ( 'successfully connects with TLS' , metadata , async function ( ) {
1310+ // Use client encryption to create a data key. If this succeeds, then TLS worked.
1311+ const awsDatakeyId = await clientEncryption . createDataKey ( 'aws' , {
1312+ masterKey,
1313+ keyAltNames : [ 'aws_altname' ]
1314+ } ) ;
1315+ expect ( awsDatakeyId ) . to . have . property ( 'sub_type' , 4 ) ;
1316+ // Use the client to get the data key. If this succeeds, then the TLS connection
1317+ // for auto encryption worked.
1318+ const results = await client
1319+ . db ( keyVaultDbName )
1320+ . collection ( keyVaultCollName )
1321+ . find ( { _id : awsDatakeyId } )
1322+ . toArray ( ) ;
1323+ expect ( results )
1324+ . to . have . a . lengthOf ( 1 )
1325+ . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
1326+ } ) ;
13521327 } ) ;
13531328
1354- afterEach ( async function ( ) {
1355- await client . db ( keyVaultDbName ) . collection ( keyVaultCollName ) . deleteMany ( ) ;
1356- await client . close ( ) ;
1357- } ) ;
1329+ context ( 'when driver specific TLS options are provided' , function ( ) {
1330+ let client ;
1331+ 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.
1334+ const options = {
1335+ keyVaultNamespace,
1336+ kmsProviders : { aws : getCSFLEKMSProviders ( ) . aws } ,
1337+ tlsOptions : {
1338+ aws : {
1339+ secureContext : tls . createSecureContext ( secureContextOptions ) ,
1340+ tlsCAFile : 'nofilename' ,
1341+ tlsCertificateKeyFile : 'nofilename' ,
1342+ tlsCertificateKeyFilePassword : 'invalid'
1343+ }
1344+ } ,
1345+ extraOptions : getEncryptExtraOptions ( )
1346+ } ;
1347+
1348+ beforeEach ( async function ( ) {
1349+ client = this . configuration . newClient ( { } , { autoEncryption : { ...options , schemaMap } } ) ;
1350+ clientEncryption = new ClientEncryption ( client , options ) ;
1351+ await client . connect ( ) ;
1352+ } ) ;
13581353
1359- it ( 'succeeds to connect' , metadata , async function ( ) {
1360- // Use client encryption to create a data key. If this succeeds, then TLS worked.
1361- const awsDatakeyId = await clientEncryption . createDataKey ( 'aws' , {
1362- masterKey,
1363- keyAltNames : [ 'aws_altname' ]
1354+ afterEach ( async function ( ) {
1355+ await client . db ( keyVaultDbName ) . collection ( keyVaultCollName ) . deleteMany ( ) ;
1356+ await client . close ( ) ;
13641357 } ) ;
1365- expect ( awsDatakeyId ) . to . have . property ( 'sub_type' , 4 ) ;
1366- // Use the client to get the data key. If this succeeds, then the TLS connection
1367- // for auto encryption worked.
1368- const results = await client
1369- . db ( keyVaultDbName )
1370- . collection ( keyVaultCollName )
1371- . find ( { _id : awsDatakeyId } )
1372- . toArray ( ) ;
1373- expect ( results )
1374- . to . have . a . lengthOf ( 1 )
1375- . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
1358+
1359+ it (
1360+ 'successfully connects with TLS without attempting to parse the driver specific options' ,
1361+ metadata ,
1362+ async function ( ) {
1363+ // Use client encryption to create a data key. If this succeeds, then TLS worked.
1364+ const awsDatakeyId = await clientEncryption . createDataKey ( 'aws' , {
1365+ masterKey,
1366+ keyAltNames : [ 'aws_altname' ]
1367+ } ) ;
1368+ expect ( awsDatakeyId ) . to . have . property ( 'sub_type' , 4 ) ;
1369+ // Use the client to get the data key. If this succeeds, then the TLS connection
1370+ // for auto encryption worked.
1371+ const results = await client
1372+ . db ( keyVaultDbName )
1373+ . collection ( keyVaultCollName )
1374+ . find ( { _id : awsDatakeyId } )
1375+ . toArray ( ) ;
1376+ expect ( results )
1377+ . to . have . a . lengthOf ( 1 )
1378+ . and . to . have . nested . property ( '0.masterKey.provider' , 'aws' ) ;
1379+ }
1380+ ) ;
13761381 } ) ;
13771382 } ) ;
13781383 } ) ;
0 commit comments