@@ -3,7 +3,13 @@ import { externalDataInterceptor } from "@smithy/shared-ini-file-loader";
33import { NodeHttpHandler } from "@smithy/node-http-handler" ;
44import { STS , STSExtensionConfiguration } from "@aws-sdk/client-sts" ;
55import * as credentialProviderHttp from "@aws-sdk/credential-provider-http" ;
6- import { fromCognitoIdentity , fromCognitoIdentityPool , fromIni , fromWebToken } from "@aws-sdk/credential-providers" ;
6+ import {
7+ fromCognitoIdentity ,
8+ fromCognitoIdentityPool ,
9+ fromIni ,
10+ fromWebToken ,
11+ fromTokenFile ,
12+ } from "@aws-sdk/credential-providers" ;
713import { HttpResponse } from "@smithy/protocol-http" ;
814import type { HttpRequest , MiddlewareStack , NodeHttpHandlerOptions , ParsedIniData } from "@smithy/types" ;
915import { AdaptiveRetryStrategy , StandardRetryStrategy } from "@smithy/util-retry" ;
@@ -777,6 +783,51 @@ describe("credential-provider-node integration test", () => {
777783 } ) ;
778784
779785 describe ( "fromTokenFile" , ( ) => {
786+ it ( "should use the caller client region when combined with one" , async ( ) => {
787+ sts = new STS ( {
788+ region : "ap-northeast-1" ,
789+ credentials : fromTokenFile ( {
790+ roleArn : "ROLE_ARN" ,
791+ webIdentityTokenFile : "token-filepath" ,
792+ } ) ,
793+ } ) ;
794+ await sts . getCallerIdentity ( { } ) ;
795+ const credentials = await sts . config . credentials ( ) ;
796+ expect ( credentials ) . toEqual ( {
797+ accessKeyId : "STS_ARWI_ACCESS_KEY_ID" ,
798+ secretAccessKey : "STS_ARWI_SECRET_ACCESS_KEY" ,
799+ sessionToken : "STS_ARWI_SESSION_TOKEN_ap-northeast-1" ,
800+ expiration : new Date ( "3000-01-01T00:00:00.000Z" ) ,
801+ $source : {
802+ CREDENTIALS_CODE : "e" ,
803+ CREDENTIALS_STS_ASSUME_ROLE_WEB_ID : "k" ,
804+ } ,
805+ } ) ;
806+ } ) ;
807+
808+ it ( "should use the caller client region if derived from AWS_REGION" , async ( ) => {
809+ process . env . AWS_REGION = "eu-west-2" ;
810+ const provider = fromTokenFile ( {
811+ roleArn : "ROLE_ARN" ,
812+ webIdentityTokenFile : "token-filepath" ,
813+ } ) ;
814+ sts = new STS ( {
815+ credentials : provider ,
816+ } ) ;
817+ await sts . getCallerIdentity ( { } ) ;
818+ const credentials = await sts . config . credentials ( ) ;
819+ expect ( credentials ) . toEqual ( {
820+ accessKeyId : "STS_ARWI_ACCESS_KEY_ID" ,
821+ secretAccessKey : "STS_ARWI_SECRET_ACCESS_KEY" ,
822+ sessionToken : "STS_ARWI_SESSION_TOKEN_eu-west-2" ,
823+ expiration : new Date ( "3000-01-01T00:00:00.000Z" ) ,
824+ $source : {
825+ CREDENTIALS_CODE : "e" ,
826+ CREDENTIALS_STS_ASSUME_ROLE_WEB_ID : "k" ,
827+ } ,
828+ } ) ;
829+ } ) ;
830+
780831 it ( "should resolve credentials with STS assumeRoleWithWebIdentity using a token" , async ( ) => {
781832 process . env . AWS_WEB_IDENTITY_TOKEN_FILE = "token-filepath" ;
782833 process . env . AWS_ROLE_ARN = "ROLE_ARN" ;
0 commit comments