Skip to content

Commit 9d3a804

Browse files
committed
chore: remove secure context preference
1 parent 4291595 commit 9d3a804

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

src/client-side-encryption/state_machine.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ declare module 'mongodb-client-encryption' {
103103
* - tlsInsecure
104104
*
105105
* These options are not included in the type, and are ignored if provided.
106-
*
107-
* Note that if a secureContext option is provided, all other TLS options will be ignored.
108106
*/
109107
export type ClientEncryptionTlsOptions = Pick<
110108
MongoClientOptions,
@@ -523,20 +521,19 @@ export class StateMachine {
523521
tlsOptions: ClientEncryptionTlsOptions,
524522
options: tls.ConnectionOptions
525523
): Promise<void> {
526-
// If a secureContext is provided, it takes precedence over the other options.
524+
// If a secureContext is provided, ensure it is set.
527525
if (tlsOptions.secureContext) {
528526
options.secureContext = tlsOptions.secureContext;
529-
} else {
530-
if (tlsOptions.tlsCertificateKeyFile) {
531-
const cert = await fs.readFile(tlsOptions.tlsCertificateKeyFile);
532-
options.cert = options.key = cert;
533-
}
534-
if (tlsOptions.tlsCAFile) {
535-
options.ca = await fs.readFile(tlsOptions.tlsCAFile);
536-
}
537-
if (tlsOptions.tlsCertificateKeyFilePassword) {
538-
options.passphrase = tlsOptions.tlsCertificateKeyFilePassword;
539-
}
527+
}
528+
if (tlsOptions.tlsCertificateKeyFile) {
529+
const cert = await fs.readFile(tlsOptions.tlsCertificateKeyFile);
530+
options.cert = options.key = cert;
531+
}
532+
if (tlsOptions.tlsCAFile) {
533+
options.ca = await fs.readFile(tlsOptions.tlsCAFile);
534+
}
535+
if (tlsOptions.tlsCertificateKeyFilePassword) {
536+
options.passphrase = tlsOptions.tlsCertificateKeyFilePassword;
540537
}
541538
}
542539

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ describe('CSOT', function () {
13261326
});
13271327
});
13281328

1329-
context('when driver specific TLS options are provided', function () {
1329+
context('when driver specific TLS options are provided with a secure context', function () {
13301330
let client;
13311331
let clientEncryption;
13321332
// Note we set tlsCAFile and tlsCertificateKeyFile to 'nofilename' to also
@@ -1337,9 +1337,8 @@ describe('CSOT', function () {
13371337
tlsOptions: {
13381338
aws: {
13391339
secureContext: tls.createSecureContext(secureContextOptions),
1340-
tlsCAFile: 'nofilename',
1341-
tlsCertificateKeyFile: 'nofilename',
1342-
tlsCertificateKeyFilePassword: 'invalid'
1340+
tlsCAFile: process.env.CSFLE_TLS_CA_FILE,
1341+
tlsCertificateKeyFile: process.env.CSFLE_TLS_CLIENT_CERT_FILE
13431342
}
13441343
},
13451344
extraOptions: getEncryptExtraOptions()
@@ -1356,28 +1355,24 @@ describe('CSOT', function () {
13561355
await client.close();
13571356
});
13581357

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-
);
1358+
it('successfully connects with TLS', metadata, async function () {
1359+
// Use client encryption to create a data key. If this succeeds, then TLS worked.
1360+
const awsDatakeyId = await clientEncryption.createDataKey('aws', {
1361+
masterKey,
1362+
keyAltNames: ['aws_altname']
1363+
});
1364+
expect(awsDatakeyId).to.have.property('sub_type', 4);
1365+
// Use the client to get the data key. If this succeeds, then the TLS connection
1366+
// for auto encryption worked.
1367+
const results = await client
1368+
.db(keyVaultDbName)
1369+
.collection(keyVaultCollName)
1370+
.find({ _id: awsDatakeyId })
1371+
.toArray();
1372+
expect(results)
1373+
.to.have.a.lengthOf(1)
1374+
.and.to.have.nested.property('0.masterKey.provider', 'aws');
1375+
});
13811376
});
13821377
});
13831378
});

0 commit comments

Comments
 (0)