File tree 2 files changed +22
-1
lines changed
packages/credential-provider-node/src
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -395,5 +395,26 @@ describe("defaultProvider", () => {
395
395
expect ( ( fromContainerMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
396
396
expect ( ( fromInstanceMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
397
397
} ) ;
398
+
399
+ it ( "should consult the process provider if no credentials are found in the ini provider" , async ( ) => {
400
+ const creds = {
401
+ accessKeyId : "foo" ,
402
+ secretAccessKey : "bar" ,
403
+ } ;
404
+
405
+ ( fromEnv ( ) as any ) . mockImplementation ( ( ) => Promise . reject ( new Error ( "PANIC" ) ) ) ;
406
+ ( fromIni ( ) as any ) . mockImplementation ( ( ) => Promise . reject ( new ProviderError ( "Nothing here!" ) ) ) ;
407
+ ( fromProcess ( ) as any ) . mockImplementation ( ( ) => Promise . resolve ( creds ) ) ;
408
+ ( fromInstanceMetadata ( ) as any ) . mockImplementation ( ( ) => Promise . reject ( new Error ( "PANIC" ) ) ) ;
409
+ ( fromContainerMetadata ( ) as any ) . mockImplementation ( ( ) => Promise . reject ( new Error ( "PANIC" ) ) ) ;
410
+
411
+ process . env [ ENV_PROFILE ] = "foo" ;
412
+ expect ( await defaultProvider ( ) ( ) ) . toEqual ( creds ) ;
413
+ expect ( ( fromEnv ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
414
+ expect ( ( fromIni ( ) as any ) . mock . calls . length ) . toBe ( 1 ) ;
415
+ expect ( ( fromProcess ( ) as any ) . mock . calls . length ) . toBe ( 1 ) ;
416
+ expect ( ( fromContainerMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
417
+ expect ( ( fromInstanceMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
418
+ } ) ;
398
419
} ) ;
399
420
} ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED";
44
44
export function defaultProvider ( init : FromIniInit & RemoteProviderInit & FromProcessInit = { } ) : CredentialProvider {
45
45
const { profile = process . env [ ENV_PROFILE ] } = init ;
46
46
const providerChain = profile
47
- ? fromIni ( init )
47
+ ? chain ( fromIni ( init ) , fromProcess ( init ) )
48
48
: chain ( fromEnv ( ) , fromIni ( init ) , fromProcess ( init ) , remoteProvider ( init ) ) ;
49
49
50
50
return memoize (
You can’t perform that action at this time.
0 commit comments