File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
packages/credential-provider-node/src Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -395,5 +395,26 @@ describe("defaultProvider", () => {
395395 expect ( ( fromContainerMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
396396 expect ( ( fromInstanceMetadata ( ) as any ) . mock . calls . length ) . toBe ( 0 ) ;
397397 } ) ;
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+ } ) ;
398419 } ) ;
399420} ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED";
4444export function defaultProvider ( init : FromIniInit & RemoteProviderInit & FromProcessInit = { } ) : CredentialProvider {
4545 const { profile = process . env [ ENV_PROFILE ] } = init ;
4646 const providerChain = profile
47- ? fromIni ( init )
47+ ? chain ( fromIni ( init ) , fromProcess ( init ) )
4848 : chain ( fromEnv ( ) , fromIni ( init ) , fromProcess ( init ) , remoteProvider ( init ) ) ;
4949
5050 return memoize (
You can’t perform that action at this time.
0 commit comments