fastify 5.0.0 → 5.2.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/.borp.yaml +3 -0
- package/.vscode/settings.json +22 -0
- package/README.md +12 -7
- package/docs/Guides/Database.md +15 -15
- package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
- package/docs/Guides/Ecosystem.md +14 -15
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +133 -9
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Recommendations.md +9 -9
- package/docs/Guides/Serverless.md +5 -5
- package/docs/Guides/Testing.md +58 -57
- package/docs/Guides/Write-Plugin.md +2 -2
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/ContentTypeParser.md +4 -4
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +3 -3
- package/docs/Reference/Hooks.md +7 -7
- package/docs/Reference/LTS.md +8 -0
- package/docs/Reference/Logging.md +5 -4
- package/docs/Reference/Reply.md +55 -58
- package/docs/Reference/Request.md +49 -42
- package/docs/Reference/Routes.md +16 -13
- package/docs/Reference/Server.md +32 -28
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +5 -5
- package/examples/typescript-server.ts +1 -1
- package/fastify.d.ts +14 -5
- package/fastify.js +8 -6
- package/lib/contentTypeParser.js +9 -7
- package/lib/context.js +1 -2
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +1 -1
- package/lib/fourOhFour.js +1 -1
- package/lib/hooks.js +4 -1
- package/lib/{logger.js → logger-factory.js} +70 -122
- package/lib/logger-pino.js +68 -0
- package/lib/pluginOverride.js +1 -1
- package/lib/pluginUtils.js +2 -2
- package/lib/reply.js +4 -5
- package/lib/request.js +16 -9
- package/lib/route.js +23 -22
- package/lib/validation.js +2 -2
- package/package.json +13 -15
- package/test/404s.test.js +675 -629
- package/test/500s.test.js +72 -63
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +30 -26
- package/test/als.test.js +48 -45
- package/test/async-await.test.js +148 -134
- package/test/async-dispose.test.js +4 -5
- package/test/async_hooks.test.js +30 -28
- package/test/{bodyLimit.test.js → body-limit.test.js} +61 -58
- package/test/buffer.test.js +9 -10
- package/test/build/error-serializer.test.js +3 -4
- package/test/build/version.test.js +2 -3
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/bundler/esbuild/bundler-test.js +10 -9
- package/test/bundler/webpack/bundler-test.js +10 -9
- package/test/case-insensitive.test.js +31 -28
- package/test/chainable.test.js +4 -5
- package/test/check.test.js +8 -10
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +56 -19
- package/test/client-timeout.test.js +5 -5
- package/test/close-pipelining.test.js +6 -8
- package/test/conditional-pino.test.js +47 -0
- package/test/{connectionTimeout.test.js → connection-timeout.test.js} +10 -11
- package/test/constrained-routes.test.js +243 -236
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +186 -158
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-http-server.test.js +16 -20
- package/test/custom-parser.5.test.js +32 -32
- package/test/diagnostics-channel/404.test.js +15 -15
- package/test/diagnostics-channel/async-delay-request.test.js +25 -25
- package/test/diagnostics-channel/async-request.test.js +24 -24
- package/test/diagnostics-channel/error-before-handler.test.js +4 -5
- package/test/diagnostics-channel/error-request.test.js +19 -19
- package/test/diagnostics-channel/error-status.test.js +8 -8
- package/test/diagnostics-channel/init.test.js +6 -7
- package/test/diagnostics-channel/sync-delay-request.test.js +16 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +16 -16
- package/test/diagnostics-channel/sync-request.test.js +19 -19
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/esm/errorCodes.test.mjs +5 -5
- package/test/esm/esm.test.mjs +3 -3
- package/test/esm/named-exports.mjs +3 -3
- package/test/esm/other.mjs +2 -2
- package/test/fastify-instance.test.js +33 -34
- package/test/{findRoute.test.js → find-route.test.js} +11 -10
- package/test/fluent-schema.test.js +33 -36
- package/test/handler-context.test.js +11 -11
- package/test/has-route.test.js +12 -15
- package/test/header-overflow.test.js +13 -12
- package/test/hooks.on-ready.test.js +2 -2
- package/test/hooks.test.js +25 -25
- package/test/http-methods/copy.test.js +22 -24
- package/test/http-methods/custom-http-methods.test.js +24 -21
- package/test/http-methods/get.test.js +97 -84
- package/test/http-methods/head.test.js +63 -57
- package/test/http-methods/lock.test.js +21 -20
- package/test/http-methods/mkcalendar.test.js +31 -27
- package/test/http-methods/mkcol.test.js +10 -10
- package/test/http-methods/move.test.js +11 -11
- package/test/http-methods/propfind.test.js +32 -27
- package/test/http-methods/proppatch.test.js +21 -19
- package/test/http-methods/report.test.js +32 -27
- package/test/http-methods/search.test.js +52 -47
- package/test/http-methods/trace.test.js +3 -4
- package/test/http-methods/unlock.test.js +10 -10
- package/test/http2/closing.test.js +50 -58
- package/test/http2/constraint.test.js +47 -50
- package/test/http2/head.test.js +18 -19
- package/test/http2/missing-http2-module.test.js +4 -5
- package/test/http2/plain.test.js +31 -31
- package/test/http2/secure-with-fallback.test.js +61 -61
- package/test/http2/secure.test.js +28 -31
- package/test/http2/unknown-http-method.test.js +13 -14
- package/test/https/custom-https-server.test.js +6 -7
- package/test/https/https.test.js +78 -78
- package/test/imports.test.js +5 -6
- package/test/internals/all.test.js +8 -11
- package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +5 -6
- package/test/internals/context.test.js +9 -11
- package/test/internals/decorator.test.js +20 -21
- package/test/internals/errors.test.js +427 -427
- package/test/internals/{handleRequest.test.js → handle-request.test.js} +53 -42
- package/test/internals/{hookRunner.test.js → hook-runner.test.js} +99 -100
- package/test/internals/hooks.test.js +31 -35
- package/test/internals/{initialConfig.test.js → initial-config.test.js} +92 -80
- package/test/internals/logger.test.js +28 -28
- package/test/internals/plugin.test.js +17 -18
- package/test/internals/reply-serialize.test.js +106 -106
- package/test/internals/reply.test.js +620 -585
- package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +31 -31
- package/test/internals/request-validate.test.js +218 -221
- package/test/internals/request.test.js +225 -107
- package/test/internals/server.test.js +15 -12
- package/test/internals/validation.test.js +35 -36
- package/test/{keepAliveTimeout.test.js → keep-alive-timeout.test.js} +9 -10
- package/test/listen.5.test.js +9 -9
- package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
- package/test/middleware.test.js +4 -5
- package/test/noop-set.test.js +5 -5
- package/test/post-empty-body.test.js +18 -11
- package/test/pretty-print.test.js +59 -49
- package/test/proto-poisoning.test.js +42 -37
- package/test/reply-code.test.js +34 -32
- package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
- package/test/request-error.test.js +122 -0
- package/test/request-header-host.test.js +339 -0
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.1.test.js +79 -72
- package/test/route.2.test.js +17 -16
- package/test/route.3.test.js +32 -27
- package/test/route.4.test.js +21 -25
- package/test/route.5.test.js +45 -64
- package/test/route.6.test.js +70 -89
- package/test/route.7.test.js +61 -65
- package/test/route.8.test.js +80 -18
- package/test/router-options.test.js +80 -77
- package/test/same-shape.test.js +5 -5
- package/test/schema-examples.test.js +72 -38
- package/test/serialize-response.test.js +9 -10
- package/test/server.test.js +75 -78
- package/test/set-error-handler.test.js +2 -3
- package/test/stream-serializers.test.js +10 -7
- package/test/sync-routes.test.js +18 -18
- package/test/test-reporter.mjs +68 -0
- package/test/trust-proxy.test.js +51 -45
- package/test/type-provider.test.js +8 -6
- package/test/types/content-type-parser.test-d.ts +1 -1
- package/test/types/fastify.test-d.ts +16 -4
- package/test/types/hooks.test-d.ts +2 -1
- package/test/types/instance.test-d.ts +13 -13
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +17 -9
- package/test/types/register.test-d.ts +22 -6
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +34 -4
- package/test/types/serverFactory.test-d.ts +1 -1
- package/test/types/type-provider.test-d.ts +1 -1
- package/test/url-rewriting.test.js +35 -38
- package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
- package/test/validation-error-handling.test.js +259 -285
- package/test/versioned-routes.test.js +126 -113
- package/test/web-api.test.js +48 -37
- package/test/{wrapThenable.test.js → wrap-thenable.test.js} +10 -9
- package/types/hooks.d.ts +2 -1
- package/types/instance.d.ts +9 -2
- package/types/register.d.ts +12 -3
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +2 -6
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +13 -5
- package/test/types/import.js +0 -2
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const Fastify = require('..')
|
|
6
5
|
|
|
7
|
-
test('pretty print - static routes', t => {
|
|
6
|
+
test('pretty print - static routes', (t, done) => {
|
|
8
7
|
t.plan(2)
|
|
9
8
|
|
|
10
9
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -22,12 +21,13 @@ test('pretty print - static routes', t => {
|
|
|
22
21
|
└── hello/world (GET)
|
|
23
22
|
`
|
|
24
23
|
|
|
25
|
-
t.
|
|
26
|
-
t.
|
|
24
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
25
|
+
t.assert.strictEqual(tree, expected)
|
|
26
|
+
done()
|
|
27
27
|
})
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
test('pretty print - internal tree - static routes', t => {
|
|
30
|
+
test('pretty print - internal tree - static routes', (t, done) => {
|
|
31
31
|
t.plan(4)
|
|
32
32
|
|
|
33
33
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -47,8 +47,8 @@ test('pretty print - internal tree - static routes', t => {
|
|
|
47
47
|
└── hello/world (GET)
|
|
48
48
|
`
|
|
49
49
|
|
|
50
|
-
t.
|
|
51
|
-
t.
|
|
50
|
+
t.assert.strictEqual(typeof getTree, 'string')
|
|
51
|
+
t.assert.strictEqual(getTree, expectedGetTree)
|
|
52
52
|
|
|
53
53
|
const putTree = fastify.printRoutes({ method: 'PUT' })
|
|
54
54
|
const expectedPutTree = `\
|
|
@@ -57,12 +57,13 @@ test('pretty print - internal tree - static routes', t => {
|
|
|
57
57
|
└── /foo (PUT)
|
|
58
58
|
`
|
|
59
59
|
|
|
60
|
-
t.
|
|
61
|
-
t.
|
|
60
|
+
t.assert.strictEqual(typeof putTree, 'string')
|
|
61
|
+
t.assert.strictEqual(putTree, expectedPutTree)
|
|
62
|
+
done()
|
|
62
63
|
})
|
|
63
64
|
})
|
|
64
65
|
|
|
65
|
-
test('pretty print - parametric routes', t => {
|
|
66
|
+
test('pretty print - parametric routes', (t, done) => {
|
|
66
67
|
t.plan(2)
|
|
67
68
|
|
|
68
69
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -82,12 +83,13 @@ test('pretty print - parametric routes', t => {
|
|
|
82
83
|
└── :world (GET)
|
|
83
84
|
`
|
|
84
85
|
|
|
85
|
-
t.
|
|
86
|
-
t.
|
|
86
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
87
|
+
t.assert.strictEqual(tree, expected)
|
|
88
|
+
done()
|
|
87
89
|
})
|
|
88
90
|
})
|
|
89
91
|
|
|
90
|
-
test('pretty print - internal tree - parametric routes', t => {
|
|
92
|
+
test('pretty print - internal tree - parametric routes', (t, done) => {
|
|
91
93
|
t.plan(4)
|
|
92
94
|
|
|
93
95
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -109,8 +111,8 @@ test('pretty print - internal tree - parametric routes', t => {
|
|
|
109
111
|
└── :world (GET)
|
|
110
112
|
`
|
|
111
113
|
|
|
112
|
-
t.
|
|
113
|
-
t.
|
|
114
|
+
t.assert.strictEqual(typeof getTree, 'string')
|
|
115
|
+
t.assert.strictEqual(getTree, expectedGetTree)
|
|
114
116
|
|
|
115
117
|
const putTree = fastify.printRoutes({ method: 'PUT' })
|
|
116
118
|
const expectedPutTree = `\
|
|
@@ -120,12 +122,13 @@ test('pretty print - internal tree - parametric routes', t => {
|
|
|
120
122
|
└── :hello (PUT)
|
|
121
123
|
`
|
|
122
124
|
|
|
123
|
-
t.
|
|
124
|
-
t.
|
|
125
|
+
t.assert.strictEqual(typeof putTree, 'string')
|
|
126
|
+
t.assert.strictEqual(putTree, expectedPutTree)
|
|
127
|
+
done()
|
|
125
128
|
})
|
|
126
129
|
})
|
|
127
130
|
|
|
128
|
-
test('pretty print - mixed parametric routes', t => {
|
|
131
|
+
test('pretty print - mixed parametric routes', (t, done) => {
|
|
129
132
|
t.plan(2)
|
|
130
133
|
|
|
131
134
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -145,12 +148,13 @@ test('pretty print - mixed parametric routes', t => {
|
|
|
145
148
|
└── /world (GET)
|
|
146
149
|
`
|
|
147
150
|
|
|
148
|
-
t.
|
|
149
|
-
t.
|
|
151
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
152
|
+
t.assert.strictEqual(tree, expected)
|
|
153
|
+
done()
|
|
150
154
|
})
|
|
151
155
|
})
|
|
152
156
|
|
|
153
|
-
test('pretty print - wildcard routes', t => {
|
|
157
|
+
test('pretty print - wildcard routes', (t, done) => {
|
|
154
158
|
t.plan(2)
|
|
155
159
|
|
|
156
160
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -170,12 +174,13 @@ test('pretty print - wildcard routes', t => {
|
|
|
170
174
|
└── * (GET)
|
|
171
175
|
`
|
|
172
176
|
|
|
173
|
-
t.
|
|
174
|
-
t.
|
|
177
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
178
|
+
t.assert.strictEqual(tree, expected)
|
|
179
|
+
done()
|
|
175
180
|
})
|
|
176
181
|
})
|
|
177
182
|
|
|
178
|
-
test('pretty print - internal tree - wildcard routes', t => {
|
|
183
|
+
test('pretty print - internal tree - wildcard routes', (t, done) => {
|
|
179
184
|
t.plan(4)
|
|
180
185
|
|
|
181
186
|
const fastify = Fastify({ exposeHeadRoutes: false })
|
|
@@ -197,8 +202,8 @@ test('pretty print - internal tree - wildcard routes', t => {
|
|
|
197
202
|
└── * (GET)
|
|
198
203
|
`
|
|
199
204
|
|
|
200
|
-
t.
|
|
201
|
-
t.
|
|
205
|
+
t.assert.strictEqual(typeof getTree, 'string')
|
|
206
|
+
t.assert.strictEqual(getTree, expectedGetTree)
|
|
202
207
|
|
|
203
208
|
const putTree = fastify.printRoutes({ method: 'PUT' })
|
|
204
209
|
const expectedPutTree = `\
|
|
@@ -208,23 +213,25 @@ test('pretty print - internal tree - wildcard routes', t => {
|
|
|
208
213
|
└── * (PUT)
|
|
209
214
|
`
|
|
210
215
|
|
|
211
|
-
t.
|
|
212
|
-
t.
|
|
216
|
+
t.assert.strictEqual(typeof putTree, 'string')
|
|
217
|
+
t.assert.strictEqual(putTree, expectedPutTree)
|
|
218
|
+
done()
|
|
213
219
|
})
|
|
214
220
|
})
|
|
215
221
|
|
|
216
|
-
test('pretty print - empty plugins', t => {
|
|
222
|
+
test('pretty print - empty plugins', (t, done) => {
|
|
217
223
|
t.plan(2)
|
|
218
224
|
|
|
219
225
|
const fastify = Fastify()
|
|
220
226
|
fastify.ready(() => {
|
|
221
227
|
const tree = fastify.printPlugins()
|
|
222
|
-
t.
|
|
223
|
-
t.match(tree, /root \d+ ms\n└── bound _after \d+ ms/m)
|
|
228
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
229
|
+
t.assert.match(tree, /root \d+ ms\n└── bound _after \d+ ms/m)
|
|
230
|
+
done()
|
|
224
231
|
})
|
|
225
232
|
})
|
|
226
233
|
|
|
227
|
-
test('pretty print - nested plugins', t => {
|
|
234
|
+
test('pretty print - nested plugins', (t, done) => {
|
|
228
235
|
t.plan(4)
|
|
229
236
|
|
|
230
237
|
const fastify = Fastify()
|
|
@@ -234,14 +241,15 @@ test('pretty print - nested plugins', t => {
|
|
|
234
241
|
})
|
|
235
242
|
fastify.ready(() => {
|
|
236
243
|
const tree = fastify.printPlugins()
|
|
237
|
-
t.
|
|
238
|
-
t.match(tree,
|
|
239
|
-
t.match(tree,
|
|
240
|
-
t.match(tree,
|
|
244
|
+
t.assert.strictEqual(typeof tree, 'string')
|
|
245
|
+
t.assert.match(tree, /foo/)
|
|
246
|
+
t.assert.match(tree, /bar/)
|
|
247
|
+
t.assert.match(tree, /baz/)
|
|
248
|
+
done()
|
|
241
249
|
})
|
|
242
250
|
})
|
|
243
251
|
|
|
244
|
-
test('pretty print - commonPrefix', t => {
|
|
252
|
+
test('pretty print - commonPrefix', (t, done) => {
|
|
245
253
|
t.plan(4)
|
|
246
254
|
|
|
247
255
|
const fastify = Fastify()
|
|
@@ -263,14 +271,15 @@ test('pretty print - commonPrefix', t => {
|
|
|
263
271
|
├── /hello (GET, HEAD, PUT)
|
|
264
272
|
└── /helicopter (GET, HEAD)
|
|
265
273
|
`
|
|
266
|
-
t.
|
|
267
|
-
t.
|
|
268
|
-
t.
|
|
269
|
-
t.
|
|
274
|
+
t.assert.strictEqual(typeof radixTree, 'string')
|
|
275
|
+
t.assert.strictEqual(typeof flatTree, 'string')
|
|
276
|
+
t.assert.strictEqual(radixTree, radixExpected)
|
|
277
|
+
t.assert.strictEqual(flatTree, flatExpected)
|
|
278
|
+
done()
|
|
270
279
|
})
|
|
271
280
|
})
|
|
272
281
|
|
|
273
|
-
test('pretty print - includeMeta, includeHooks', t => {
|
|
282
|
+
test('pretty print - includeMeta, includeHooks', (t, done) => {
|
|
274
283
|
t.plan(6)
|
|
275
284
|
|
|
276
285
|
const fastify = Fastify()
|
|
@@ -346,11 +355,12 @@ test('pretty print - includeMeta, includeHooks', t => {
|
|
|
346
355
|
• (onRequest) ["anonymous()"]
|
|
347
356
|
• (onSend) ["headRouteOnSendHandler()"]
|
|
348
357
|
`
|
|
349
|
-
t.
|
|
350
|
-
t.
|
|
351
|
-
t.
|
|
352
|
-
t.
|
|
353
|
-
t.
|
|
354
|
-
t.
|
|
358
|
+
t.assert.strictEqual(typeof radixTree, 'string')
|
|
359
|
+
t.assert.strictEqual(typeof flatTree, 'string')
|
|
360
|
+
t.assert.strictEqual(typeof hooksOnlyExpected, 'string')
|
|
361
|
+
t.assert.strictEqual(radixTree, radixExpected)
|
|
362
|
+
t.assert.strictEqual(flatTree, flatExpected)
|
|
363
|
+
t.assert.strictEqual(hooksOnly, hooksOnlyExpected)
|
|
364
|
+
done()
|
|
355
365
|
})
|
|
356
366
|
})
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const Fastify = require('..')
|
|
4
4
|
const sget = require('simple-get').concat
|
|
5
|
-
const
|
|
6
|
-
const test = t.test
|
|
5
|
+
const { test } = require('node:test')
|
|
7
6
|
|
|
8
|
-
test('proto-poisoning error', t => {
|
|
7
|
+
test('proto-poisoning error', (t, done) => {
|
|
9
8
|
t.plan(3)
|
|
10
9
|
|
|
11
10
|
const fastify = Fastify()
|
|
12
|
-
t.teardown(fastify.close.bind(fastify))
|
|
13
11
|
|
|
14
12
|
fastify.post('/', (request, reply) => {
|
|
15
|
-
t.fail('handler should not be called')
|
|
13
|
+
t.assert.fail('handler should not be called')
|
|
16
14
|
})
|
|
17
15
|
|
|
18
16
|
fastify.listen({ port: 0 }, function (err) {
|
|
19
|
-
t.
|
|
17
|
+
t.assert.ifError(err)
|
|
20
18
|
|
|
21
19
|
sget({
|
|
22
20
|
method: 'POST',
|
|
@@ -24,25 +22,26 @@ test('proto-poisoning error', t => {
|
|
|
24
22
|
headers: { 'Content-Type': 'application/json' },
|
|
25
23
|
body: '{ "__proto__": { "a": 42 } }'
|
|
26
24
|
}, (err, response, body) => {
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
25
|
+
t.assert.ifError(err)
|
|
26
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
27
|
+
fastify.close()
|
|
28
|
+
done()
|
|
29
29
|
})
|
|
30
30
|
})
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
test('proto-poisoning remove', t => {
|
|
33
|
+
test('proto-poisoning remove', (t, done) => {
|
|
34
34
|
t.plan(4)
|
|
35
35
|
|
|
36
36
|
const fastify = Fastify({ onProtoPoisoning: 'remove' })
|
|
37
|
-
t.teardown(fastify.close.bind(fastify))
|
|
38
37
|
|
|
39
38
|
fastify.post('/', (request, reply) => {
|
|
40
|
-
t.
|
|
39
|
+
t.assert.strictEqual(undefined, Object.assign({}, request.body).a)
|
|
41
40
|
reply.send({ ok: true })
|
|
42
41
|
})
|
|
43
42
|
|
|
44
43
|
fastify.listen({ port: 0 }, function (err) {
|
|
45
|
-
t.
|
|
44
|
+
t.assert.ifError(err)
|
|
46
45
|
|
|
47
46
|
sget({
|
|
48
47
|
method: 'POST',
|
|
@@ -50,25 +49,26 @@ test('proto-poisoning remove', t => {
|
|
|
50
49
|
headers: { 'Content-Type': 'application/json' },
|
|
51
50
|
body: '{ "__proto__": { "a": 42 }, "b": 42 }'
|
|
52
51
|
}, (err, response, body) => {
|
|
53
|
-
t.
|
|
54
|
-
t.
|
|
52
|
+
t.assert.ifError(err)
|
|
53
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
54
|
+
fastify.close()
|
|
55
|
+
done()
|
|
55
56
|
})
|
|
56
57
|
})
|
|
57
58
|
})
|
|
58
59
|
|
|
59
|
-
test('proto-poisoning ignore', t => {
|
|
60
|
+
test('proto-poisoning ignore', (t, done) => {
|
|
60
61
|
t.plan(4)
|
|
61
62
|
|
|
62
63
|
const fastify = Fastify({ onProtoPoisoning: 'ignore' })
|
|
63
|
-
t.teardown(fastify.close.bind(fastify))
|
|
64
64
|
|
|
65
65
|
fastify.post('/', (request, reply) => {
|
|
66
|
-
t.
|
|
66
|
+
t.assert.strictEqual(42, Object.assign({}, request.body).a)
|
|
67
67
|
reply.send({ ok: true })
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
fastify.listen({ port: 0 }, function (err) {
|
|
71
|
-
t.
|
|
71
|
+
t.assert.ifError(err)
|
|
72
72
|
|
|
73
73
|
sget({
|
|
74
74
|
method: 'POST',
|
|
@@ -76,24 +76,25 @@ test('proto-poisoning ignore', t => {
|
|
|
76
76
|
headers: { 'Content-Type': 'application/json' },
|
|
77
77
|
body: '{ "__proto__": { "a": 42 }, "b": 42 }'
|
|
78
78
|
}, (err, response, body) => {
|
|
79
|
-
t.
|
|
80
|
-
t.
|
|
79
|
+
t.assert.ifError(err)
|
|
80
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
81
|
+
fastify.close()
|
|
82
|
+
done()
|
|
81
83
|
})
|
|
82
84
|
})
|
|
83
85
|
})
|
|
84
86
|
|
|
85
|
-
test('constructor-poisoning error (default in v3)', t => {
|
|
87
|
+
test('constructor-poisoning error (default in v3)', (t, done) => {
|
|
86
88
|
t.plan(3)
|
|
87
89
|
|
|
88
90
|
const fastify = Fastify()
|
|
89
|
-
t.teardown(fastify.close.bind(fastify))
|
|
90
91
|
|
|
91
92
|
fastify.post('/', (request, reply) => {
|
|
92
93
|
reply.send('ok')
|
|
93
94
|
})
|
|
94
95
|
|
|
95
96
|
fastify.listen({ port: 0 }, function (err) {
|
|
96
|
-
t.
|
|
97
|
+
t.assert.ifError(err)
|
|
97
98
|
|
|
98
99
|
sget({
|
|
99
100
|
method: 'POST',
|
|
@@ -101,24 +102,25 @@ test('constructor-poisoning error (default in v3)', t => {
|
|
|
101
102
|
headers: { 'Content-Type': 'application/json' },
|
|
102
103
|
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
103
104
|
}, (err, response, body) => {
|
|
104
|
-
t.
|
|
105
|
-
t.
|
|
105
|
+
t.assert.ifError(err)
|
|
106
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
107
|
+
fastify.close()
|
|
108
|
+
done()
|
|
106
109
|
})
|
|
107
110
|
})
|
|
108
111
|
})
|
|
109
112
|
|
|
110
|
-
test('constructor-poisoning error', t => {
|
|
113
|
+
test('constructor-poisoning error', (t, done) => {
|
|
111
114
|
t.plan(3)
|
|
112
115
|
|
|
113
116
|
const fastify = Fastify({ onConstructorPoisoning: 'error' })
|
|
114
|
-
t.teardown(fastify.close.bind(fastify))
|
|
115
117
|
|
|
116
118
|
fastify.post('/', (request, reply) => {
|
|
117
|
-
t.fail('handler should not be called')
|
|
119
|
+
t.assert.fail('handler should not be called')
|
|
118
120
|
})
|
|
119
121
|
|
|
120
122
|
fastify.listen({ port: 0 }, function (err) {
|
|
121
|
-
t.
|
|
123
|
+
t.assert.ifError(err)
|
|
122
124
|
|
|
123
125
|
sget({
|
|
124
126
|
method: 'POST',
|
|
@@ -126,25 +128,26 @@ test('constructor-poisoning error', t => {
|
|
|
126
128
|
headers: { 'Content-Type': 'application/json' },
|
|
127
129
|
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
128
130
|
}, (err, response, body) => {
|
|
129
|
-
t.
|
|
130
|
-
t.
|
|
131
|
+
t.assert.ifError(err)
|
|
132
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
133
|
+
fastify.close()
|
|
134
|
+
done()
|
|
131
135
|
})
|
|
132
136
|
})
|
|
133
137
|
})
|
|
134
138
|
|
|
135
|
-
test('constructor-poisoning remove', t => {
|
|
139
|
+
test('constructor-poisoning remove', (t, done) => {
|
|
136
140
|
t.plan(4)
|
|
137
141
|
|
|
138
142
|
const fastify = Fastify({ onConstructorPoisoning: 'remove' })
|
|
139
|
-
t.teardown(fastify.close.bind(fastify))
|
|
140
143
|
|
|
141
144
|
fastify.post('/', (request, reply) => {
|
|
142
|
-
t.
|
|
145
|
+
t.assert.strictEqual(undefined, Object.assign({}, request.body).foo)
|
|
143
146
|
reply.send({ ok: true })
|
|
144
147
|
})
|
|
145
148
|
|
|
146
149
|
fastify.listen({ port: 0 }, function (err) {
|
|
147
|
-
t.
|
|
150
|
+
t.assert.ifError(err)
|
|
148
151
|
|
|
149
152
|
sget({
|
|
150
153
|
method: 'POST',
|
|
@@ -152,8 +155,10 @@ test('constructor-poisoning remove', t => {
|
|
|
152
155
|
headers: { 'Content-Type': 'application/json' },
|
|
153
156
|
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
154
157
|
}, (err, response, body) => {
|
|
155
|
-
t.
|
|
156
|
-
t.
|
|
158
|
+
t.assert.ifError(err)
|
|
159
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
160
|
+
fastify.close()
|
|
161
|
+
done()
|
|
157
162
|
})
|
|
158
163
|
})
|
|
159
164
|
})
|
package/test/reply-code.test.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const { Readable } = require('stream')
|
|
5
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const { Readable } = require('node:stream')
|
|
6
5
|
const Fastify = require('..')
|
|
7
6
|
|
|
8
|
-
test('code should handle null/undefined/float', t => {
|
|
7
|
+
test('code should handle null/undefined/float', (t, done) => {
|
|
9
8
|
t.plan(8)
|
|
10
9
|
|
|
11
10
|
const fastify = Fastify()
|
|
@@ -26,9 +25,9 @@ test('code should handle null/undefined/float', t => {
|
|
|
26
25
|
method: 'GET',
|
|
27
26
|
url: '/null'
|
|
28
27
|
}, (error, res) => {
|
|
29
|
-
t.
|
|
30
|
-
t.
|
|
31
|
-
t.
|
|
28
|
+
t.assert.ifError(error)
|
|
29
|
+
t.assert.strictEqual(res.statusCode, 500)
|
|
30
|
+
t.assert.deepStrictEqual(res.json(), {
|
|
32
31
|
statusCode: 500,
|
|
33
32
|
code: 'FST_ERR_BAD_STATUS_CODE',
|
|
34
33
|
error: 'Internal Server Error',
|
|
@@ -40,9 +39,9 @@ test('code should handle null/undefined/float', t => {
|
|
|
40
39
|
method: 'GET',
|
|
41
40
|
url: '/undefined'
|
|
42
41
|
}, (error, res) => {
|
|
43
|
-
t.
|
|
44
|
-
t.
|
|
45
|
-
t.
|
|
42
|
+
t.assert.ifError(error)
|
|
43
|
+
t.assert.strictEqual(res.statusCode, 500)
|
|
44
|
+
t.assert.deepStrictEqual(res.json(), {
|
|
46
45
|
statusCode: 500,
|
|
47
46
|
code: 'FST_ERR_BAD_STATUS_CODE',
|
|
48
47
|
error: 'Internal Server Error',
|
|
@@ -54,12 +53,13 @@ test('code should handle null/undefined/float', t => {
|
|
|
54
53
|
method: 'GET',
|
|
55
54
|
url: '/404.5'
|
|
56
55
|
}, (error, res) => {
|
|
57
|
-
t.
|
|
58
|
-
t.
|
|
56
|
+
t.assert.ifError(error)
|
|
57
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
58
|
+
done()
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
test('code should handle 204', t => {
|
|
62
|
+
test('code should handle 204', (t, done) => {
|
|
63
63
|
t.plan(13)
|
|
64
64
|
|
|
65
65
|
const fastify = Fastify()
|
|
@@ -80,7 +80,7 @@ test('code should handle 204', t => {
|
|
|
80
80
|
}
|
|
81
81
|
})
|
|
82
82
|
stream.on('end', () => {
|
|
83
|
-
t.
|
|
83
|
+
t.assert.ok('stream ended')
|
|
84
84
|
})
|
|
85
85
|
reply.status(204).send(stream)
|
|
86
86
|
})
|
|
@@ -89,34 +89,35 @@ test('code should handle 204', t => {
|
|
|
89
89
|
method: 'GET',
|
|
90
90
|
url: '/204'
|
|
91
91
|
}, (error, res) => {
|
|
92
|
-
t.
|
|
93
|
-
t.
|
|
94
|
-
t.
|
|
95
|
-
t.
|
|
92
|
+
t.assert.ifError(error)
|
|
93
|
+
t.assert.strictEqual(res.statusCode, 204)
|
|
94
|
+
t.assert.strictEqual(res.payload, '')
|
|
95
|
+
t.assert.strictEqual(res.headers['content-length'], undefined)
|
|
96
96
|
})
|
|
97
97
|
|
|
98
98
|
fastify.inject({
|
|
99
99
|
method: 'GET',
|
|
100
100
|
url: '/undefined/204'
|
|
101
101
|
}, (error, res) => {
|
|
102
|
-
t.
|
|
103
|
-
t.
|
|
104
|
-
t.
|
|
105
|
-
t.
|
|
102
|
+
t.assert.ifError(error)
|
|
103
|
+
t.assert.strictEqual(res.statusCode, 204)
|
|
104
|
+
t.assert.strictEqual(res.payload, '')
|
|
105
|
+
t.assert.strictEqual(res.headers['content-length'], undefined)
|
|
106
106
|
})
|
|
107
107
|
|
|
108
108
|
fastify.inject({
|
|
109
109
|
method: 'GET',
|
|
110
110
|
url: '/stream/204'
|
|
111
111
|
}, (error, res) => {
|
|
112
|
-
t.
|
|
113
|
-
t.
|
|
114
|
-
t.
|
|
115
|
-
t.
|
|
112
|
+
t.assert.ifError(error)
|
|
113
|
+
t.assert.strictEqual(res.statusCode, 204)
|
|
114
|
+
t.assert.strictEqual(res.payload, '')
|
|
115
|
+
t.assert.strictEqual(res.headers['content-length'], undefined)
|
|
116
|
+
done()
|
|
116
117
|
})
|
|
117
118
|
})
|
|
118
119
|
|
|
119
|
-
test('code should handle onSend hook on 204', t => {
|
|
120
|
+
test('code should handle onSend hook on 204', (t, done) => {
|
|
120
121
|
t.plan(5)
|
|
121
122
|
|
|
122
123
|
const fastify = Fastify()
|
|
@@ -137,10 +138,11 @@ test('code should handle onSend hook on 204', t => {
|
|
|
137
138
|
method: 'GET',
|
|
138
139
|
url: '/204'
|
|
139
140
|
}, (error, res) => {
|
|
140
|
-
t.
|
|
141
|
-
t.
|
|
142
|
-
t.
|
|
143
|
-
t.
|
|
144
|
-
t.
|
|
141
|
+
t.assert.ifError(error)
|
|
142
|
+
t.assert.strictEqual(res.statusCode, 204)
|
|
143
|
+
t.assert.strictEqual(res.payload, '')
|
|
144
|
+
t.assert.strictEqual(res.headers['content-length'], undefined)
|
|
145
|
+
t.assert.strictEqual(res.headers['content-type'], undefined)
|
|
146
|
+
done()
|
|
145
147
|
})
|
|
146
148
|
})
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const Fastify = require('..')
|
|
4
|
-
const { test } = require('
|
|
5
|
-
const http = require('http')
|
|
6
|
-
const http2 = require('http2')
|
|
4
|
+
const { test } = require('node:test')
|
|
5
|
+
const http = require('node:http')
|
|
6
|
+
const http2 = require('node:http2')
|
|
7
7
|
|
|
8
8
|
const testResBody = 'Hello, world!'
|
|
9
9
|
|
|
10
|
-
test('sends early hints', (t) => {
|
|
10
|
+
test('sends early hints', (t, done) => {
|
|
11
11
|
t.plan(6)
|
|
12
12
|
|
|
13
13
|
const fastify = Fastify({
|
|
@@ -18,24 +18,24 @@ test('sends early hints', (t) => {
|
|
|
18
18
|
reply.writeEarlyHints({
|
|
19
19
|
link: '</styles.css>; rel=preload; as=style'
|
|
20
20
|
}, () => {
|
|
21
|
-
t.
|
|
21
|
+
t.assert.ok('callback called')
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
return testResBody
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
28
|
-
t.
|
|
28
|
+
t.assert.ifError(err)
|
|
29
29
|
|
|
30
30
|
const req = http.get(address)
|
|
31
31
|
|
|
32
32
|
req.on('information', (res) => {
|
|
33
|
-
t.
|
|
34
|
-
t.
|
|
33
|
+
t.assert.strictEqual(res.statusCode, 103)
|
|
34
|
+
t.assert.strictEqual(res.headers.link, '</styles.css>; rel=preload; as=style')
|
|
35
35
|
})
|
|
36
36
|
|
|
37
37
|
req.on('response', (res) => {
|
|
38
|
-
t.
|
|
38
|
+
t.assert.strictEqual(res.statusCode, 200)
|
|
39
39
|
|
|
40
40
|
let data = ''
|
|
41
41
|
res.on('data', (chunk) => {
|
|
@@ -43,14 +43,15 @@ test('sends early hints', (t) => {
|
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
res.on('end', () => {
|
|
46
|
-
t.
|
|
47
|
-
fastify.close(
|
|
46
|
+
t.assert.strictEqual(data, testResBody)
|
|
47
|
+
fastify.close()
|
|
48
|
+
done()
|
|
48
49
|
})
|
|
49
50
|
})
|
|
50
51
|
})
|
|
51
52
|
})
|
|
52
53
|
|
|
53
|
-
test('sends early hints (http2)', (t) => {
|
|
54
|
+
test('sends early hints (http2)', (t, done) => {
|
|
54
55
|
t.plan(6)
|
|
55
56
|
|
|
56
57
|
const fastify = Fastify({
|
|
@@ -67,19 +68,19 @@ test('sends early hints (http2)', (t) => {
|
|
|
67
68
|
})
|
|
68
69
|
|
|
69
70
|
fastify.listen({ port: 0 }, (err, address) => {
|
|
70
|
-
t.
|
|
71
|
+
t.assert.ifError(err)
|
|
71
72
|
|
|
72
73
|
const client = http2.connect(address)
|
|
73
74
|
const req = client.request()
|
|
74
75
|
|
|
75
76
|
req.on('headers', (headers) => {
|
|
76
|
-
t.
|
|
77
|
-
t.
|
|
78
|
-
t.
|
|
77
|
+
t.assert.notStrictEqual(headers, undefined)
|
|
78
|
+
t.assert.strictEqual(headers[':status'], 103)
|
|
79
|
+
t.assert.strictEqual(headers.link, '</styles.css>; rel=preload; as=style')
|
|
79
80
|
})
|
|
80
81
|
|
|
81
82
|
req.on('response', (headers) => {
|
|
82
|
-
t.
|
|
83
|
+
t.assert.strictEqual(headers[':status'], 200)
|
|
83
84
|
})
|
|
84
85
|
|
|
85
86
|
let data = ''
|
|
@@ -88,9 +89,10 @@ test('sends early hints (http2)', (t) => {
|
|
|
88
89
|
})
|
|
89
90
|
|
|
90
91
|
req.on('end', () => {
|
|
91
|
-
t.
|
|
92
|
+
t.assert.strictEqual(data, testResBody)
|
|
92
93
|
client.close()
|
|
93
|
-
fastify.close(
|
|
94
|
+
fastify.close()
|
|
95
|
+
done()
|
|
94
96
|
})
|
|
95
97
|
|
|
96
98
|
req.end()
|