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.
Files changed (103) hide show
  1. package/README.md +2 -0
  2. package/build/build-validation.js +2 -1
  3. package/docs/Guides/Delay-Accepting-Requests.md +3 -3
  4. package/docs/Guides/Ecosystem.md +16 -7
  5. package/docs/Guides/Serverless.md +28 -69
  6. package/docs/Reference/ContentTypeParser.md +1 -1
  7. package/docs/Reference/Errors.md +2 -4
  8. package/docs/Reference/Hooks.md +14 -14
  9. package/docs/Reference/Logging.md +3 -3
  10. package/docs/Reference/Middleware.md +1 -1
  11. package/docs/Reference/Reply.md +8 -8
  12. package/docs/Reference/Request.md +1 -1
  13. package/docs/Reference/Routes.md +3 -3
  14. package/docs/Reference/Server.md +40 -10
  15. package/docs/Reference/Validation-and-Serialization.md +1 -1
  16. package/eslint.config.js +17 -9
  17. package/fastify.d.ts +2 -1
  18. package/fastify.js +20 -4
  19. package/lib/configValidator.js +1 -1
  20. package/lib/decorate.js +2 -2
  21. package/lib/errors.js +6 -8
  22. package/lib/logger-factory.js +1 -1
  23. package/lib/logger-pino.js +2 -2
  24. package/lib/pluginOverride.js +3 -1
  25. package/lib/reply.js +9 -13
  26. package/lib/request.js +4 -11
  27. package/lib/server.js +30 -51
  28. package/lib/symbols.js +1 -0
  29. package/lib/warnings.js +8 -0
  30. package/package.json +11 -7
  31. package/test/404s.test.js +226 -325
  32. package/test/allow-unsafe-regex.test.js +19 -48
  33. package/test/als.test.js +28 -40
  34. package/test/async-await.test.js +11 -2
  35. package/test/body-limit.test.js +41 -65
  36. package/test/build-certificate.js +1 -1
  37. package/test/close-pipelining.test.js +5 -4
  38. package/test/custom-parser-async.test.js +17 -22
  39. package/test/decorator-namespace.test._js_ +3 -4
  40. package/test/decorator.test.js +422 -341
  41. package/test/diagnostics-channel/async-delay-request.test.js +7 -16
  42. package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
  43. package/test/helper.js +108 -70
  44. package/test/hooks-async.test.js +248 -218
  45. package/test/hooks.on-listen.test.js +255 -239
  46. package/test/hooks.on-ready.test.js +110 -92
  47. package/test/hooks.test.js +910 -769
  48. package/test/http-methods/lock.test.js +31 -31
  49. package/test/http-methods/mkcol.test.js +5 -9
  50. package/test/http-methods/proppatch.test.js +23 -29
  51. package/test/http-methods/report.test.js +44 -69
  52. package/test/http-methods/search.test.js +67 -82
  53. package/test/http2/closing.test.js +38 -20
  54. package/test/http2/secure-with-fallback.test.js +28 -27
  55. package/test/https/https.test.js +56 -53
  56. package/test/inject.test.js +114 -97
  57. package/test/input-validation.js +63 -53
  58. package/test/internals/errors.test.js +0 -10
  59. package/test/internals/handle-request.test.js +49 -66
  60. package/test/internals/hooks.test.js +17 -0
  61. package/test/issue-4959.test.js +14 -5
  62. package/test/listen.4.test.js +31 -43
  63. package/test/logger/response.test.js +19 -20
  64. package/test/nullable-validation.test.js +33 -46
  65. package/test/options.error-handler.test.js +1 -1
  66. package/test/options.test.js +1 -1
  67. package/test/output-validation.test.js +49 -72
  68. package/test/patch.error-handler.test.js +1 -1
  69. package/test/patch.test.js +1 -1
  70. package/test/plugin.1.test.js +71 -60
  71. package/test/plugin.2.test.js +104 -86
  72. package/test/plugin.3.test.js +56 -35
  73. package/test/plugin.4.test.js +124 -119
  74. package/test/promises.test.js +36 -30
  75. package/test/proto-poisoning.test.js +78 -97
  76. package/test/put.error-handler.test.js +1 -1
  77. package/test/put.test.js +1 -1
  78. package/test/reply-error.test.js +169 -148
  79. package/test/reply-trailers.test.js +119 -108
  80. package/test/request-error.test.js +0 -46
  81. package/test/route-hooks.test.js +112 -92
  82. package/test/route-prefix.test.js +194 -133
  83. package/test/schema-feature.test.js +309 -238
  84. package/test/schema-serialization.test.js +177 -154
  85. package/test/schema-special-usage.test.js +165 -132
  86. package/test/schema-validation.test.js +278 -199
  87. package/test/set-error-handler.test.js +58 -1
  88. package/test/skip-reply-send.test.js +64 -69
  89. package/test/stream.1.test.js +30 -27
  90. package/test/stream.2.test.js +20 -10
  91. package/test/stream.3.test.js +37 -31
  92. package/test/trust-proxy.test.js +32 -58
  93. package/test/types/errors.test-d.ts +0 -1
  94. package/test/types/fastify.test-d.ts +3 -0
  95. package/test/types/plugin.test-d.ts +1 -1
  96. package/test/types/register.test-d.ts +1 -1
  97. package/test/types/request.test-d.ts +1 -0
  98. package/test/url-rewriting.test.js +45 -62
  99. package/test/use-semicolon-delimiter.test.js +1 -1
  100. package/types/errors.d.ts +0 -1
  101. package/types/request.d.ts +1 -0
  102. package/.taprc +0 -7
  103. 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, done) => {
8
- t.plan(3)
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
- fastify.listen({ port: 0 }, function (err) {
17
- t.assert.ifError(err)
18
-
19
- sget({
20
- method: 'POST',
21
- url: 'http://localhost:' + fastify.server.address().port,
22
- headers: { 'Content-Type': 'application/json' },
23
- body: '{ "__proto__": { "a": 42 } }'
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, done) => {
34
- t.plan(4)
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 }, function (err) {
44
- t.assert.ifError(err)
45
-
46
- sget({
47
- method: 'POST',
48
- url: 'http://localhost:' + fastify.server.address().port,
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, done) => {
61
- t.plan(4)
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
- fastify.listen({ port: 0 }, function (err) {
71
- t.assert.ifError(err)
72
-
73
- sget({
74
- method: 'POST',
75
- url: 'http://localhost:' + fastify.server.address().port,
76
- headers: { 'Content-Type': 'application/json' },
77
- body: '{ "__proto__": { "a": 42 }, "b": 42 }'
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, done) => {
88
- t.plan(3)
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
- fastify.listen({ port: 0 }, function (err) {
97
- t.assert.ifError(err)
98
-
99
- sget({
100
- method: 'POST',
101
- url: 'http://localhost:' + fastify.server.address().port,
102
- headers: { 'Content-Type': 'application/json' },
103
- body: '{ "constructor": { "prototype": { "foo": "bar" } } }'
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, done) => {
114
- t.plan(3)
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 }, function (err) {
123
- t.assert.ifError(err)
124
-
125
- sget({
126
- method: 'POST',
127
- url: 'http://localhost:' + fastify.server.address().port,
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, done) => {
140
- t.plan(4)
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 }, function (err) {
150
- t.assert.ifError(err)
151
-
152
- sget({
153
- method: 'POST',
154
- url: 'http://localhost:' + fastify.server.address().port,
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
  })
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const t = require('node:test')
4
4
  require('./helper').payloadMethod('put', t, true)
5
5
  require('./input-validation').payloadMethod('put', t)
package/test/put.test.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const t = require('node:test')
4
4
  require('./helper').payloadMethod('put', t)
5
5
  require('./input-validation').payloadMethod('put', t)