@@ -136,6 +136,34 @@ describe('MONGODB-AWS', function () {
136
136
} ) ;
137
137
} ) ;
138
138
139
+ context ( 'when user supplies a credentials provider' , function ( ) {
140
+ beforeEach ( function ( ) {
141
+ if ( ! awsSdkPresent ) {
142
+ this . skipReason = 'only relevant to AssumeRoleWithWebIdentity with SDK installed' ;
143
+ return this . skip ( ) ;
144
+ }
145
+ } ) ;
146
+
147
+ it ( 'authenticates with a user provided credentials provider' , async function ( ) {
148
+ // @ts -expect-error We intentionally access a protected variable.
149
+ const credentialProvider = AWSTemporaryCredentialProvider . awsSDK ;
150
+ client = this . configuration . newClient ( process . env . MONGODB_URI , {
151
+ authMechanismProperties : {
152
+ AWS_CREDENTIAL_PROVIDER : credentialProvider . fromNodeProviderChain ( )
153
+ }
154
+ } ) ;
155
+
156
+ const result = await client
157
+ . db ( 'aws' )
158
+ . collection ( 'aws_test' )
159
+ . estimatedDocumentCount ( )
160
+ . catch ( error => error ) ;
161
+
162
+ expect ( result ) . to . not . be . instanceOf ( MongoServerError ) ;
163
+ expect ( result ) . to . be . a ( 'number' ) ;
164
+ } ) ;
165
+ } ) ;
166
+
139
167
it ( 'should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable' , function ( ) {
140
168
client = this . configuration . newClient ( this . configuration . url ( ) , {
141
169
authMechanismProperties : { AWS_SESSION_TOKEN : '' }
@@ -426,11 +454,33 @@ describe('AWS KMS Credential Fetching', function () {
426
454
: undefined ;
427
455
this . currentTest ?. skipReason && this . skip ( ) ;
428
456
} ) ;
429
- it ( 'KMS credentials are successfully fetched.' , async function ( ) {
430
- const { aws } = await refreshKMSCredentials ( { aws : { } } ) ;
431
457
432
- expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
433
- expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
458
+ context ( 'when a credential provider is not providered' , function ( ) {
459
+ it ( 'KMS credentials are successfully fetched.' , async function ( ) {
460
+ const { aws } = await refreshKMSCredentials ( { aws : { } } ) ;
461
+
462
+ expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
463
+ expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
464
+ } ) ;
465
+ } ) ;
466
+
467
+ context ( 'when a credential provider is provided' , function ( ) {
468
+ let credentialProvider ;
469
+
470
+ beforeEach ( function ( ) {
471
+ // @ts -expect-error We intentionally access a protected variable.
472
+ credentialProvider = AWSTemporaryCredentialProvider . awsSDK ;
473
+ } ) ;
474
+
475
+ it ( 'KMS credentials are successfully fetched.' , async function ( ) {
476
+ const { aws } = await refreshKMSCredentials (
477
+ { aws : { } } ,
478
+ credentialProvider . fromNodeProviderChain ( )
479
+ ) ;
480
+
481
+ expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
482
+ expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
483
+ } ) ;
434
484
} ) ;
435
485
436
486
it ( 'does not return any extra keys for the `aws` credential provider' , async function ( ) {
0 commit comments