@@ -22,6 +22,7 @@ import (
2222 "github.com/aws/aws-sdk-go-v2/config"
2323 "github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
2424 "github.com/aws/aws-sdk-go-v2/service/sts"
25+ "github.com/aws/smithy-go"
2526 "github.com/aws/smithy-go/middleware"
2627 smithyhttp "github.com/aws/smithy-go/transport/http"
2728 "github.com/google/go-cmp/cmp"
@@ -94,6 +95,52 @@ func TestGetAwsConfig(t *testing.T) {
9495 servicemocks .MockStsGetCallerIdentityValidEndpoint ,
9596 },
9697 },
98+ {
99+ Config : & Config {
100+ AccessKey : servicemocks .MockStaticAccessKey ,
101+ Region : "us-east-1" ,
102+ SecretKey : servicemocks .MockStaticSecretKey ,
103+ MaxRetries : 100 ,
104+ },
105+ Description : "ExpiredToken" ,
106+ ExpectedRegion : "us-east-1" ,
107+ ExpectedError : func (err error ) bool {
108+ return strings .Contains (err .Error (), "ExpiredToken" )
109+ },
110+ MockStsEndpoints : []* servicemocks.MockEndpoint {
111+ servicemocks .MockStsGetCallerIdentityInvalidBodyExpiredToken ,
112+ },
113+ },
114+ {
115+ Config : & Config {
116+ AccessKey : servicemocks .MockStaticAccessKey ,
117+ Region : "us-east-1" ,
118+ SecretKey : servicemocks .MockStaticSecretKey ,
119+ },
120+ Description : "ExpiredTokenException" ,
121+ ExpectedRegion : "us-east-1" ,
122+ ExpectedError : func (err error ) bool {
123+ return strings .Contains (err .Error (), "ExpiredTokenException" )
124+ },
125+ MockStsEndpoints : []* servicemocks.MockEndpoint {
126+ servicemocks .MockStsGetCallerIdentityInvalidBodyExpiredTokenException ,
127+ },
128+ },
129+ {
130+ Config : & Config {
131+ AccessKey : servicemocks .MockStaticAccessKey ,
132+ Region : "us-east-1" ,
133+ SecretKey : servicemocks .MockStaticSecretKey ,
134+ },
135+ Description : "RequestExpired" ,
136+ ExpectedRegion : "us-east-1" ,
137+ ExpectedError : func (err error ) bool {
138+ return strings .Contains (err .Error (), "RequestExpired" )
139+ },
140+ MockStsEndpoints : []* servicemocks.MockEndpoint {
141+ servicemocks .MockStsGetCallerIdentityInvalidBodyRequestExpired ,
142+ },
143+ },
97144 {
98145 Config : & Config {
99146 AccessKey : servicemocks .MockStaticAccessKey ,
@@ -3043,6 +3090,76 @@ func TestRetryHandlers(t *testing.T) {
30433090 return results
30443091 }(),
30453092 },
3093+ "no retries for ExpiredToken" : {
3094+ NextHandler : func () middleware.FinalizeHandler {
3095+ num := 0
3096+ reqsErrs := make ([]error , 2 )
3097+ for i := 0 ; i < 2 ; i ++ {
3098+ reqsErrs [i ] = & smithy.OperationError {
3099+ ServiceID : "STS" ,
3100+ OperationName : "GetCallerIdentity" ,
3101+ Err : & smithyhttp.ResponseError {
3102+ Response : & smithyhttp.Response {
3103+ Response : & http.Response {
3104+ StatusCode : 403 ,
3105+ },
3106+ },
3107+ Err : & smithy.GenericAPIError {
3108+ Code : "ExpiredToken" ,
3109+ Message : "The security token included in the request is expired" ,
3110+ },
3111+ },
3112+ }
3113+ }
3114+ return middleware .FinalizeHandlerFunc (func (ctx context.Context , in middleware.FinalizeInput ) (out middleware.FinalizeOutput , metadata middleware.Metadata , err error ) {
3115+ if num >= len (reqsErrs ) {
3116+ err = fmt .Errorf ("more requests than expected" )
3117+ } else {
3118+ err = reqsErrs [num ]
3119+ num ++
3120+ }
3121+ return out , metadata , err
3122+ })
3123+ },
3124+ Err : & smithy.OperationError {
3125+ ServiceID : "STS" ,
3126+ OperationName : "GetCallerIdentity" ,
3127+ Err : & smithyhttp.ResponseError {
3128+ Response : & smithyhttp.Response {
3129+ Response : & http.Response {
3130+ StatusCode : 403 ,
3131+ },
3132+ },
3133+ Err : & smithy.GenericAPIError {
3134+ Code : "ExpiredToken" ,
3135+ Message : "The security token included in the request is expired" ,
3136+ },
3137+ },
3138+ },
3139+ ExpectResults : func () retry.AttemptResults {
3140+ results := retry.AttemptResults {
3141+ Results : make ([]retry.AttemptResult , 1 ),
3142+ }
3143+ results .Results [0 ] = retry.AttemptResult {
3144+ Err : & smithy.OperationError {
3145+ ServiceID : "STS" ,
3146+ OperationName : "GetCallerIdentity" ,
3147+ Err : & smithyhttp.ResponseError {
3148+ Response : & smithyhttp.Response {
3149+ Response : & http.Response {
3150+ StatusCode : 403 ,
3151+ },
3152+ },
3153+ Err : & smithy.GenericAPIError {
3154+ Code : "ExpiredToken" ,
3155+ Message : "The security token included in the request is expired" ,
3156+ },
3157+ },
3158+ },
3159+ }
3160+ return results
3161+ }(),
3162+ },
30463163 "stops at maxRetries for other network errors" : {
30473164 NextHandler : func () middleware.FinalizeHandler {
30483165 num := 0
0 commit comments