Skip to content

Commit a20d7b2

Browse files
committed
test: add invalid tls options test
1 parent 9d3a804 commit a20d7b2

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

test/integration/client-side-encryption/driver.test.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,51 @@ 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('fails to connect with TLS', metadata, async function () {
1409+
// Use client encryption to create a data key. If this succeeds, then TLS worked.
1410+
const error = await clientEncryption
1411+
.createDataKey('aws', {
1412+
masterKey,
1413+
keyAltNames: ['aws_altname']
1414+
})
1415+
.catch(error => error);
1416+
expect(error.message).to.include('KMS request failed');
1417+
});
1418+
}
1419+
);
13771420
});
13781421
});
13791422
});

0 commit comments

Comments
 (0)