Skip to content

Commit 66a7045

Browse files
authored
fix: do not revoke token if already expired (actions#147)
Closes actions#140 The pull request at actions#95 introduced changes to avoid revoking expired tokens by saving the `expiresAt` value in the state. The change, however, used `core.setOutput` instead of `core.setState` meaning the value is not saved in the state but rather available in the output. ```javascript if (!skipTokenRevoke) { core.saveState("token", authentication.token); core.setOutput("expiresAt", authentication.expiresAt); } ``` This means that when we use the value downstream, it evaluates to an empty string and the following code block is never run: ```javascript const expiresAt = core.getState("expiresAt"); if (expiresAt && tokenExpiresIn(expiresAt) < 0) { core.info("Token expired, skipping token revocation"); return; } ``` This is a tiny PR to correct that typo.
1 parent d2eeb38 commit 66a7045

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

dist/main.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39753,7 +39753,7 @@ async function main(appId2, privateKey2, owner2, repositories2, core3, createApp
3975339753
core3.setOutput("app-slug", appSlug);
3975439754
if (!skipTokenRevoke2) {
3975539755
core3.saveState("token", authentication.token);
39756-
core3.setOutput("expiresAt", authentication.expiresAt);
39756+
core3.saveState("expiresAt", authentication.expiresAt);
3975739757
}
3975839758
}
3975939759
async function getTokenFromOwner(request2, auth5, parsedOwner) {

lib/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function main(
104104
// Make token accessible to post function (so we can invalidate it)
105105
if (!skipTokenRevoke) {
106106
core.saveState("token", authentication.token);
107-
core.setOutput("expiresAt", authentication.expiresAt);
107+
core.saveState("expiresAt", authentication.expiresAt);
108108
}
109109
}
110110

tests/snapshots/index.js.md

+9-18
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ Generated by [AVA](https://avajs.dev).
3333
3434
::set-output name=app-slug::github-actions␊
3535
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
36-
37-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
36+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
3837

3938
## main-missing-app-id.test.js
4039

@@ -94,8 +93,7 @@ Generated by [AVA](https://avajs.dev).
9493
9594
::set-output name=app-slug::github-actions␊
9695
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
97-
98-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
96+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
9997

10098
## main-token-get-owner-set-repo-set-to-many.test.js
10199

@@ -114,8 +112,7 @@ Generated by [AVA](https://avajs.dev).
114112
115113
::set-output name=app-slug::github-actions␊
116114
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
117-
118-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
115+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
119116

120117
## main-token-get-owner-set-repo-set-to-one.test.js
121118

@@ -134,8 +131,7 @@ Generated by [AVA](https://avajs.dev).
134131
135132
::set-output name=app-slug::github-actions␊
136133
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
137-
138-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
134+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
139135

140136
## main-token-get-owner-set-to-org-repo-unset.test.js
141137

@@ -154,8 +150,7 @@ Generated by [AVA](https://avajs.dev).
154150
155151
::set-output name=app-slug::github-actions␊
156152
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
157-
158-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
153+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
159154

160155
## main-token-get-owner-set-to-user-fail-response.test.js
161156

@@ -175,8 +170,7 @@ Generated by [AVA](https://avajs.dev).
175170
176171
::set-output name=app-slug::github-actions␊
177172
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
178-
179-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
173+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
180174

181175
## main-token-get-owner-set-to-user-repo-unset.test.js
182176

@@ -195,8 +189,7 @@ Generated by [AVA](https://avajs.dev).
195189
196190
::set-output name=app-slug::github-actions␊
197191
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
198-
199-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
192+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
200193

201194
## main-token-get-owner-unset-repo-set.test.js
202195

@@ -215,8 +208,7 @@ Generated by [AVA](https://avajs.dev).
215208
216209
::set-output name=app-slug::github-actions␊
217210
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
218-
219-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
211+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
220212

221213
## main-token-get-owner-unset-repo-unset.test.js
222214

@@ -235,8 +227,7 @@ Generated by [AVA](https://avajs.dev).
235227
236228
::set-output name=app-slug::github-actions␊
237229
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a␊
238-
239-
::set-output name=expiresAt::2016-07-11T22:14:10Z`
230+
::save-state name=expiresAt::2016-07-11T22:14:10Z`
240231

241232
## post-revoke-token-fail-response.test.js
242233

tests/snapshots/index.js.snap

-3 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)