Skip to content

Commit 31e1327

Browse files
committed
chore: comments
1 parent a595dbd commit 31e1327

File tree

5 files changed

+14
-78
lines changed

5 files changed

+14
-78
lines changed

src/client-side-encryption/auto_encrypter.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,9 @@ export class AutoEncrypter {
247247
this._kmsProviders = options.kmsProviders || {};
248248
this._credentialProviders = options.credentialProviders;
249249

250-
if (
251-
options.credentialProviders?.aws &&
252-
!isEmptyCredentials('aws', options.kmsProviders || {})
253-
) {
250+
if (options.credentialProviders?.aws && !isEmptyCredentials('aws', this._kmsProviders)) {
254251
throw new MongoCryptInvalidArgumentError(
255-
'Cannot provide both a custom credential provider and credentials. Please specify one or the other.'
252+
'Can only provide a custom AWS credential provider when the state machine is configured for automatic AWS credential fetching'
256253
);
257254
}
258255

src/client-side-encryption/client_encryption.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,9 @@ export class ClientEncryption {
132132
this._timeoutMS = timeoutMS;
133133
this._credentialProviders = options.credentialProviders;
134134

135-
if (
136-
options.credentialProviders?.aws &&
137-
!isEmptyCredentials('aws', options.kmsProviders || {})
138-
) {
135+
if (options.credentialProviders?.aws && !isEmptyCredentials('aws', this._kmsProviders)) {
139136
throw new MongoCryptInvalidArgumentError(
140-
'Cannot provide both a custom credential provider and credentials. Please specify one or the other.'
137+
'Can only provide a custom AWS credential provider when the state machine is configured for automatic AWS credential fetching'
141138
);
142139
}
143140

test/integration/auth/mongodb_aws.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ describe('AWS KMS Credential Fetching', function () {
468468
this.currentTest?.skipReason && this.skip();
469469
});
470470

471-
context('when a credential provider is not providered', function () {
471+
context('when a credential provider is not provided', function () {
472472
it('KMS credentials are successfully fetched.', async function () {
473473
const { aws } = await refreshKMSCredentials({ aws: {} });
474474

@@ -479,20 +479,23 @@ describe('AWS KMS Credential Fetching', function () {
479479

480480
context('when a credential provider is provided', function () {
481481
let credentialProvider;
482+
let providerCount = 0;
482483

483484
beforeEach(function () {
484485
// @ts-expect-error We intentionally access a protected variable.
485-
credentialProvider = AWSTemporaryCredentialProvider.awsSDK;
486+
const provider = AWSTemporaryCredentialProvider.awsSDK;
487+
credentialProvider = async () => {
488+
providerCount++;
489+
return await provider.fromNodeProviderChain().apply();
490+
};
486491
});
487492

488493
it('KMS credentials are successfully fetched.', async function () {
489-
const { aws } = await refreshKMSCredentials(
490-
{ aws: {} },
491-
{ aws: credentialProvider.fromNodeProviderChain() }
492-
);
494+
const { aws } = await refreshKMSCredentials({ aws: {} }, { aws: credentialProvider });
493495

494496
expect(aws).to.have.property('accessKeyId');
495497
expect(aws).to.have.property('secretAccessKey');
498+
expect(providerCount).to.be.greaterThan(0);
496499
});
497500
});
498501

test/integration/client-side-encryption/client_side_encryption.prose.26.custom_aws_credential_providers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const masterKey = {
1818
key: 'arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0'
1919
};
2020

21-
describe('25. Custom AWS Credential Providers', metadata, () => {
21+
describe('26. Custom AWS Credential Providers', metadata, () => {
2222
let keyVaultClient;
2323
let credentialProvider;
2424

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -50,67 +50,6 @@ 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-
11453
describe('Collection', metadata, function () {
11554
describe('#bulkWrite()', metadata, function () {
11655
context('when encryption errors', function () {

0 commit comments

Comments
 (0)