@@ -61,6 +61,34 @@ describe('MONGODB-AWS', function () {
61
61
expect ( result ) . to . be . a ( 'number' ) ;
62
62
} ) ;
63
63
64
+ context ( 'when user supplies a credentials provider' , function ( ) {
65
+ beforeEach ( function ( ) {
66
+ if ( ! awsSdkPresent ) {
67
+ this . skipReason = 'only relevant to AssumeRoleWithWebIdentity with SDK installed' ;
68
+ return this . skip ( ) ;
69
+ }
70
+ } ) ;
71
+
72
+ it ( 'authenticates with a user provided credentials provider' , async function ( ) {
73
+ // @ts -expect-error We intentionally access a protected variable.
74
+ const credentialProvider = AWSTemporaryCredentialProvider . awsSDK ;
75
+ client = this . configuration . newClient ( process . env . MONGODB_URI , {
76
+ authMechanismProperties : {
77
+ AWS_CREDENTIAL_PROVIDER : credentialProvider . fromNodeProviderChain ( )
78
+ }
79
+ } ) ;
80
+
81
+ const result = await client
82
+ . db ( 'aws' )
83
+ . collection ( 'aws_test' )
84
+ . estimatedDocumentCount ( )
85
+ . catch ( error => error ) ;
86
+
87
+ expect ( result ) . to . not . be . instanceOf ( MongoServerError ) ;
88
+ expect ( result ) . to . be . a ( 'number' ) ;
89
+ } ) ;
90
+ } ) ;
91
+
64
92
it ( 'should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable' , function ( ) {
65
93
client = this . configuration . newClient ( this . configuration . url ( ) , {
66
94
authMechanismProperties : { AWS_SESSION_TOKEN : '' }
@@ -351,11 +379,33 @@ describe('AWS KMS Credential Fetching', function () {
351
379
: undefined ;
352
380
this . currentTest ?. skipReason && this . skip ( ) ;
353
381
} ) ;
354
- it ( 'KMS credentials are successfully fetched.' , async function ( ) {
355
- const { aws } = await refreshKMSCredentials ( { aws : { } } ) ;
356
382
357
- expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
358
- expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
383
+ context ( 'when a credential provider is not providered' , function ( ) {
384
+ it ( 'KMS credentials are successfully fetched.' , async function ( ) {
385
+ const { aws } = await refreshKMSCredentials ( { aws : { } } ) ;
386
+
387
+ expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
388
+ expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
389
+ } ) ;
390
+ } ) ;
391
+
392
+ context ( 'when a credential provider is provided' , function ( ) {
393
+ let credentialProvider ;
394
+
395
+ beforeEach ( function ( ) {
396
+ // @ts -expect-error We intentionally access a protected variable.
397
+ credentialProvider = AWSTemporaryCredentialProvider . awsSDK ;
398
+ } ) ;
399
+
400
+ it ( 'KMS credentials are successfully fetched.' , async function ( ) {
401
+ const { aws } = await refreshKMSCredentials (
402
+ { aws : { } } ,
403
+ credentialProvider . fromNodeProviderChain ( )
404
+ ) ;
405
+
406
+ expect ( aws ) . to . have . property ( 'accessKeyId' ) ;
407
+ expect ( aws ) . to . have . property ( 'secretAccessKey' ) ;
408
+ } ) ;
359
409
} ) ;
360
410
361
411
it ( 'does not return any extra keys for the `aws` credential provider' , async function ( ) {
0 commit comments