Skip to content

Commit f30b190

Browse files
committed
CCM-11602: Get enpoint safe header check
1 parent 214ef5f commit f30b190

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lambdas/api-handler/src/handlers/__tests__/get-letters.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('API Lambda handler', () => {
7676
});
7777
});
7878

79-
it('returns 400 for missing supplier ID', async () => {
79+
it('returns 400 for missing supplier ID (empty headers)', async () => {
8080
const event = makeApiGwEvent({ path: "/letters", headers: {} });
8181
const context = mockDeep<Context>();
8282
const callback = jest.fn();
@@ -87,4 +87,16 @@ describe('API Lambda handler', () => {
8787
body: 'Bad Request: Missing supplier ID',
8888
});
8989
});
90+
91+
it('returns 400 for missing supplier ID (undefined headers)', async () => {
92+
const event = makeApiGwEvent({ path: "/letters", headers: undefined });
93+
const context = mockDeep<Context>();
94+
const callback = jest.fn();
95+
const result = await getLetters(event, context, callback);
96+
97+
expect(result).toEqual({
98+
statusCode: 400,
99+
body: 'Bad Request: Missing supplier ID',
100+
});
101+
});
90102
});

lambdas/api-handler/src/handlers/__tests__/utils/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function makeApiGwEvent(
88
path: '/',
99
httpMethod: 'GET',
1010
headers: {
11-
'nhsd-supplier-id': 'supplier1'
11+
'NHSD-Supplier-ID': 'supplier1'
1212
},
1313
multiValueHeaders: {},
1414
queryStringParameters: null,

lambdas/api-handler/src/handlers/get-letters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const letterRepo = createLetterRepository();
77

88
export const getLetters: APIGatewayProxyHandler = async (event) => {
99
if (event.path === "/letters") {
10-
const supplierId = event.headers["nhsd-supplier-id"];
10+
const supplierId = event.headers ? event.headers["NHSD-Supplier-ID"] : undefined;
1111

1212
if (!supplierId) {
1313
return {

0 commit comments

Comments
 (0)