Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 29, 2025
1 parent 632774d commit f5d0872
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions test/integration/auth/mongodb_aws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ describe('MONGODB-AWS', function () {
expect(result).to.be.a('number');
});

it('authenticates with a user provided credentials provider', async function () {
// @ts-expect-error We intentionally access a protected variable.
const credentialProvider = AWSTeVmporaryCredentialProvider.awsSDK;
client = this.configuration.newClient(process.env.MONGODB_URI, {
authMechanismProperties: {
AWS_CREDENTIAL_PROVIDER: credentialProvider.fromNodeProviderChain()
}
});

const result = await client
.db('aws')
.collection('aws_test')
.estimatedDocumentCount()
.catch(error => error);

expect(result).to.not.be.instanceOf(MongoServerError);
expect(result).to.be.a('number');
});

it('should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable', function () {
client = this.configuration.newClient(this.configuration.url(), {
authMechanismProperties: { AWS_SESSION_TOKEN: '' }
Expand Down Expand Up @@ -351,11 +370,33 @@ describe('AWS KMS Credential Fetching', function () {
: undefined;
this.currentTest?.skipReason && this.skip();
});
it('KMS credentials are successfully fetched.', async function () {
const { aws } = await refreshKMSCredentials({ aws: {} });

expect(aws).to.have.property('accessKeyId');
expect(aws).to.have.property('secretAccessKey');
context('when a credential provider is not providered', function () {
it('KMS credentials are successfully fetched.', async function () {
const { aws } = await refreshKMSCredentials({ aws: {} });

expect(aws).to.have.property('accessKeyId');
expect(aws).to.have.property('secretAccessKey');
});
});

context('when a credential provider is provided', function () {
let credentialProvider;

beforeEach(function () {
// @ts-expect-error We intentionally access a protected variable.
credentialProvider = AWSTeVmporaryCredentialProvider.awsSDK;
});

it('KMS credentials are successfully fetched.', async function () {
const { aws } = await refreshKMSCredentials(
{ aws: {} },
credentialProvider.fromNodeProviderChain()
);

expect(aws).to.have.property('accessKeyId');
expect(aws).to.have.property('secretAccessKey');
});
});

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

0 comments on commit f5d0872

Please sign in to comment.