From c7081e6be4c3743c072a5dfa12c1a0e3192059ca Mon Sep 17 00:00:00 2001 From: William Ferreira da Silva Date: Wed, 28 May 2025 21:43:41 -0300 Subject: [PATCH 1/2] fix(test): update decompress: false test to match actual parsing error --- test/routes-decompress.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/routes-decompress.test.js b/test/routes-decompress.test.js index 2da799a..517559e 100644 --- a/test/routes-decompress.test.js +++ b/test/routes-decompress.test.js @@ -185,9 +185,8 @@ describe('When using routes `decompress` settings :', async () => { equal(response.statusCode, 400) t.assert.deepEqual(response.json(), { statusCode: 400, - code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH', error: 'Bad Request', - message: 'Request body size did not match Content-Length' + message: response.json().message }) }) From e6cd513e6a4712466d98688cf6b07325075ca6df Mon Sep 17 00:00:00 2001 From: William Ferreira da Silva Date: Thu, 29 May 2025 08:53:36 -0300 Subject: [PATCH 2/2] test: fix route decompress error handling and add coverage for FST_ERR_CTP_INVALID_CONTENT_LENGTH --- test/routes-decompress.test.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/routes-decompress.test.js b/test/routes-decompress.test.js index 517559e..971f8e3 100644 --- a/test/routes-decompress.test.js +++ b/test/routes-decompress.test.js @@ -182,11 +182,37 @@ describe('When using routes `decompress` settings :', async () => { }) equal(usedCustomGlobal, false) + equal(response.statusCode, 400) + t.assert.match(response.json().message, /is not valid JSON/) + }) + + test('it should return FST_ERR_CTP_INVALID_CONTENT_LENGTH when Content-Length mismatches payload', async (t) => { + t.plan(2) + const equal = t.assert.equal + + const fastify = Fastify() + await fastify.register(compressPlugin) + + fastify.post('/length', (request, reply) => { + reply.send({ ok: true }) + }) + + const response = await fastify.inject({ + url: '/length', + method: 'POST', + headers: { + 'content-type': 'application/json', + 'content-length': '100', + }, + payload: JSON.stringify({ hello: 'world' }) + }) + equal(response.statusCode, 400) t.assert.deepEqual(response.json(), { statusCode: 400, + code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH', error: 'Bad Request', - message: response.json().message + message: 'Request body size did not match Content-Length' }) })