Skip to content

Commit f5d0872

Browse files
committed
test: add tests
1 parent 632774d commit f5d0872

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

test/integration/auth/mongodb_aws.test.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ describe('MONGODB-AWS', function () {
6161
expect(result).to.be.a('number');
6262
});
6363

64+
it('authenticates with a user provided credentials provider', async function () {
65+
// @ts-expect-error We intentionally access a protected variable.
66+
const credentialProvider = AWSTeVmporaryCredentialProvider.awsSDK;
67+
client = this.configuration.newClient(process.env.MONGODB_URI, {
68+
authMechanismProperties: {
69+
AWS_CREDENTIAL_PROVIDER: credentialProvider.fromNodeProviderChain()
70+
}
71+
});
72+
73+
const result = await client
74+
.db('aws')
75+
.collection('aws_test')
76+
.estimatedDocumentCount()
77+
.catch(error => error);
78+
79+
expect(result).to.not.be.instanceOf(MongoServerError);
80+
expect(result).to.be.a('number');
81+
});
82+
6483
it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
6584
client = this.configuration.newClient(this.configuration.url(), {
6685
authMechanismProperties: { AWS_SESSION_TOKEN: '' }
@@ -351,11 +370,33 @@ describe('AWS KMS Credential Fetching', function () {
351370
: undefined;
352371
this.currentTest?.skipReason && this.skip();
353372
});
354-
it('KMS credentials are successfully fetched.', async function () {
355-
const { aws } = await refreshKMSCredentials({ aws: {} });
356373

357-
expect(aws).to.have.property('accessKeyId');
358-
expect(aws).to.have.property('secretAccessKey');
374+
context('when a credential provider is not providered', function () {
375+
it('KMS credentials are successfully fetched.', async function () {
376+
const { aws } = await refreshKMSCredentials({ aws: {} });
377+
378+
expect(aws).to.have.property('accessKeyId');
379+
expect(aws).to.have.property('secretAccessKey');
380+
});
381+
});
382+
383+
context('when a credential provider is provided', function () {
384+
let credentialProvider;
385+
386+
beforeEach(function () {
387+
// @ts-expect-error We intentionally access a protected variable.
388+
credentialProvider = AWSTeVmporaryCredentialProvider.awsSDK;
389+
});
390+
391+
it('KMS credentials are successfully fetched.', async function () {
392+
const { aws } = await refreshKMSCredentials(
393+
{ aws: {} },
394+
credentialProvider.fromNodeProviderChain()
395+
);
396+
397+
expect(aws).to.have.property('accessKeyId');
398+
expect(aws).to.have.property('secretAccessKey');
399+
});
359400
});
360401

361402
it('does not return any extra keys for the `aws` credential provider', async function () {

0 commit comments

Comments
 (0)