Skip to content

Commit 8214c5f

Browse files
committed
CCM-11600: fix header lookup
1 parent 035ef65 commit 8214c5f

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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 () => {

lambdas/authorizer/src/authorizer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ export function createAuthorizerHandler(deps: Deps): APIGatewayRequestAuthorizer
4242

4343
async 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

0 commit comments

Comments
 (0)