@@ -61,6 +61,25 @@ describe('MONGODB-AWS', function () {
61
61
expect ( result ) . to . be . a ( 'number' ) ;
62
62
} ) ;
63
63
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
+
64
83
it ( 'should allow empty string in authMechanismProperties.AWS_SESSION_TOKEN to override AWS_SESSION_TOKEN environment variable' , function ( ) {
65
84
client = this . configuration . newClient ( this . configuration . url ( ) , {
66
85
authMechanismProperties : { AWS_SESSION_TOKEN : '' }
@@ -351,11 +370,33 @@ describe('AWS KMS Credential Fetching', function () {
351
370
: undefined ;
352
371
this . currentTest ?. skipReason && this . skip ( ) ;
353
372
} ) ;
354
- it ( 'KMS credentials are successfully fetched.' , async function ( ) {
355
- const { aws } = await refreshKMSCredentials ( { aws : { } } ) ;
356
373
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
+ } ) ;
359
400
} ) ;
360
401
361
402
it ( 'does not return any extra keys for the `aws` credential provider' , async function ( ) {
0 commit comments