File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lambdas/mock-webhook-lambda/src Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,10 @@ const mockLogger = jest.requireMock(
2222 "@nhs-notify-client-callbacks/logger" ,
2323) . instance ;
2424
25- const DEFAULT_HEADERS = { "x-api-key" : TEST_API_KEY } ;
25+ const DEFAULT_HEADERS = {
26+ "x-api-key" : TEST_API_KEY ,
27+ "x-hmac-sha256-signature" : "abc123" ,
28+ } ;
2629
2730const createMockEvent = (
2831 body : string | null ,
@@ -61,6 +64,18 @@ describe("Mock Webhook Lambda", () => {
6164 const body = JSON . parse ( result . body ) ;
6265 expect ( body . message ) . toBe ( "Unauthorized" ) ;
6366 } ) ;
67+
68+ it ( "should return 400 when x-hmac-sha256-signature header is missing" , async ( ) => {
69+ const callback = { data : [ ] } ;
70+ const event = createMockEvent ( JSON . stringify ( callback ) , {
71+ "x-api-key" : TEST_API_KEY ,
72+ } ) ;
73+ const result = await handler ( event ) ;
74+
75+ expect ( result . statusCode ) . toBe ( 400 ) ;
76+ const body = JSON . parse ( result . body ) ;
77+ expect ( body . message ) . toBe ( "Missing x-hmac-sha256-signature" ) ;
78+ } ) ;
6479 } ) ;
6580
6681 describe ( "Happy Path" , ( ) => {
Original file line number Diff line number Diff line change @@ -52,6 +52,14 @@ async function buildResponse(
5252 } ;
5353 }
5454
55+ if ( ! event . headers [ "x-hmac-sha256-signature" ] ) {
56+ logger . error ( "Bad request: missing x-hmac-sha256-signature header" ) ;
57+ return {
58+ statusCode : 400 ,
59+ body : JSON . stringify ( { message : "Missing x-hmac-sha256-signature" } ) ,
60+ } ;
61+ }
62+
5563 if ( ! event . body ) {
5664 logger . error ( "No event body received" ) ;
5765
You can’t perform that action at this time.
0 commit comments