File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,13 +27,18 @@ jobs:
2727 - name : Install dependencies
2828 run : npm ci --legacy-peer-deps
2929
30+ - name : Get current date for cache key
31+ id : date
32+ run : echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
33+
3034 - name : Restore IMS token cache
3135 uses : actions/cache@v4
3236 with :
3337 path : .ims-token-prod-cache.json
34- key : ims-token-${{ github.repository }}-${{ hashFiles('.ims-token-prod-cache.json') }}
38+ # Cache key includes date to force refresh daily (prevents stale/corrupted tokens)
39+ key : ims-token-prod-${{ steps.date.outputs.date }}
3540 restore-keys : |
36- ims-token-${{ github.repository }}- prod-
41+ ims-token-prod-
3742
3843 - name : Run E2E Tests
3944 env :
Original file line number Diff line number Diff line change @@ -27,13 +27,18 @@ jobs:
2727 - name : Install dependencies
2828 run : npm ci --legacy-peer-deps
2929
30+ - name : Get current date for cache key
31+ id : date
32+ run : echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
33+
3034 - name : Restore IMS token cache
3135 uses : actions/cache@v4
3236 with :
3337 path : .ims-token-dev-cache.json
34- key : ims-token-${{ github.repository }}-${{ hashFiles('.ims-token-dev-cache.json') }}
38+ # Cache key includes date to force refresh daily (prevents stale/corrupted tokens)
39+ key : ims-token-dev-${{ steps.date.outputs.date }}
3540 restore-keys : |
36- ims-token-${{ github.repository }}- dev-
41+ ims-token-dev-
3742
3843 - name : Run E2E Tests
3944 env :
Original file line number Diff line number Diff line change @@ -188,7 +188,26 @@ export class ImsHelper {
188188 if ( ! tokenData || ! tokenData . expires_at ) {
189189 return false ;
190190 }
191- return Date . now ( ) < tokenData . expires_at ;
191+
192+ const now = Date . now ( ) ;
193+ const expiresAt = tokenData . expires_at ;
194+
195+ // Check if expires_at is in the past
196+ if ( expiresAt <= now ) {
197+ return false ;
198+ }
199+
200+ // Sanity check: expires_at should not be more than 48 hours in the future
201+ // IMS tokens typically last 24 hours, so 48 hours is a reasonable max
202+ const maxValidDuration = 48 * 60 * 60 * 1000 ; // 48 hours in milliseconds
203+ const remainingTime = expiresAt - now ;
204+
205+ if ( remainingTime > maxValidDuration ) {
206+ console . warn ( `Token expiration looks invalid (${ Math . floor ( remainingTime / 60000 ) } minutes). Treating as expired.` ) ;
207+ return false ;
208+ }
209+
210+ return true ;
192211 }
193212}
194213
You can’t perform that action at this time.
0 commit comments