Skip to content

Commit fb34edb

Browse files
committed
Add mocks for other possible expired credentials errors
1 parent ea09e4c commit fb34edb

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

servicemocks/mock.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ const (
114114
</Error>
115115
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
116116
</ErrorResponse>`
117+
// MockStsGetCallerIdentityValidResponseBodyExpiredToken uses code "ExpiredToken", seemingly the most common
118+
// code. Errors usually have an invalid body but this may be fixed at some point.
117119
MockStsGetCallerIdentityValidResponseBodyExpiredToken = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
118120
<Error>
119121
<Type>Sender</Type>
@@ -124,13 +126,59 @@ const (
124126
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
125127
</ResponseMetadata>
126128
</ErrorResponse>`
129+
// MockStsGetCallerIdentityInvalidResponseBodyExpiredToken uses code "ExpiredToken", seemingly the most common
130+
// code. Errors usually have an invalid body.
127131
MockStsGetCallerIdentityInvalidResponseBodyExpiredToken = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
128132
<Error>
129133
<Type>Sender</Type>
130134
<Code>ExpiredToken</Code>
131135
<Message>The security token included in the request is expired</Message>
132136
</Error>
133137
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
138+
</ErrorResponse>`
139+
// MockStsGetCallerIdentityValidResponseBodyExpiredTokenException uses code "ExpiredTokenException", a more rare code
140+
// but used at least by Fargate. Errors usually have an invalid body but this may change.
141+
MockStsGetCallerIdentityValidResponseBodyExpiredTokenException = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
142+
<Error>
143+
<Type>Sender</Type>
144+
<Code>ExpiredTokenException</Code>
145+
<Message>The security token included in the request is expired</Message>
146+
</Error>
147+
<ResponseMetadata>
148+
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
149+
</ResponseMetadata>
150+
</ErrorResponse>`
151+
// MockStsGetCallerIdentityInvalidResponseBodyExpiredTokenException uses code "ExpiredTokenException", a more rare code
152+
// but used at least by Fargate. Errors usually have an invalid body but this may change.
153+
MockStsGetCallerIdentityInvalidResponseBodyExpiredTokenException = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
154+
<Error>
155+
<Type>Sender</Type>
156+
<Code>ExpiredTokenException</Code>
157+
<Message>The security token included in the request is expired</Message>
158+
</Error>
159+
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
160+
</ErrorResponse>`
161+
// MockStsGetCallerIdentityValidResponseBodyRequestExpired uses code "RequestExpired", a code only used in EC2.
162+
// Errors usually have an invalid body but this may change.
163+
MockStsGetCallerIdentityValidResponseBodyRequestExpired = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
164+
<Error>
165+
<Type>Sender</Type>
166+
<Code>RequestExpired</Code>
167+
<Message>The security token included in the request is expired</Message>
168+
</Error>
169+
<ResponseMetadata>
170+
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
171+
</ResponseMetadata>
172+
</ErrorResponse>`
173+
// MockStsGetCallerIdentityInvalidResponseBodyRequestExpired uses code "RequestExpired", a code only used in EC2.
174+
// Errors usually have an invalid body but this may change.
175+
MockStsGetCallerIdentityInvalidResponseBodyRequestExpired = `<ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
176+
<Error>
177+
<Type>Sender</Type>
178+
<Code>RequestExpired</Code>
179+
<Message>The security token included in the request is expired</Message>
180+
</Error>
181+
<RequestId>01234567-89ab-cdef-0123-456789abcdef</RequestId>
134182
</ErrorResponse>`
135183
MockStsGetCallerIdentityPartition = `aws`
136184
MockStsGetCallerIdentityValidResponseBody = `<GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
@@ -259,6 +307,66 @@ var (
259307
StatusCode: http.StatusForbidden,
260308
},
261309
}
310+
MockStsGetCallerIdentityInvalidBodyExpiredTokenException = &MockEndpoint{
311+
Request: &MockRequest{
312+
Body: url.Values{
313+
"Action": []string{"GetCallerIdentity"},
314+
"Version": []string{"2011-06-15"},
315+
}.Encode(),
316+
Method: http.MethodPost,
317+
Uri: "/",
318+
},
319+
Response: &MockResponse{
320+
Body: MockStsGetCallerIdentityInvalidResponseBodyExpiredTokenException,
321+
ContentType: "text/xml",
322+
StatusCode: http.StatusForbidden,
323+
},
324+
}
325+
MockStsGetCallerIdentityValidBodyExpiredTokenException = &MockEndpoint{
326+
Request: &MockRequest{
327+
Body: url.Values{
328+
"Action": []string{"GetCallerIdentity"},
329+
"Version": []string{"2011-06-15"},
330+
}.Encode(),
331+
Method: http.MethodPost,
332+
Uri: "/",
333+
},
334+
Response: &MockResponse{
335+
Body: MockStsGetCallerIdentityValidResponseBodyExpiredTokenException,
336+
ContentType: "text/xml",
337+
StatusCode: http.StatusForbidden,
338+
},
339+
}
340+
MockStsGetCallerIdentityInvalidBodyRequestExpired = &MockEndpoint{
341+
Request: &MockRequest{
342+
Body: url.Values{
343+
"Action": []string{"GetCallerIdentity"},
344+
"Version": []string{"2011-06-15"},
345+
}.Encode(),
346+
Method: http.MethodPost,
347+
Uri: "/",
348+
},
349+
Response: &MockResponse{
350+
Body: MockStsGetCallerIdentityInvalidResponseBodyRequestExpired,
351+
ContentType: "text/xml",
352+
StatusCode: http.StatusForbidden,
353+
},
354+
}
355+
MockStsGetCallerIdentityValidBodyRequestExpired = &MockEndpoint{
356+
Request: &MockRequest{
357+
Body: url.Values{
358+
"Action": []string{"GetCallerIdentity"},
359+
"Version": []string{"2011-06-15"},
360+
}.Encode(),
361+
Method: http.MethodPost,
362+
Uri: "/",
363+
},
364+
Response: &MockResponse{
365+
Body: MockStsGetCallerIdentityValidResponseBodyRequestExpired,
366+
ContentType: "text/xml",
367+
StatusCode: http.StatusForbidden,
368+
},
369+
}
262370
MockStsGetCallerIdentityValidEndpoint = &MockEndpoint{
263371
Request: &MockRequest{
264372
Body: url.Values{

0 commit comments

Comments
 (0)