@@ -13,8 +13,9 @@ const FAKE_STS_SECRET_ACCESS_KEY = 'STS-AWS-SECRET-ACCESS-KEY';
1313const FAKE_STS_SESSION_TOKEN = 'STS-AWS-SESSION-TOKEN' ;
1414const FAKE_REGION = 'fake-region-1' ;
1515const FAKE_ACCOUNT_ID = '123456789012' ;
16+ const FAKE_ROLE_ACCOUNT_ID = '111111111111' ;
1617const 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' ;
1819const ENVIRONMENT_VARIABLE_OVERRIDES = {
1920 SHOW_STACK_TRACE : 'true' ,
2021 GITHUB_REPOSITORY : 'MY-REPOSITORY-NAME' ,
@@ -68,13 +69,18 @@ describe('Configure AWS Credentials', () => {
6869 . fn ( )
6970 . mockImplementation ( mockGetInput ( DEFAULT_INPUTS ) ) ;
7071
71- mockStsCallerIdentity . mockImplementation ( ( ) => {
72- return {
72+ mockStsCallerIdentity . mockReset ( ) ;
73+ mockStsCallerIdentity
74+ . mockReturnValueOnce ( {
7375 promise ( ) {
7476 return Promise . resolve ( { Account : FAKE_ACCOUNT_ID } ) ;
7577 }
76- } ;
77- } ) ;
78+ } )
79+ . mockReturnValueOnce ( {
80+ promise ( ) {
81+ return Promise . resolve ( { Account : FAKE_ROLE_ACCOUNT_ID } ) ;
82+ }
83+ } ) ;
7884
7985 mockStsAssumeRole . mockImplementation ( ( ) => {
8086 return {
@@ -154,6 +160,7 @@ describe('Configure AWS Credentials', () => {
154160 test ( 'error is caught by core.setFailed and caught' , async ( ) => {
155161 process . env . SHOW_STACK_TRACE = 'false' ;
156162
163+ mockStsCallerIdentity . mockReset ( ) ;
157164 mockStsCallerIdentity . mockImplementation ( ( ) => {
158165 throw new Error ( ) ;
159166 } ) ;
@@ -165,6 +172,7 @@ describe('Configure AWS Credentials', () => {
165172
166173 test ( 'error is caught by core.setFailed and passed' , async ( ) => {
167174
175+ mockStsCallerIdentity . mockReset ( ) ;
168176 mockStsCallerIdentity . mockImplementation ( ( ) => {
169177 throw new Error ( ) ;
170178 } ) ;
@@ -181,18 +189,33 @@ describe('Configure AWS Credentials', () => {
181189
182190 await run ( ) ;
183191 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 ) ;
196219 } ) ;
197220
198221 test ( 'role assumption tags' , async ( ) => {
@@ -268,7 +291,7 @@ describe('Configure AWS Credentials', () => {
268291
269292 await run ( ) ;
270293 expect ( mockStsAssumeRole ) . toHaveBeenCalledWith ( {
271- RoleArn : ROLE_ARN ,
294+ RoleArn : 'arn:aws:iam::123456789012:role/MY-ROLE' ,
272295 RoleSessionName : 'GitHubActions' ,
273296 DurationSeconds : 6 * 3600 ,
274297 Tags : [
0 commit comments