File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed
Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,32 @@ describe('Authorizer Lambda Function', () => {
182182 principalId : 'supplier-123' ,
183183 } ) ) ;
184184 } ) ;
185+
186+ it ( 'Should allow the request when the supplier ID case mismatches' , async ( ) => {
187+ mockEvent . headers = { 'apim-application-id' : 'Valid-Apim-Id' } ;
188+ ( mockedDeps . supplierRepo . getSupplierByApimId as jest . Mock ) . mockResolvedValue ( {
189+ id : 'supplier-123' ,
190+ apimApplicationId : 'valid-apim-id' ,
191+ name : 'Test Supplier' ,
192+ status : 'ENABLED'
193+ } ) ;
194+
195+ const handler = createAuthorizerHandler ( mockedDeps ) ;
196+ handler ( mockEvent , mockContext , mockCallback ) ;
197+ await new Promise ( process . nextTick ) ;
198+
199+ expect ( mockCallback ) . toHaveBeenCalledWith ( null , expect . objectContaining ( {
200+ policyDocument : expect . objectContaining ( {
201+ Statement : [
202+ expect . objectContaining ( {
203+ Effect : 'Allow' ,
204+ } ) ,
205+ ] ,
206+ } ) ,
207+ principalId : 'supplier-123' ,
208+ } ) ) ;
209+ } ) ;
210+
185211 } ) ;
186212
187213 it ( 'Should deny the request the supplier is disabled' , async ( ) => {
Original file line number Diff line number Diff line change @@ -42,16 +42,16 @@ export function createAuthorizerHandler(deps: Deps): APIGatewayRequestAuthorizer
4242
4343async function getSupplier ( headers : APIGatewayRequestAuthorizerEventHeaders | null , deps : Deps ) : Promise < Supplier > {
4444 const apimId = Object . entries ( headers || { } )
45- . find ( ( [ headerName , _ ] ) => headerName . toLowerCase ( ) === deps . env . APIM_APPLICATION_ID_HEADER ) ?. [ 1 ] as string ;
45+ . find ( ( [ headerName , _ ] ) => headerName . toLowerCase ( ) === deps . env . APIM_APPLICATION_ID_HEADER . toLowerCase ( ) ) ?. [ 1 ] as string ;
4646
47- if ( ! apimId ) {
48- throw new Error ( 'No APIM application ID found in header' ) ;
49- }
50- const supplier = await deps . supplierRepo . getSupplierByApimId ( apimId ) ;
51- if ( supplier . status === 'DISABLED' ) {
47+ if ( ! apimId ) {
48+ throw new Error ( 'No APIM application ID found in header' ) ;
49+ }
50+ const supplier = await deps . supplierRepo . getSupplierByApimId ( apimId ) ;
51+ if ( supplier . status === 'DISABLED' ) {
5252 throw new Error ( `Supplier ${ supplier . id } is disabled` ) ;
53- }
54- return supplier ;
53+ }
54+ return supplier ;
5555}
5656
5757
You can’t perform that action at this time.
0 commit comments