Skip to content

Commit b7341fe

Browse files
CCM-23428: fix sonarqube error in main (#747)
* fix sonarqube error in main * update unit test coverage * fix lint issues
1 parent 2477685 commit b7341fe

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ describe("Authorizer Lambda Function", () => {
139139

140140
expect(metricScope).not.toHaveBeenCalled();
141141
});
142+
143+
it("Should log an error when the certificate expiry check fails", async () => {
144+
mockEvent.requestContext.identity.clientCert = buildCertWithExpiry(
145+
"2025-11-31T14:19:00Z",
146+
);
147+
const error = new Error("Metrics failure");
148+
(metricScope as jest.Mock).mockImplementationOnce(() =>
149+
jest.fn().mockRejectedValue(error),
150+
);
151+
152+
const handler = createAuthorizerHandler(mockedDeps);
153+
handler(mockEvent, mockContext, mockCallback);
154+
await new Promise(process.nextTick);
155+
156+
expect(mockedDeps.logger.error).toHaveBeenCalledWith({
157+
description: "Error checking certificate expiry",
158+
err: error,
159+
});
160+
});
142161
});
143162

144163
describe("Supplier ID lookup", () => {

‎lambdas/authorizer/src/authorizer.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ export default function createAuthorizerHandler(
1919
context: Context,
2020
callback: Callback<APIGatewayAuthorizerResult>,
2121
): void => {
22-
checkCertificateExpiry(event.requestContext.identity.clientCert, deps);
22+
checkCertificateExpiry(
23+
event.requestContext.identity.clientCert,
24+
deps,
25+
).catch((error) => {
26+
deps.logger.error({
27+
description: "Error checking certificate expiry",
28+
err: error,
29+
});
30+
});
2331

2432
getSupplier(event.headers, deps)
2533
.then((supplier: Supplier) => {

0 commit comments

Comments
 (0)