Skip to content

Commit 4711785

Browse files
S PadmaS Padma
authored andcommitted
modified cache
1 parent 3d0b4ff commit 4711785

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

.github/workflows/e2e-test-prod.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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:

.github/workflows/e2e-test-stage.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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:

utils/imsHelper.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)