Aktueller Stand
This commit is contained in:
121
backend/node_modules/fastify/test/content-length.test.js
generated
vendored
121
backend/node_modules/fastify/test/content-length.test.js
generated
vendored
@@ -1,11 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const Fastify = require('..')
|
||||
|
||||
test('default 413 with bodyLimit option', t => {
|
||||
t.plan(4)
|
||||
test('default 413 with bodyLimit option', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const fastify = Fastify({
|
||||
bodyLimit: 10
|
||||
@@ -15,27 +14,25 @@ test('default 413 with bodyLimit option', t => {
|
||||
reply.send({ hello: 'world' })
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'POST',
|
||||
url: '/',
|
||||
body: {
|
||||
text: '12345678901234567890123456789012345678901234567890'
|
||||
}
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 413)
|
||||
t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.same(JSON.parse(res.payload), {
|
||||
error: 'Payload Too Large',
|
||||
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
||||
message: 'Request body is too large',
|
||||
statusCode: 413
|
||||
})
|
||||
})
|
||||
t.assert.strictEqual(response.statusCode, 413)
|
||||
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
||||
error: 'Payload Too Large',
|
||||
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
||||
message: 'Request body is too large',
|
||||
statusCode: 413
|
||||
})
|
||||
})
|
||||
|
||||
test('default 400 with wrong content-length', t => {
|
||||
t.plan(4)
|
||||
test('default 400 with wrong content-length', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -43,7 +40,7 @@ test('default 400 with wrong content-length', t => {
|
||||
reply.send({ hello: 'world' })
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'POST',
|
||||
url: '/',
|
||||
headers: {
|
||||
@@ -52,21 +49,19 @@ test('default 400 with wrong content-length', t => {
|
||||
body: {
|
||||
text: '12345678901234567890123456789012345678901234567890'
|
||||
}
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 400)
|
||||
t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.same(JSON.parse(res.payload), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
|
||||
message: 'Request body size did not match Content-Length',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
t.assert.strictEqual(response.statusCode, 400)
|
||||
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
|
||||
message: 'Request body size did not match Content-Length',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
|
||||
test('custom 413 with bodyLimit option', t => {
|
||||
t.plan(4)
|
||||
test('custom 413 with bodyLimit option', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const fastify = Fastify({
|
||||
bodyLimit: 10
|
||||
@@ -83,27 +78,25 @@ test('custom 413 with bodyLimit option', t => {
|
||||
.send(err)
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'POST',
|
||||
url: '/',
|
||||
body: {
|
||||
text: '12345678901234567890123456789012345678901234567890'
|
||||
}
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 413)
|
||||
t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.same(JSON.parse(res.payload), {
|
||||
error: 'Payload Too Large',
|
||||
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
||||
message: 'Request body is too large',
|
||||
statusCode: 413
|
||||
})
|
||||
})
|
||||
t.assert.strictEqual(response.statusCode, 413)
|
||||
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
||||
error: 'Payload Too Large',
|
||||
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
||||
message: 'Request body is too large',
|
||||
statusCode: 413
|
||||
})
|
||||
})
|
||||
|
||||
test('custom 400 with wrong content-length', t => {
|
||||
t.plan(4)
|
||||
test('custom 400 with wrong content-length', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -118,7 +111,7 @@ test('custom 400 with wrong content-length', t => {
|
||||
.send(err)
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'POST',
|
||||
url: '/',
|
||||
headers: {
|
||||
@@ -127,20 +120,18 @@ test('custom 400 with wrong content-length', t => {
|
||||
body: {
|
||||
text: '12345678901234567890123456789012345678901234567890'
|
||||
}
|
||||
}, (err, res) => {
|
||||
t.error(err)
|
||||
t.equal(res.statusCode, 400)
|
||||
t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.same(JSON.parse(res.payload), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
|
||||
message: 'Request body size did not match Content-Length',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
t.assert.strictEqual(response.statusCode, 400)
|
||||
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
||||
error: 'Bad Request',
|
||||
code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH',
|
||||
message: 'Request body size did not match Content-Length',
|
||||
statusCode: 400
|
||||
})
|
||||
})
|
||||
|
||||
test('#2214 - wrong content-length', t => {
|
||||
test('#2214 - wrong content-length', async (t) => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.get('/', async () => {
|
||||
@@ -151,17 +142,14 @@ test('#2214 - wrong content-length', t => {
|
||||
throw error
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'GET',
|
||||
path: '/'
|
||||
})
|
||||
.then(response => {
|
||||
t.equal(response.headers['content-length'], '' + response.rawPayload.length)
|
||||
t.end()
|
||||
})
|
||||
t.assert.strictEqual(response.headers['content-length'], '' + response.rawPayload.length)
|
||||
})
|
||||
|
||||
test('#2543 - wrong content-length with errorHandler', t => {
|
||||
test('#2543 - wrong content-length with errorHandler', async (t) => {
|
||||
const fastify = Fastify()
|
||||
|
||||
fastify.setErrorHandler((_error, _request, reply) => {
|
||||
@@ -176,14 +164,11 @@ test('#2543 - wrong content-length with errorHandler', t => {
|
||||
throw error
|
||||
})
|
||||
|
||||
fastify.inject({
|
||||
const response = await fastify.inject({
|
||||
method: 'GET',
|
||||
path: '/'
|
||||
})
|
||||
.then(res => {
|
||||
t.equal(res.statusCode, 500)
|
||||
t.equal(res.headers['content-length'], '' + res.rawPayload.length)
|
||||
t.same(JSON.parse(res.payload), { message: 'longer than 2 bytes' })
|
||||
t.end()
|
||||
})
|
||||
t.assert.strictEqual(response.statusCode, 500)
|
||||
t.assert.strictEqual(response.headers['content-length'], '' + response.rawPayload.length)
|
||||
t.assert.deepStrictEqual(JSON.parse(response.payload), { message: 'longer than 2 bytes' })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user