Skip to content

Commit 32490b5

Browse files
committed
test: add config tests
1 parent aa8972e commit 32490b5

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/client-side-encryption/client_encryption.ts

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import {
3636
type ClientEncryptionDataKeyProvider,
3737
type CredentialProviders,
38+
isEmptyCredentials,
3839
type KMSProviders,
3940
refreshKMSCredentials
4041
} from './providers/index';
@@ -131,6 +132,15 @@ export class ClientEncryption {
131132
this._timeoutMS = timeoutMS;
132133
this._credentialProviders = options.credentialProviders;
133134

135+
if (
136+
options.credentialProviders?.aws &&
137+
!isEmptyCredentials('aws', options.kmsProviders || {})
138+
) {
139+
throw new MongoCryptInvalidArgumentError(
140+
'Cannot provide both a custom credential provider and credentials. Please specify one or the other.'
141+
);
142+
}
143+
134144
if (options.keyVaultNamespace == null) {
135145
throw new MongoCryptInvalidArgumentError('Missing required option `keyVaultNamespace`');
136146
}

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

+61
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,67 @@ describe('Client Side Encryption Functional', function () {
5050
const keyVaultCollName = 'datakeys';
5151
const keyVaultNamespace = `${keyVaultDbName}.${keyVaultCollName}`;
5252

53+
describe('ClientEncryption', metadata, function () {
54+
describe('#constructor', function () {
55+
context('when a custom credential provider and credentials are provided', function () {
56+
let client;
57+
58+
before(function () {
59+
client = this.configuration.newClient({});
60+
});
61+
62+
it('throws an error', function () {
63+
expect(() => {
64+
new ClientEncryption(client, {
65+
keyVaultNamespace: 'test.keyvault',
66+
kmsProviders: {
67+
aws: { secretAccessKey: 'test', accessKeyId: 'test' }
68+
},
69+
credentialProviders: {
70+
aws: async () => {
71+
return {
72+
sessionToken: 'test',
73+
secretAccessKey: 'test',
74+
accessKeyId: 'test'
75+
};
76+
}
77+
}
78+
});
79+
}).to.throw(/custom credential provider and credentials/);
80+
});
81+
});
82+
});
83+
});
84+
85+
describe('AutoEncrypter', metadata, function () {
86+
context('when a custom credential provider and credentials are provided', function () {
87+
it('throws an error', function () {
88+
expect(() => {
89+
this.configuration.newClient(
90+
{},
91+
{
92+
autoEncryption: {
93+
keyVaultNamespace: 'test.keyvault',
94+
kmsProviders: {
95+
aws: { secretAccessKey: 'test', accessKeyId: 'test' }
96+
},
97+
credentialProviders: {
98+
aws: async () => {
99+
return {
100+
sessionToken: 'test',
101+
secretAccessKey: 'test',
102+
accessKeyId: 'test'
103+
};
104+
}
105+
}
106+
}
107+
}
108+
);
109+
}).to.throw(/custom credential provider and credentials/);
110+
});
111+
});
112+
});
113+
53114
describe('Collection', metadata, function () {
54115
describe('#bulkWrite()', metadata, function () {
55116
context('when encryption errors', function () {

0 commit comments

Comments
 (0)