Skip to content

Commit 9cae234

Browse files
Fix expiry unit tests
1 parent c962260 commit 9cae234

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

lambdas/authorizer/src/__tests__/index.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ describe("Authorizer Lambda Function", () => {
5656
});
5757

5858
describe("Certificate expiry check", () => {
59+
const currentDate = new Date("2025-11-01T14:19:00Z");
5960
beforeEach(() => {
6061
jest
6162
.useFakeTimers({ doNotFake: ["nextTick"] })
62-
.setSystemTime(new Date("2025-11-03T14:19:00Z"));
63+
.setSystemTime(currentDate);
6364
});
6465

6566
afterEach(() => {
@@ -81,7 +82,7 @@ describe("Authorizer Lambda Function", () => {
8182

8283
it("Should log CloudWatch metric when the certificate expiry threshold is reached", async () => {
8384
mockEvent.requestContext.identity.clientCert = buildCertWithExpiry(
84-
"2025-11-17T14:19:00Z",
85+
"2025-11-31T14:19:00Z",
8586
);
8687

8788
const handler = createAuthorizerHandler(mockedDeps);
@@ -92,7 +93,7 @@ describe("Authorizer Lambda Function", () => {
9293
expect(mockedInfo.mock.calls.map((call) => call[0])).toContain(
9394
JSON.stringify({
9495
_aws: {
95-
Timestamp: 1_762_179_540_000,
96+
Timestamp: currentDate.getTime(),
9697
CloudWatchMetrics: [
9798
{
9899
Namespace: "cloudwatch-namespace",
@@ -108,15 +109,15 @@ describe("Authorizer Lambda Function", () => {
108109
],
109110
},
110111
SUBJECT_DN: "CN=test-subject",
111-
NOT_AFTER: "2025-11-17T14:19:00Z",
112+
NOT_AFTER: "2025-11-31T14:19:00Z",
112113
"apim-client-certificate-near-expiry": 1,
113114
}),
114115
);
115116
});
116117

117118
it("Should not log CloudWatch metric when the certificate expiry threshold is not yet reached", async () => {
118119
mockEvent.requestContext.identity.clientCert = buildCertWithExpiry(
119-
"2025-11-18T14:19:00Z",
120+
"2026-01-01T14:19:00Z",
120121
);
121122

122123
const handler = createAuthorizerHandler(mockedDeps);

0 commit comments

Comments
 (0)