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
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const Fastify = require('..')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const { test } = require('node:test')
|
|
6
5
|
|
|
7
|
-
test('proto-poisoning error', (t
|
|
8
|
-
t.plan(
|
|
6
|
+
test('proto-poisoning error', async (t) => {
|
|
7
|
+
t.plan(2)
|
|
9
8
|
|
|
10
9
|
const fastify = Fastify()
|
|
11
10
|
|
|
@@ -13,52 +12,46 @@ test('proto-poisoning error', (t, done) => {
|
|
|
13
12
|
t.assert.fail('handler should not be called')
|
|
14
13
|
})
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, (err, response, body) => {
|
|
25
|
-
t.assert.ifError(err)
|
|
26
|
-
t.assert.strictEqual(response.statusCode, 400)
|
|
27
|
-
fastify.close()
|
|
28
|
-
done()
|
|
29
|
-
})
|
|
15
|
+
t.after(() => fastify.close())
|
|
16
|
+
|
|
17
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
18
|
+
|
|
19
|
+
const result = await fetch(fastifyServer, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: { 'Content-Type': 'application/json' },
|
|
22
|
+
body: '{ "__proto__": { "a": 42 } }'
|
|
30
23
|
})
|
|
24
|
+
|
|
25
|
+
t.assert.ok(!result.ok)
|
|
26
|
+
t.assert.strictEqual(result.status, 400)
|
|
31
27
|
})
|
|
32
28
|
|
|
33
|
-
test('proto-poisoning remove', (t
|
|
34
|
-
t.plan(
|
|
29
|
+
test('proto-poisoning remove', async (t) => {
|
|
30
|
+
t.plan(3)
|
|
35
31
|
|
|
36
32
|
const fastify = Fastify({ onProtoPoisoning: 'remove' })
|
|
37
33
|
|
|
34
|
+
t.after(() => fastify.close())
|
|
35
|
+
|
|
38
36
|
fastify.post('/', (request, reply) => {
|
|
39
37
|
t.assert.strictEqual(undefined, Object.assign({}, request.body).a)
|
|
40
38
|
reply.send({ ok: true })
|
|
41
39
|
})
|
|
42
40
|
|
|
43
|
-
fastify.listen({ port: 0 }
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
body: '{ "__proto__": { "a": 42 }, "b": 42 }'
|
|
51
|
-
}, (err, response, body) => {
|
|
52
|
-
t.assert.ifError(err)
|
|
53
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
54
|
-
fastify.close()
|
|
55
|
-
done()
|
|
56
|
-
})
|
|
41
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
42
|
+
|
|
43
|
+
const result = await fetch(fastifyServer, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: { 'Content-Type': 'application/json' },
|
|
46
|
+
body: '{ "__proto__": { "a": 42 }, "b": 42 }'
|
|
57
47
|
})
|
|
48
|
+
|
|
49
|
+
t.assert.ok(result.ok)
|
|
50
|
+
t.assert.strictEqual(result.status, 200)
|
|
58
51
|
})
|
|
59
52
|
|
|
60
|
-
test('proto-poisoning ignore', (t
|
|
61
|
-
t.plan(
|
|
53
|
+
test('proto-poisoning ignore', async (t) => {
|
|
54
|
+
t.plan(3)
|
|
62
55
|
|
|
63
56
|
const fastify = Fastify({ onProtoPoisoning: 'ignore' })
|
|
64
57
|
|
|
@@ -67,25 +60,22 @@ test('proto-poisoning ignore', (t, done) => {
|
|
|
67
60
|
reply.send({ ok: true })
|
|
68
61
|
})
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}, (err, response, body) => {
|
|
79
|
-
t.assert.ifError(err)
|
|
80
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
81
|
-
fastify.close()
|
|
82
|
-
done()
|
|
83
|
-
})
|
|
63
|
+
t.after(() => fastify.close())
|
|
64
|
+
|
|
65
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
66
|
+
|
|
67
|
+
const result = await fetch(fastifyServer, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: { 'Content-Type': 'application/json' },
|
|
70
|
+
body: '{ "__proto__": { "a": 42 }, "b": 42 }'
|
|
84
71
|
})
|
|
72
|
+
|
|
73
|
+
t.assert.ok(result.ok)
|
|
74
|
+
t.assert.strictEqual(result.status, 200)
|
|
85
75
|
})
|
|
86
76
|
|
|
87
|
-
test('constructor-poisoning error (default in v3)', (t
|
|
88
|
-
t.plan(
|
|
77
|
+
test('constructor-poisoning error (default in v3)', async (t) => {
|
|
78
|
+
t.plan(2)
|
|
89
79
|
|
|
90
80
|
const fastify = Fastify()
|
|
91
81
|
|
|
@@ -93,72 +83,63 @@ test('constructor-poisoning error (default in v3)', (t, done) => {
|
|
|
93
83
|
reply.send('ok')
|
|
94
84
|
})
|
|
95
85
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}, (err, response, body) => {
|
|
105
|
-
t.assert.ifError(err)
|
|
106
|
-
t.assert.strictEqual(response.statusCode, 400)
|
|
107
|
-
fastify.close()
|
|
108
|
-
done()
|
|
109
|
-
})
|
|
86
|
+
t.after(() => fastify.close())
|
|
87
|
+
|
|
88
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
89
|
+
|
|
90
|
+
const result = await fetch(fastifyServer, {
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: { 'Content-Type': 'application/json' },
|
|
93
|
+
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
110
94
|
})
|
|
95
|
+
|
|
96
|
+
t.assert.ok(!result.ok)
|
|
97
|
+
t.assert.strictEqual(result.status, 400)
|
|
111
98
|
})
|
|
112
99
|
|
|
113
|
-
test('constructor-poisoning error', (t
|
|
114
|
-
t.plan(
|
|
100
|
+
test('constructor-poisoning error', async (t) => {
|
|
101
|
+
t.plan(2)
|
|
115
102
|
|
|
116
103
|
const fastify = Fastify({ onConstructorPoisoning: 'error' })
|
|
117
104
|
|
|
105
|
+
t.after(() => fastify.close())
|
|
106
|
+
|
|
118
107
|
fastify.post('/', (request, reply) => {
|
|
119
108
|
t.assert.fail('handler should not be called')
|
|
120
109
|
})
|
|
121
110
|
|
|
122
|
-
fastify.listen({ port: 0 }
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
headers: { 'Content-Type': 'application/json' },
|
|
129
|
-
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
130
|
-
}, (err, response, body) => {
|
|
131
|
-
t.assert.ifError(err)
|
|
132
|
-
t.assert.strictEqual(response.statusCode, 400)
|
|
133
|
-
fastify.close()
|
|
134
|
-
done()
|
|
135
|
-
})
|
|
111
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
112
|
+
|
|
113
|
+
const result = await fetch(fastifyServer, {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: { 'Content-Type': 'application/json' },
|
|
116
|
+
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
136
117
|
})
|
|
118
|
+
|
|
119
|
+
t.assert.ok(!result.ok)
|
|
120
|
+
t.assert.strictEqual(result.status, 400)
|
|
137
121
|
})
|
|
138
122
|
|
|
139
|
-
test('constructor-poisoning remove', (t
|
|
140
|
-
t.plan(
|
|
123
|
+
test('constructor-poisoning remove', async (t) => {
|
|
124
|
+
t.plan(3)
|
|
141
125
|
|
|
142
126
|
const fastify = Fastify({ onConstructorPoisoning: 'remove' })
|
|
143
127
|
|
|
128
|
+
t.after(() => fastify.close())
|
|
129
|
+
|
|
144
130
|
fastify.post('/', (request, reply) => {
|
|
145
131
|
t.assert.strictEqual(undefined, Object.assign({}, request.body).foo)
|
|
146
132
|
reply.send({ ok: true })
|
|
147
133
|
})
|
|
148
134
|
|
|
149
|
-
fastify.listen({ port: 0 }
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
headers: { 'Content-Type': 'application/json' },
|
|
156
|
-
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
157
|
-
}, (err, response, body) => {
|
|
158
|
-
t.assert.ifError(err)
|
|
159
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
160
|
-
fastify.close()
|
|
161
|
-
done()
|
|
162
|
-
})
|
|
135
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
136
|
+
|
|
137
|
+
const result = await fetch(fastifyServer, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
headers: { 'Content-Type': 'application/json' },
|
|
140
|
+
body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
|
|
163
141
|
})
|
|
142
|
+
|
|
143
|
+
t.assert.ok(result.ok)
|
|
144
|
+
t.assert.strictEqual(result.status, 200)
|
|
164
145
|
})
|
package/test/put.test.js
CHANGED