diff --git a/src/services/fastifyUtils.spec.ts b/src/services/fastifyUtils.spec.ts index ae29a4c6f..8149bd4f3 100644 --- a/src/services/fastifyUtils.spec.ts +++ b/src/services/fastifyUtils.spec.ts @@ -5,6 +5,7 @@ import pino from 'pino'; import { mockSpy } from '../_test_utils'; import { configureMockEnvVars, getMockContext, getMockInstance } from './_test_utils'; +import { MAX_RAMF_MESSAGE_SIZE } from './constants'; import { configureFastify, runFastify } from './fastifyUtils'; const mockFastify: FastifyInstance = { @@ -61,6 +62,20 @@ describe('configureFastify', () => { expect(fastifyCallArgs[0]).toHaveProperty('requestIdHeader', requestIdHeader.toLowerCase()); }); + test('Maximum request body should allow for the largest RAMF message', () => { + configureFastify([dummyRoutes]); + + const fastifyCallArgs = getMockContext(fastify).calls[0]; + expect(fastifyCallArgs[0]).toHaveProperty('bodyLimit', MAX_RAMF_MESSAGE_SIZE); + }); + + test('Proxy request headers should be trusted', () => { + configureFastify([dummyRoutes]); + + const fastifyCallArgs = getMockContext(fastify).calls[0]; + expect(fastifyCallArgs[0]).toHaveProperty('trustProxy', true); + }); + test('Routes should be loaded', async () => { await configureFastify([dummyRoutes]); diff --git a/src/services/fastifyUtils.ts b/src/services/fastifyUtils.ts index 847fa74a3..5e1aa4469 100644 --- a/src/services/fastifyUtils.ts +++ b/src/services/fastifyUtils.ts @@ -8,6 +8,7 @@ import { HTTPMethods, } from 'fastify'; import { Logger } from 'pino'; +import { MAX_RAMF_MESSAGE_SIZE } from './constants'; const DEFAULT_REQUEST_ID_HEADER = 'X-Request-Id'; const SERVER_PORT = 8080; @@ -55,11 +56,13 @@ export async function configureFastify { const server = fastify({ + bodyLimit: MAX_RAMF_MESSAGE_SIZE, logger, requestIdHeader: getEnvVar('REQUEST_ID_HEADER') .default(DEFAULT_REQUEST_ID_HEADER) .asString() .toLowerCase(), + trustProxy: true, }); await Promise.all(routes.map((route) => server.register(route, routeOptions)));