fastify 5.3.2 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/build-validation.js +2 -1
- package/docs/Guides/Delay-Accepting-Requests.md +3 -3
- package/docs/Guides/Ecosystem.md +16 -7
- package/docs/Guides/Serverless.md +28 -69
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +2 -4
- package/docs/Reference/Hooks.md +14 -14
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +3 -3
- package/docs/Reference/Server.md +40 -10
- package/docs/Reference/Validation-and-Serialization.md +1 -1
- package/eslint.config.js +17 -9
- package/fastify.d.ts +2 -1
- package/fastify.js +20 -4
- package/lib/configValidator.js +1 -1
- package/lib/decorate.js +2 -2
- package/lib/errors.js +6 -8
- package/lib/logger-factory.js +1 -1
- package/lib/logger-pino.js +2 -2
- package/lib/pluginOverride.js +3 -1
- package/lib/reply.js +9 -13
- package/lib/request.js +4 -11
- package/lib/server.js +30 -51
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +8 -0
- package/package.json +11 -7
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +11 -2
- package/test/body-limit.test.js +41 -65
- package/test/build-certificate.js +1 -1
- package/test/close-pipelining.test.js +5 -4
- package/test/custom-parser-async.test.js +17 -22
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +422 -341
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/helper.js +108 -70
- package/test/hooks-async.test.js +248 -218
- package/test/hooks.on-listen.test.js +255 -239
- package/test/hooks.on-ready.test.js +110 -92
- package/test/hooks.test.js +910 -769
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +28 -27
- package/test/https/https.test.js +56 -53
- package/test/inject.test.js +114 -97
- package/test/input-validation.js +63 -53
- package/test/internals/errors.test.js +0 -10
- package/test/internals/handle-request.test.js +49 -66
- package/test/internals/hooks.test.js +17 -0
- package/test/issue-4959.test.js +14 -5
- package/test/listen.4.test.js +31 -43
- package/test/logger/response.test.js +19 -20
- package/test/nullable-validation.test.js +33 -46
- package/test/options.error-handler.test.js +1 -1
- package/test/options.test.js +1 -1
- package/test/output-validation.test.js +49 -72
- package/test/patch.error-handler.test.js +1 -1
- package/test/patch.test.js +1 -1
- package/test/plugin.1.test.js +71 -60
- package/test/plugin.2.test.js +104 -86
- package/test/plugin.3.test.js +56 -35
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +36 -30
- package/test/proto-poisoning.test.js +78 -97
- package/test/put.error-handler.test.js +1 -1
- package/test/put.test.js +1 -1
- package/test/reply-error.test.js +169 -148
- package/test/reply-trailers.test.js +119 -108
- package/test/request-error.test.js +0 -46
- package/test/route-hooks.test.js +112 -92
- package/test/route-prefix.test.js +194 -133
- package/test/schema-feature.test.js +309 -238
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +278 -199
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +30 -27
- package/test/stream.2.test.js +20 -10
- package/test/stream.3.test.js +37 -31
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +0 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/plugin.test-d.ts +1 -1
- package/test/types/register.test-d.ts +1 -1
- package/test/types/request.test-d.ts +1 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +1 -1
- package/types/errors.d.ts +0 -1
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
- package/test/http2/missing-http2-module.test.js +0 -17
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const diagnostics = require('node:diagnostics_channel')
|
|
4
4
|
const { test } = require('node:test')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel async events fire in expected order',
|
|
9
|
+
test('diagnostics channel async events fire in expected order', async t => {
|
|
12
10
|
t.plan(19)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -56,19 +54,12 @@ test('diagnostics channel async events fire in expected order', (t, done) => {
|
|
|
56
54
|
}
|
|
57
55
|
})
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
if (err) t.assert.ifError(err)
|
|
57
|
+
t.after(() => { fastify.close() })
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
t.assert.ifError(err)
|
|
69
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
70
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
71
|
-
done()
|
|
72
|
-
})
|
|
73
|
-
})
|
|
61
|
+
const result = await fetch(fastifyServer + '/')
|
|
62
|
+
t.assert.ok(result.ok)
|
|
63
|
+
t.assert.strictEqual(result.status, 200)
|
|
64
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
74
65
|
})
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
4
|
const diagnostics = require('node:diagnostics_channel')
|
|
5
|
-
const sget = require('simple-get').concat
|
|
6
5
|
const Fastify = require('../..')
|
|
7
|
-
const { getServerUrl } = require('../helper')
|
|
8
6
|
const Request = require('../../lib/request')
|
|
9
7
|
const Reply = require('../../lib/reply')
|
|
10
8
|
|
|
11
|
-
test('diagnostics channel sync events fire in expected order',
|
|
9
|
+
test('diagnostics channel sync events fire in expected order', async t => {
|
|
12
10
|
t.plan(10)
|
|
13
11
|
let callOrder = 0
|
|
14
12
|
let firstEncounteredMessage
|
|
@@ -40,19 +38,12 @@ test('diagnostics channel sync events fire in expected order', (t, done) => {
|
|
|
40
38
|
}
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
if (err) t.assert.ifError(err)
|
|
41
|
+
t.after(() => { fastify.close() })
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
t.assert.ifError(err)
|
|
53
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
54
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
55
|
-
done()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
45
|
+
const result = await fetch(fastifyServer + '/')
|
|
46
|
+
t.assert.ok(result.ok)
|
|
47
|
+
t.assert.strictEqual(result.status, 200)
|
|
48
|
+
t.assert.deepStrictEqual(await result.json(), { hello: 'world' })
|
|
58
49
|
})
|
package/test/helper.js
CHANGED
|
@@ -5,12 +5,14 @@ const dns = require('node:dns').promises
|
|
|
5
5
|
const stream = require('node:stream')
|
|
6
6
|
const { promisify } = require('node:util')
|
|
7
7
|
const symbols = require('../lib/symbols')
|
|
8
|
+
const { waitForCb } = require('./toolkit')
|
|
9
|
+
const assert = require('node:assert')
|
|
8
10
|
|
|
9
11
|
module.exports.sleep = promisify(setTimeout)
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* @param method HTTP request method
|
|
13
|
-
* @param t
|
|
15
|
+
* @param t node:test instance
|
|
14
16
|
* @param isSetErrorHandler true: using setErrorHandler
|
|
15
17
|
*/
|
|
16
18
|
module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
@@ -19,8 +21,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
19
21
|
|
|
20
22
|
if (isSetErrorHandler) {
|
|
21
23
|
fastify.setErrorHandler(function (err, request, reply) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
assert.ok(request instanceof fastify[symbols.kRequest].parent)
|
|
25
|
+
assert.strictEqual(typeof request, 'object')
|
|
24
26
|
reply
|
|
25
27
|
.code(err.statusCode)
|
|
26
28
|
.type('application/json; charset=utf-8')
|
|
@@ -52,9 +54,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
52
54
|
fastify[loMethod]('/', schema, function (req, reply) {
|
|
53
55
|
reply.code(200).send(req.body)
|
|
54
56
|
})
|
|
55
|
-
t.
|
|
57
|
+
t.assert.ok(true)
|
|
56
58
|
} catch (e) {
|
|
57
|
-
t.fail()
|
|
59
|
+
t.assert.fail()
|
|
58
60
|
}
|
|
59
61
|
})
|
|
60
62
|
|
|
@@ -64,9 +66,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
64
66
|
fastify[loMethod]('/missing', function (req, reply) {
|
|
65
67
|
reply.code(200).send(req.body)
|
|
66
68
|
})
|
|
67
|
-
t.
|
|
69
|
+
t.assert.ok(true)
|
|
68
70
|
} catch (e) {
|
|
69
|
-
t.fail()
|
|
71
|
+
t.assert.fail()
|
|
70
72
|
}
|
|
71
73
|
})
|
|
72
74
|
|
|
@@ -77,9 +79,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
77
79
|
req.body.hello = req.body.hello + req.query.foo
|
|
78
80
|
reply.code(200).send(req.body)
|
|
79
81
|
})
|
|
80
|
-
t.
|
|
82
|
+
t.assert.ok(true)
|
|
81
83
|
} catch (e) {
|
|
82
|
-
t.fail()
|
|
84
|
+
t.assert.fail()
|
|
83
85
|
}
|
|
84
86
|
})
|
|
85
87
|
|
|
@@ -89,21 +91,21 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
89
91
|
fastify[loMethod]('/with-limit', { bodyLimit: 1 }, function (req, reply) {
|
|
90
92
|
reply.send(req.body)
|
|
91
93
|
})
|
|
92
|
-
t.
|
|
94
|
+
t.assert.ok(true)
|
|
93
95
|
} catch (e) {
|
|
94
|
-
t.fail()
|
|
96
|
+
t.assert.fail()
|
|
95
97
|
}
|
|
96
98
|
})
|
|
97
99
|
|
|
98
100
|
fastify.listen({ port: 0 }, function (err) {
|
|
99
101
|
if (err) {
|
|
100
|
-
t.
|
|
102
|
+
t.assert.ifError(err)
|
|
101
103
|
return
|
|
102
104
|
}
|
|
103
105
|
|
|
104
|
-
t.
|
|
106
|
+
t.after(() => { fastify.close() })
|
|
105
107
|
|
|
106
|
-
test(`${upMethod} - correctly replies`, t => {
|
|
108
|
+
test(`${upMethod} - correctly replies`, (t, testDone) => {
|
|
107
109
|
t.plan(3)
|
|
108
110
|
sget({
|
|
109
111
|
method: upMethod,
|
|
@@ -113,13 +115,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
113
115
|
},
|
|
114
116
|
json: true
|
|
115
117
|
}, (err, response, body) => {
|
|
116
|
-
t.
|
|
117
|
-
t.
|
|
118
|
-
t.
|
|
118
|
+
t.assert.ifError(err)
|
|
119
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
120
|
+
t.assert.deepStrictEqual(body, { hello: 'world' })
|
|
121
|
+
testDone()
|
|
119
122
|
})
|
|
120
123
|
})
|
|
121
124
|
|
|
122
|
-
test(`${upMethod} - correctly replies with very large body`, t => {
|
|
125
|
+
test(`${upMethod} - correctly replies with very large body`, (t, testDone) => {
|
|
123
126
|
t.plan(3)
|
|
124
127
|
|
|
125
128
|
const largeString = 'world'.repeat(13200)
|
|
@@ -129,13 +132,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
129
132
|
body: { hello: largeString },
|
|
130
133
|
json: true
|
|
131
134
|
}, (err, response, body) => {
|
|
132
|
-
t.
|
|
133
|
-
t.
|
|
134
|
-
t.
|
|
135
|
+
t.assert.ifError(err)
|
|
136
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
137
|
+
t.assert.deepStrictEqual(body, { hello: largeString })
|
|
138
|
+
testDone()
|
|
135
139
|
})
|
|
136
140
|
})
|
|
137
141
|
|
|
138
|
-
test(`${upMethod} - correctly replies if the content type has the charset`, t => {
|
|
142
|
+
test(`${upMethod} - correctly replies if the content type has the charset`, (t, testDone) => {
|
|
139
143
|
t.plan(3)
|
|
140
144
|
sget({
|
|
141
145
|
method: upMethod,
|
|
@@ -145,13 +149,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
145
149
|
'content-type': 'application/json; charset=utf-8'
|
|
146
150
|
}
|
|
147
151
|
}, (err, response, body) => {
|
|
148
|
-
t.
|
|
149
|
-
t.
|
|
150
|
-
t.
|
|
152
|
+
t.assert.ifError(err)
|
|
153
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
154
|
+
t.assert.deepStrictEqual(body.toString(), JSON.stringify({ hello: 'world' }))
|
|
155
|
+
testDone()
|
|
151
156
|
})
|
|
152
157
|
})
|
|
153
158
|
|
|
154
|
-
test(`${upMethod} without schema - correctly replies`, t => {
|
|
159
|
+
test(`${upMethod} without schema - correctly replies`, (t, testDone) => {
|
|
155
160
|
t.plan(3)
|
|
156
161
|
sget({
|
|
157
162
|
method: upMethod,
|
|
@@ -161,13 +166,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
161
166
|
},
|
|
162
167
|
json: true
|
|
163
168
|
}, (err, response, body) => {
|
|
164
|
-
t.
|
|
165
|
-
t.
|
|
166
|
-
t.
|
|
169
|
+
t.assert.ifError(err)
|
|
170
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
171
|
+
t.assert.deepStrictEqual(body, { hello: 'world' })
|
|
172
|
+
testDone()
|
|
167
173
|
})
|
|
168
174
|
})
|
|
169
175
|
|
|
170
|
-
test(`${upMethod} with body and querystring - correctly replies`, t => {
|
|
176
|
+
test(`${upMethod} with body and querystring - correctly replies`, (t, testDone) => {
|
|
171
177
|
t.plan(3)
|
|
172
178
|
sget({
|
|
173
179
|
method: upMethod,
|
|
@@ -177,23 +183,27 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
177
183
|
},
|
|
178
184
|
json: true
|
|
179
185
|
}, (err, response, body) => {
|
|
180
|
-
t.
|
|
181
|
-
t.
|
|
182
|
-
t.
|
|
186
|
+
t.assert.ifError(err)
|
|
187
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
188
|
+
t.assert.deepStrictEqual(body, { hello: 'worldhello' })
|
|
189
|
+
testDone()
|
|
183
190
|
})
|
|
184
191
|
})
|
|
185
192
|
|
|
186
193
|
test(`${upMethod} with no body - correctly replies`, t => {
|
|
187
194
|
t.plan(6)
|
|
188
195
|
|
|
196
|
+
const { stepIn, patience } = waitForCb({ steps: 2 })
|
|
197
|
+
|
|
189
198
|
sget({
|
|
190
199
|
method: upMethod,
|
|
191
200
|
url: 'http://localhost:' + fastify.server.address().port + '/missing',
|
|
192
201
|
headers: { 'Content-Length': '0' }
|
|
193
202
|
}, (err, response, body) => {
|
|
194
|
-
t.
|
|
195
|
-
t.
|
|
196
|
-
t.
|
|
203
|
+
t.assert.ifError(err)
|
|
204
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
205
|
+
t.assert.strictEqual(body.toString(), '')
|
|
206
|
+
stepIn()
|
|
197
207
|
})
|
|
198
208
|
|
|
199
209
|
// Must use inject to make a request without a Content-Length header
|
|
@@ -201,13 +211,16 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
201
211
|
method: upMethod,
|
|
202
212
|
url: '/missing'
|
|
203
213
|
}, (err, res) => {
|
|
204
|
-
t.
|
|
205
|
-
t.
|
|
206
|
-
t.
|
|
214
|
+
t.assert.ifError(err)
|
|
215
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
216
|
+
t.assert.strictEqual(res.payload.toString(), '')
|
|
217
|
+
stepIn()
|
|
207
218
|
})
|
|
219
|
+
|
|
220
|
+
return patience
|
|
208
221
|
})
|
|
209
222
|
|
|
210
|
-
test(`${upMethod} returns 415 - incorrect media type if body is not json`, t => {
|
|
223
|
+
test(`${upMethod} returns 415 - incorrect media type if body is not json`, (t, testDone) => {
|
|
211
224
|
t.plan(2)
|
|
212
225
|
sget({
|
|
213
226
|
method: upMethod,
|
|
@@ -215,13 +228,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
215
228
|
body: 'hello world'
|
|
216
229
|
|
|
217
230
|
}, (err, response, body) => {
|
|
218
|
-
t.
|
|
219
|
-
t.
|
|
231
|
+
t.assert.ifError(err)
|
|
232
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
233
|
+
testDone()
|
|
220
234
|
})
|
|
221
235
|
})
|
|
222
236
|
|
|
223
237
|
if (loMethod === 'options') {
|
|
224
|
-
test('OPTIONS returns 415 - should return 415 if Content-Type is not json or plain text', t => {
|
|
238
|
+
test('OPTIONS returns 415 - should return 415 if Content-Type is not json or plain text', (t, testDone) => {
|
|
225
239
|
t.plan(2)
|
|
226
240
|
sget({
|
|
227
241
|
method: upMethod,
|
|
@@ -231,8 +245,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
231
245
|
'Content-Type': 'text/xml'
|
|
232
246
|
}
|
|
233
247
|
}, (err, response, body) => {
|
|
234
|
-
t.
|
|
235
|
-
t.
|
|
248
|
+
t.assert.ifError(err)
|
|
249
|
+
t.assert.strictEqual(response.statusCode, 415)
|
|
250
|
+
testDone()
|
|
236
251
|
})
|
|
237
252
|
})
|
|
238
253
|
}
|
|
@@ -240,6 +255,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
240
255
|
test(`${upMethod} returns 400 - Bad Request`, t => {
|
|
241
256
|
t.plan(4)
|
|
242
257
|
|
|
258
|
+
const { stepIn, patience } = waitForCb({ steps: 2 })
|
|
259
|
+
|
|
243
260
|
sget({
|
|
244
261
|
method: upMethod,
|
|
245
262
|
url: 'http://localhost:' + fastify.server.address().port,
|
|
@@ -248,8 +265,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
248
265
|
'Content-Type': 'application/json'
|
|
249
266
|
}
|
|
250
267
|
}, (err, response, body) => {
|
|
251
|
-
t.
|
|
252
|
-
t.
|
|
268
|
+
t.assert.ifError(err)
|
|
269
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
270
|
+
stepIn()
|
|
253
271
|
})
|
|
254
272
|
|
|
255
273
|
sget({
|
|
@@ -260,13 +278,19 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
260
278
|
'Content-Length': '0'
|
|
261
279
|
}
|
|
262
280
|
}, (err, response, body) => {
|
|
263
|
-
t.
|
|
264
|
-
t.
|
|
281
|
+
t.assert.ifError(err)
|
|
282
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
283
|
+
stepIn()
|
|
265
284
|
})
|
|
285
|
+
|
|
286
|
+
return patience
|
|
266
287
|
})
|
|
267
288
|
|
|
268
289
|
test(`${upMethod} returns 413 - Payload Too Large`, t => {
|
|
269
|
-
|
|
290
|
+
const isOptions = upMethod === 'OPTIONS'
|
|
291
|
+
t.plan(isOptions ? 4 : 6)
|
|
292
|
+
|
|
293
|
+
const { stepIn, patience } = waitForCb({ steps: isOptions ? 2 : 3 })
|
|
270
294
|
|
|
271
295
|
sget({
|
|
272
296
|
method: upMethod,
|
|
@@ -276,12 +300,13 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
276
300
|
'Content-Length': 1024 * 1024 + 1
|
|
277
301
|
}
|
|
278
302
|
}, (err, response, body) => {
|
|
279
|
-
t.
|
|
280
|
-
t.
|
|
303
|
+
t.assert.ifError(err)
|
|
304
|
+
t.assert.strictEqual(response.statusCode, 413)
|
|
305
|
+
stepIn()
|
|
281
306
|
})
|
|
282
307
|
|
|
283
308
|
// Node errors for OPTIONS requests with a stream body and no Content-Length header
|
|
284
|
-
if (
|
|
309
|
+
if (!isOptions) {
|
|
285
310
|
let chunk = Buffer.alloc(1024 * 1024 + 1, 0)
|
|
286
311
|
const largeStream = new stream.Readable({
|
|
287
312
|
read () {
|
|
@@ -295,8 +320,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
295
320
|
headers: { 'Content-Type': 'application/json' },
|
|
296
321
|
body: largeStream
|
|
297
322
|
}, (err, response, body) => {
|
|
298
|
-
t.
|
|
299
|
-
t.
|
|
323
|
+
t.assert.ifError(err)
|
|
324
|
+
t.assert.strictEqual(response.statusCode, 413)
|
|
325
|
+
stepIn()
|
|
300
326
|
})
|
|
301
327
|
}
|
|
302
328
|
|
|
@@ -307,16 +333,21 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
307
333
|
body: {},
|
|
308
334
|
json: true
|
|
309
335
|
}, (err, response, body) => {
|
|
310
|
-
t.
|
|
311
|
-
t.
|
|
336
|
+
t.assert.ifError(err)
|
|
337
|
+
t.assert.strictEqual(response.statusCode, 413)
|
|
338
|
+
stepIn()
|
|
312
339
|
})
|
|
340
|
+
|
|
341
|
+
return patience
|
|
313
342
|
})
|
|
314
343
|
|
|
315
344
|
test(`${upMethod} should fail with empty body and application/json content-type`, t => {
|
|
316
|
-
if (upMethod === 'OPTIONS') return
|
|
345
|
+
if (upMethod === 'OPTIONS') return
|
|
317
346
|
|
|
318
347
|
t.plan(12)
|
|
319
348
|
|
|
349
|
+
const { stepIn, patience } = waitForCb({ steps: 5 })
|
|
350
|
+
|
|
320
351
|
fastify.inject({
|
|
321
352
|
method: `${upMethod}`,
|
|
322
353
|
url: '/',
|
|
@@ -324,8 +355,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
324
355
|
'Content-Type': 'application/json'
|
|
325
356
|
}
|
|
326
357
|
}, (err, res) => {
|
|
327
|
-
t.
|
|
328
|
-
t.
|
|
358
|
+
t.assert.ifError(err)
|
|
359
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
329
360
|
error: 'Bad Request',
|
|
330
361
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
331
362
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
@@ -340,13 +371,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
340
371
|
'Content-Type': 'application/json'
|
|
341
372
|
}
|
|
342
373
|
}, (err, res, body) => {
|
|
343
|
-
t.
|
|
344
|
-
t.
|
|
374
|
+
t.assert.ifError(err)
|
|
375
|
+
t.assert.deepStrictEqual(JSON.parse(body.toString()), {
|
|
345
376
|
error: 'Bad Request',
|
|
346
377
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
347
378
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
348
379
|
statusCode: 400
|
|
349
380
|
})
|
|
381
|
+
stepIn()
|
|
350
382
|
})
|
|
351
383
|
|
|
352
384
|
fastify.inject({
|
|
@@ -357,13 +389,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
357
389
|
},
|
|
358
390
|
payload: null
|
|
359
391
|
}, (err, res) => {
|
|
360
|
-
t.
|
|
361
|
-
t.
|
|
392
|
+
t.assert.ifError(err)
|
|
393
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
362
394
|
error: 'Bad Request',
|
|
363
395
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
364
396
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
365
397
|
statusCode: 400
|
|
366
398
|
})
|
|
399
|
+
stepIn()
|
|
367
400
|
})
|
|
368
401
|
|
|
369
402
|
sget({
|
|
@@ -374,13 +407,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
374
407
|
},
|
|
375
408
|
payload: null
|
|
376
409
|
}, (err, res, body) => {
|
|
377
|
-
t.
|
|
378
|
-
t.
|
|
410
|
+
t.assert.ifError(err)
|
|
411
|
+
t.assert.deepStrictEqual(JSON.parse(body.toString()), {
|
|
379
412
|
error: 'Bad Request',
|
|
380
413
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
381
414
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
382
415
|
statusCode: 400
|
|
383
416
|
})
|
|
417
|
+
stepIn()
|
|
384
418
|
})
|
|
385
419
|
|
|
386
420
|
fastify.inject({
|
|
@@ -391,13 +425,14 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
391
425
|
},
|
|
392
426
|
payload: undefined
|
|
393
427
|
}, (err, res) => {
|
|
394
|
-
t.
|
|
395
|
-
t.
|
|
428
|
+
t.assert.ifError(err)
|
|
429
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
396
430
|
error: 'Bad Request',
|
|
397
431
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
398
432
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
399
433
|
statusCode: 400
|
|
400
434
|
})
|
|
435
|
+
stepIn()
|
|
401
436
|
})
|
|
402
437
|
|
|
403
438
|
sget({
|
|
@@ -408,14 +443,17 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) {
|
|
|
408
443
|
},
|
|
409
444
|
payload: undefined
|
|
410
445
|
}, (err, res, body) => {
|
|
411
|
-
t.
|
|
412
|
-
t.
|
|
446
|
+
t.assert.ifError(err)
|
|
447
|
+
t.assert.deepStrictEqual(JSON.parse(body.toString()), {
|
|
413
448
|
error: 'Bad Request',
|
|
414
449
|
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
|
|
415
450
|
message: 'Body cannot be empty when content-type is set to \'application/json\'',
|
|
416
451
|
statusCode: 400
|
|
417
452
|
})
|
|
453
|
+
stepIn()
|
|
418
454
|
})
|
|
455
|
+
|
|
456
|
+
return patience
|
|
419
457
|
})
|
|
420
458
|
})
|
|
421
459
|
}
|