Skip to content

Commit 6ebe69b

Browse files
add test for AWS sdk returning unknown fields
1 parent 7c1961f commit 6ebe69b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/unit/client-side-encryption/providers/credentialsProvider.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
} from '../../../../src/client-side-encryption/providers/azure';
2121
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
2222
import * as utils from '../../../../src/client-side-encryption/providers/utils';
23+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
24+
import { AWSSDKCredentialProvider } from '../../../../src/cmap/auth/aws_temporary_credentials';
2325
import * as requirements from '../requirements.helper';
2426

2527
const originalAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
@@ -175,6 +177,29 @@ describe('#refreshKMSCredentials', function () {
175177
expect(providers).to.deep.equal(kmsProviders);
176178
});
177179
});
180+
181+
context('when the AWS SDK returns unknown fields', function () {
182+
beforeEach(() => {
183+
sinon.stub(AWSSDKCredentialProvider.prototype, 'getCredentials').resolves({
184+
Token: 'example',
185+
SecretAccessKey: 'example',
186+
AccessKeyId: 'example',
187+
// @ts-expect-error This is not an expected key.
188+
UnknownField: 'example'
189+
});
190+
});
191+
afterEach(() => sinon.restore());
192+
it('only returns fields libmongocrypt expects', async function () {
193+
const credentials = await new KMSCredentialProvider({ aws: {} }).refreshCredentials();
194+
expect(credentials).to.deep.equal({
195+
aws: {
196+
accessKeyId: accessKey,
197+
secretAccessKey: secretKey,
198+
sessionToken: sessionToken
199+
}
200+
});
201+
});
202+
});
178203
});
179204

180205
context('when using gcp', () => {

0 commit comments

Comments
 (0)