|
| 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 | +}); |
0 commit comments