@@ -13,8 +13,9 @@ const FAKE_STS_SECRET_ACCESS_KEY = 'STS-AWS-SECRET-ACCESS-KEY';
13
13
const FAKE_STS_SESSION_TOKEN = 'STS-AWS-SESSION-TOKEN' ;
14
14
const FAKE_REGION = 'fake-region-1' ;
15
15
const FAKE_ACCOUNT_ID = '123456789012' ;
16
+ const FAKE_ROLE_ACCOUNT_ID = '111111111111' ;
16
17
const ROLE_NAME = 'MY-ROLE' ;
17
- const ROLE_ARN = 'arn:aws:iam::123456789012 :role/MY-ROLE' ;
18
+ const ROLE_ARN = 'arn:aws:iam::111111111111 :role/MY-ROLE' ;
18
19
const ENVIRONMENT_VARIABLE_OVERRIDES = {
19
20
SHOW_STACK_TRACE : 'true' ,
20
21
GITHUB_REPOSITORY : 'MY-REPOSITORY-NAME' ,
@@ -68,13 +69,18 @@ describe('Configure AWS Credentials', () => {
68
69
. fn ( )
69
70
. mockImplementation ( mockGetInput ( DEFAULT_INPUTS ) ) ;
70
71
71
- mockStsCallerIdentity . mockImplementation ( ( ) => {
72
- return {
72
+ mockStsCallerIdentity . mockReset ( ) ;
73
+ mockStsCallerIdentity
74
+ . mockReturnValueOnce ( {
73
75
promise ( ) {
74
76
return Promise . resolve ( { Account : FAKE_ACCOUNT_ID } ) ;
75
77
}
76
- } ;
77
- } ) ;
78
+ } )
79
+ . mockReturnValueOnce ( {
80
+ promise ( ) {
81
+ return Promise . resolve ( { Account : FAKE_ROLE_ACCOUNT_ID } ) ;
82
+ }
83
+ } ) ;
78
84
79
85
mockStsAssumeRole . mockImplementation ( ( ) => {
80
86
return {
@@ -154,6 +160,7 @@ describe('Configure AWS Credentials', () => {
154
160
test ( 'error is caught by core.setFailed and caught' , async ( ) => {
155
161
process . env . SHOW_STACK_TRACE = 'false' ;
156
162
163
+ mockStsCallerIdentity . mockReset ( ) ;
157
164
mockStsCallerIdentity . mockImplementation ( ( ) => {
158
165
throw new Error ( ) ;
159
166
} ) ;
@@ -165,6 +172,7 @@ describe('Configure AWS Credentials', () => {
165
172
166
173
test ( 'error is caught by core.setFailed and passed' , async ( ) => {
167
174
175
+ mockStsCallerIdentity . mockReset ( ) ;
168
176
mockStsCallerIdentity . mockImplementation ( ( ) => {
169
177
throw new Error ( ) ;
170
178
} ) ;
@@ -181,18 +189,33 @@ describe('Configure AWS Credentials', () => {
181
189
182
190
await run ( ) ;
183
191
expect ( mockStsAssumeRole ) . toHaveBeenCalledTimes ( 1 ) ;
184
- expect ( core . exportVariable ) . toHaveBeenCalledTimes ( 5 ) ;
185
- expect ( core . setSecret ) . toHaveBeenCalledTimes ( 4 ) ;
186
- expect ( core . exportVariable ) . toHaveBeenCalledWith ( 'AWS_ACCESS_KEY_ID' , FAKE_STS_ACCESS_KEY_ID ) ;
187
- expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_STS_ACCESS_KEY_ID ) ;
188
- expect ( core . exportVariable ) . toHaveBeenCalledWith ( 'AWS_SECRET_ACCESS_KEY' , FAKE_STS_SECRET_ACCESS_KEY ) ;
189
- expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_STS_SECRET_ACCESS_KEY ) ;
190
- expect ( core . exportVariable ) . toHaveBeenCalledWith ( 'AWS_SESSION_TOKEN' , FAKE_STS_SESSION_TOKEN ) ;
191
- expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_STS_SESSION_TOKEN ) ;
192
- expect ( core . exportVariable ) . toHaveBeenCalledWith ( 'AWS_DEFAULT_REGION' , FAKE_REGION ) ;
193
- expect ( core . exportVariable ) . toHaveBeenCalledWith ( 'AWS_REGION' , FAKE_REGION ) ;
194
- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'aws-account-id' , FAKE_ACCOUNT_ID ) ;
195
- expect ( core . setSecret ) . toHaveBeenCalledWith ( FAKE_ACCOUNT_ID ) ;
192
+ expect ( core . exportVariable ) . toHaveBeenCalledTimes ( 7 ) ;
193
+ expect ( core . setSecret ) . toHaveBeenCalledTimes ( 7 ) ;
194
+ expect ( core . setOutput ) . toHaveBeenCalledTimes ( 2 ) ;
195
+
196
+ // first the source credentials are exported and masked
197
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 1 , FAKE_ACCESS_KEY_ID ) ;
198
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 2 , FAKE_SECRET_ACCESS_KEY ) ;
199
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 3 , FAKE_ACCOUNT_ID ) ;
200
+
201
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 1 , 'AWS_DEFAULT_REGION' , FAKE_REGION ) ;
202
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 2 , 'AWS_REGION' , FAKE_REGION ) ;
203
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 3 , 'AWS_ACCESS_KEY_ID' , FAKE_ACCESS_KEY_ID ) ;
204
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 4 , 'AWS_SECRET_ACCESS_KEY' , FAKE_SECRET_ACCESS_KEY ) ;
205
+
206
+ expect ( core . setOutput ) . toHaveBeenNthCalledWith ( 1 , 'aws-account-id' , FAKE_ACCOUNT_ID ) ;
207
+
208
+ // then the role credentials are exported and masked
209
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 4 , FAKE_STS_ACCESS_KEY_ID ) ;
210
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 5 , FAKE_STS_SECRET_ACCESS_KEY ) ;
211
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 6 , FAKE_STS_SESSION_TOKEN ) ;
212
+ expect ( core . setSecret ) . toHaveBeenNthCalledWith ( 7 , FAKE_ROLE_ACCOUNT_ID ) ;
213
+
214
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 5 , 'AWS_ACCESS_KEY_ID' , FAKE_STS_ACCESS_KEY_ID ) ;
215
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 6 , 'AWS_SECRET_ACCESS_KEY' , FAKE_STS_SECRET_ACCESS_KEY ) ;
216
+ expect ( core . exportVariable ) . toHaveBeenNthCalledWith ( 7 , 'AWS_SESSION_TOKEN' , FAKE_STS_SESSION_TOKEN ) ;
217
+
218
+ expect ( core . setOutput ) . toHaveBeenNthCalledWith ( 2 , 'aws-account-id' , FAKE_ROLE_ACCOUNT_ID ) ;
196
219
} ) ;
197
220
198
221
test ( 'role assumption tags' , async ( ) => {
@@ -268,7 +291,7 @@ describe('Configure AWS Credentials', () => {
268
291
269
292
await run ( ) ;
270
293
expect ( mockStsAssumeRole ) . toHaveBeenCalledWith ( {
271
- RoleArn : ROLE_ARN ,
294
+ RoleArn : 'arn:aws:iam::123456789012:role/MY-ROLE' ,
272
295
RoleSessionName : 'GitHubActions' ,
273
296
DurationSeconds : 6 * 3600 ,
274
297
Tags : [
0 commit comments