Skip to content

Commit cfdb8ec

Browse files
authored
test(NODE-3151): add KMS TLS tests for client-side encryption (#4485)
1 parent 85440c4 commit cfdb8ec

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

test/csfle-kms-providers.js renamed to test/csfle-kms-providers.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
import { type KMSProviders } from './mongodb';
22

33
const csfleKMSProviders = {
44
aws: {
@@ -22,7 +22,7 @@ const csfleKMSProviders = {
2222
}
2323
};
2424

25-
function getCSFLEKMSProviders() {
25+
export function getCSFLEKMSProviders(): KMSProviders {
2626
return JSON.parse(JSON.stringify(csfleKMSProviders));
2727
}
2828

@@ -37,10 +37,7 @@ const keys = [
3737
];
3838

3939
const isInEnvironment = key => typeof process.env[key] === 'string' && process.env[key].length > 0;
40-
const missingKeys = keys.filter(key => !isInEnvironment(key)).join(',');
4140

42-
module.exports = {
43-
getCSFLEKMSProviders,
44-
kmsCredentialsPresent: missingKeys === '',
45-
missingKeys
46-
};
41+
export const missingKeys = keys.filter(key => !isInEnvironment(key)).join(',');
42+
43+
export const kmsCredentialsPresent = missingKeys === '';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect } from 'chai';
2+
3+
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
4+
import { ClientEncryption, type MongoClient } from '../../mongodb';
5+
6+
const metadata: MongoDBMetadataUI = {
7+
requires: {
8+
clientSideEncryption: true,
9+
mongodb: '>=4.2.0'
10+
}
11+
};
12+
13+
describe('10. KMS TLS Tests', function () {
14+
const keyVaultNamespace = 'keyvault.datakeys';
15+
const masterKeyBase = {
16+
region: 'us-east-1',
17+
key: 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0'
18+
};
19+
20+
let client: MongoClient;
21+
let clientEncryption: ClientEncryption;
22+
23+
beforeEach(async function () {
24+
client = this.configuration.newClient();
25+
await client.connect();
26+
27+
clientEncryption = new ClientEncryption(client, {
28+
keyVaultNamespace,
29+
kmsProviders: { aws: getCSFLEKMSProviders().aws },
30+
tlsOptions: {
31+
aws: {
32+
tlsCAFile: process.env.CSFLE_TLS_CA_FILE,
33+
tlsCertificateKeyFile: process.env.CSFLE_TLS_CLIENT_CERT_FILE
34+
}
35+
}
36+
});
37+
});
38+
39+
afterEach(async function () {
40+
await client.close();
41+
});
42+
43+
it('should fail with an expired certificate', metadata, async function () {
44+
const masterKey = { ...masterKeyBase, endpoint: '127.0.0.1:9000' };
45+
46+
const error = await clientEncryption.createDataKey('aws', { masterKey }).then(
47+
() => null,
48+
error => error
49+
);
50+
51+
expect(error).to.exist;
52+
expect(error, error.stack).to.have.property('cause').that.is.instanceOf(Error);
53+
expect(error.cause.message, error.stack).to.include('certificate has expired');
54+
});
55+
56+
it('should fail with an invalid hostname', metadata, async function () {
57+
const masterKey = { ...masterKeyBase, endpoint: '127.0.0.1:9001' };
58+
59+
const error = await clientEncryption.createDataKey('aws', { masterKey }).then(
60+
() => null,
61+
error => error
62+
);
63+
64+
expect(error).to.exist;
65+
expect(error, error.stack).to.have.property('cause').that.is.instanceOf(Error);
66+
expect(error.cause.message, error.stack).to.include('does not match certificate');
67+
});
68+
});

test/integration/client-side-encryption/client_side_encryption.prose.test.js

-5
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,6 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
13511351
});
13521352
});
13531353

1354-
// TODO(NODE-3151): Implement kms prose tests
1355-
describe('KMS TLS Tests', () => {
1356-
it.skip('TBD', () => {}).skipReason = 'TODO(NODE-3151): Implement "KMS TLS Tests"';
1357-
});
1358-
13591354
/**
13601355
* - Create client encryption no tls
13611356
* - Create client encryption with tls

0 commit comments

Comments
 (0)