Skip to content

Commit 8e43f11

Browse files
committed
test(NODE-3151): add KMS TLS tests for client-side encryption
1 parent d8caa42 commit 8e43f11

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
mongodb: '>=4.2.0'
9+
}
10+
};
11+
12+
describe('10. KMS TLS Tests', function () {
13+
const keyVaultNamespace = 'keyvault.datakeys';
14+
const masterKeyBase = {
15+
region: 'us-east-1',
16+
key: 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0'
17+
};
18+
19+
let client: MongoClient;
20+
let clientEncryption: ClientEncryption;
21+
22+
beforeEach(async function () {
23+
client = this.configuration.newClient();
24+
await client.connect();
25+
26+
clientEncryption = new ClientEncryption(client, {
27+
keyVaultNamespace,
28+
kmsProviders: getCSFLEKMSProviders(),
29+
tlsOptions: {
30+
aws: {
31+
tlsCAFile: process.env.CSFLE_TLS_CA_FILE,
32+
tlsCertificateKeyFile: process.env.CSFLE_TLS_CLIENT_CERT_FILE
33+
}
34+
}
35+
});
36+
});
37+
38+
afterEach(async function () {
39+
await client.close();
40+
});
41+
42+
it('should fail with an expired certificate', metadata, async function () {
43+
const masterKey = { ...masterKeyBase, endpoint: '127.0.0.1:9000' };
44+
45+
const error = await clientEncryption.createDataKey('aws', { masterKey }).then(
46+
() => null,
47+
error => error
48+
);
49+
50+
expect(error.cause.message, error.stack).to.include('certificate has expired');
51+
});
52+
53+
it('should fail with an invalid hostname', metadata, async function () {
54+
const masterKey = { ...masterKeyBase, endpoint: '127.0.0.1:9001' };
55+
56+
const error = await clientEncryption.createDataKey('aws', { masterKey }).then(
57+
() => null,
58+
error => error
59+
);
60+
61+
expect(error.cause.message, error.stack).to.include('does not match certificate');
62+
});
63+
});

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

Lines changed: 0 additions & 5 deletions
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)