Skip to content

Commit b07cab1

Browse files
authored
fix(test): update decompress: false test to match actual parsing behavior (#359)
1 parent 6336520 commit b07cab1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/routes-decompress.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,31 @@ describe('When using routes `decompress` settings :', async () => {
182182
})
183183
equal(usedCustomGlobal, false)
184184

185+
equal(response.statusCode, 400)
186+
t.assert.match(response.json().message, /is not valid JSON/)
187+
})
188+
189+
test('it should return FST_ERR_CTP_INVALID_CONTENT_LENGTH when Content-Length mismatches payload', async (t) => {
190+
t.plan(2)
191+
const equal = t.assert.equal
192+
193+
const fastify = Fastify()
194+
await fastify.register(compressPlugin)
195+
196+
fastify.post('/length', (request, reply) => {
197+
reply.send({ ok: true })
198+
})
199+
200+
const response = await fastify.inject({
201+
url: '/length',
202+
method: 'POST',
203+
headers: {
204+
'content-type': 'application/json',
205+
'content-length': '100',
206+
},
207+
payload: JSON.stringify({ hello: 'world' })
208+
})
209+
185210
equal(response.statusCode, 400)
186211
t.assert.deepEqual(response.json(), {
187212
statusCode: 400,

0 commit comments

Comments
 (0)