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
package/test/404s.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const fp = require('fastify-plugin')
|
|
6
5
|
const sget = require('simple-get').concat
|
|
7
6
|
const errors = require('http-errors')
|
|
@@ -9,84 +8,83 @@ const split = require('split2')
|
|
|
9
8
|
const Fastify = require('..')
|
|
10
9
|
const { getServerUrl } = require('./helper')
|
|
11
10
|
|
|
12
|
-
test('default 404', t => {
|
|
13
|
-
t.plan(
|
|
11
|
+
test('default 404', async t => {
|
|
12
|
+
t.plan(4)
|
|
14
13
|
|
|
15
|
-
const test = t.test
|
|
16
14
|
const fastify = Fastify()
|
|
17
15
|
|
|
18
16
|
fastify.get('/', function (req, reply) {
|
|
19
17
|
reply.send({ hello: 'world' })
|
|
20
18
|
})
|
|
21
19
|
|
|
22
|
-
t.
|
|
20
|
+
t.after(() => { fastify.close() })
|
|
23
21
|
|
|
24
|
-
fastify.listen({ port: 0 }
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
22
|
+
await fastify.listen({ port: 0 })
|
|
23
|
+
|
|
24
|
+
await t.test('unsupported method', (t, done) => {
|
|
25
|
+
t.plan(3)
|
|
26
|
+
sget({
|
|
27
|
+
method: 'PUT',
|
|
28
|
+
url: getServerUrl(fastify),
|
|
29
|
+
body: {},
|
|
30
|
+
json: true
|
|
31
|
+
}, (err, response, body) => {
|
|
32
|
+
t.assert.ifError(err)
|
|
33
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
34
|
+
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
|
35
|
+
done()
|
|
39
36
|
})
|
|
37
|
+
})
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
// Return 404 instead of 405 see https://github.com/fastify/fastify/pull/862 for discussion
|
|
40
|
+
await t.test('framework-unsupported method', (t, done) => {
|
|
41
|
+
t.plan(3)
|
|
42
|
+
sget({
|
|
43
|
+
method: 'PROPFIND',
|
|
44
|
+
url: getServerUrl(fastify),
|
|
45
|
+
body: {},
|
|
46
|
+
json: true
|
|
47
|
+
}, (err, response, body) => {
|
|
48
|
+
t.assert.ifError(err)
|
|
49
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
50
|
+
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
|
51
|
+
done()
|
|
54
52
|
})
|
|
53
|
+
})
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
await t.test('unsupported route', (t, done) => {
|
|
56
|
+
t.plan(3)
|
|
57
|
+
sget({
|
|
58
|
+
method: 'GET',
|
|
59
|
+
url: getServerUrl(fastify) + '/notSupported',
|
|
60
|
+
body: {},
|
|
61
|
+
json: true
|
|
62
|
+
}, (err, response, body) => {
|
|
63
|
+
t.assert.ifError(err)
|
|
64
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
65
|
+
t.assert.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
|
|
66
|
+
done()
|
|
68
67
|
})
|
|
68
|
+
})
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
await t.test('using post method and multipart/formdata', async t => {
|
|
71
|
+
t.plan(3)
|
|
72
|
+
const form = new FormData()
|
|
73
|
+
form.set('test-field', 'just some field')
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
79
|
-
t.equal(response.status, 404)
|
|
80
|
-
t.equal(response.statusText, 'Not Found')
|
|
81
|
-
t.equal(response.headers.get('content-type'), 'application/json; charset=utf-8')
|
|
75
|
+
const response = await fetch(getServerUrl(fastify) + '/notSupported', {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
body: form
|
|
82
78
|
})
|
|
79
|
+
t.assert.strictEqual(response.status, 404)
|
|
80
|
+
t.assert.strictEqual(response.statusText, 'Not Found')
|
|
81
|
+
t.assert.strictEqual(response.headers.get('content-type'), 'application/json; charset=utf-8')
|
|
83
82
|
})
|
|
84
83
|
})
|
|
85
84
|
|
|
86
|
-
test('customized 404', t => {
|
|
87
|
-
t.plan(
|
|
85
|
+
test('customized 404', async t => {
|
|
86
|
+
t.plan(5)
|
|
88
87
|
|
|
89
|
-
const test = t.test
|
|
90
88
|
const fastify = Fastify()
|
|
91
89
|
|
|
92
90
|
fastify.get('/', function (req, reply) {
|
|
@@ -107,120 +105,121 @@ test('customized 404', t => {
|
|
|
107
105
|
reply.code(404).send('this was not found')
|
|
108
106
|
})
|
|
109
107
|
|
|
110
|
-
t.
|
|
108
|
+
t.after(() => { fastify.close() })
|
|
111
109
|
|
|
112
|
-
fastify.listen({ port: 0 }
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
110
|
+
await fastify.listen({ port: 0 })
|
|
111
|
+
|
|
112
|
+
await t.test('unsupported method', (t, done) => {
|
|
113
|
+
t.plan(3)
|
|
114
|
+
sget({
|
|
115
|
+
method: 'PUT',
|
|
116
|
+
url: getServerUrl(fastify),
|
|
117
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
118
|
+
headers: { 'Content-Type': 'application/json' }
|
|
119
|
+
}, (err, response, body) => {
|
|
120
|
+
t.assert.ifError(err)
|
|
121
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
122
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
123
|
+
done()
|
|
127
124
|
})
|
|
125
|
+
})
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
await t.test('framework-unsupported method', (t, done) => {
|
|
128
|
+
t.plan(3)
|
|
129
|
+
sget({
|
|
130
|
+
method: 'PROPFIND',
|
|
131
|
+
url: getServerUrl(fastify),
|
|
132
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
133
|
+
headers: { 'Content-Type': 'application/json' }
|
|
134
|
+
}, (err, response, body) => {
|
|
135
|
+
t.assert.ifError(err)
|
|
136
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
137
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
138
|
+
done()
|
|
141
139
|
})
|
|
140
|
+
})
|
|
142
141
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
142
|
+
await t.test('unsupported route', (t, done) => {
|
|
143
|
+
t.plan(3)
|
|
144
|
+
sget({
|
|
145
|
+
method: 'GET',
|
|
146
|
+
url: getServerUrl(fastify) + '/notSupported'
|
|
147
|
+
}, (err, response, body) => {
|
|
148
|
+
t.assert.ifError(err)
|
|
149
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
150
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
151
|
+
done()
|
|
153
152
|
})
|
|
153
|
+
})
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
})
|
|
155
|
+
await t.test('with error object', (t, done) => {
|
|
156
|
+
t.plan(3)
|
|
157
|
+
sget({
|
|
158
|
+
method: 'GET',
|
|
159
|
+
url: getServerUrl(fastify) + '/with-error'
|
|
160
|
+
}, (err, response, body) => {
|
|
161
|
+
t.assert.ifError(err)
|
|
162
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
163
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
164
|
+
error: 'Not Found',
|
|
165
|
+
message: 'Not Found',
|
|
166
|
+
statusCode: 404
|
|
168
167
|
})
|
|
168
|
+
done()
|
|
169
169
|
})
|
|
170
|
+
})
|
|
170
171
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
})
|
|
172
|
+
await t.test('error object with headers property', (t, done) => {
|
|
173
|
+
t.plan(4)
|
|
174
|
+
sget({
|
|
175
|
+
method: 'GET',
|
|
176
|
+
url: getServerUrl(fastify) + '/with-error-custom-header'
|
|
177
|
+
}, (err, response, body) => {
|
|
178
|
+
t.assert.ifError(err)
|
|
179
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
180
|
+
t.assert.strictEqual(response.headers['x-foo'], 'bar')
|
|
181
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
182
|
+
error: 'Not Found',
|
|
183
|
+
message: 'Not Found',
|
|
184
|
+
statusCode: 404
|
|
185
185
|
})
|
|
186
|
+
done()
|
|
186
187
|
})
|
|
187
188
|
})
|
|
188
189
|
})
|
|
189
190
|
|
|
190
|
-
test('custom header in notFound handler', t => {
|
|
191
|
-
t.plan(
|
|
191
|
+
test('custom header in notFound handler', async t => {
|
|
192
|
+
t.plan(1)
|
|
192
193
|
|
|
193
|
-
const test = t.test
|
|
194
194
|
const fastify = Fastify()
|
|
195
195
|
|
|
196
196
|
fastify.setNotFoundHandler(function (req, reply) {
|
|
197
197
|
reply.code(404).header('x-foo', 'bar').send('this was not found')
|
|
198
198
|
})
|
|
199
199
|
|
|
200
|
-
t.
|
|
200
|
+
t.after(() => { fastify.close() })
|
|
201
201
|
|
|
202
|
-
fastify.listen({ port: 0 }
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
202
|
+
await fastify.listen({ port: 0 })
|
|
203
|
+
|
|
204
|
+
await t.test('not found with custom header', (t, done) => {
|
|
205
|
+
t.plan(4)
|
|
206
|
+
sget({
|
|
207
|
+
method: 'GET',
|
|
208
|
+
url: getServerUrl(fastify) + '/notSupported'
|
|
209
|
+
}, (err, response, body) => {
|
|
210
|
+
t.assert.ifError(err)
|
|
211
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
212
|
+
t.assert.strictEqual(response.headers['x-foo'], 'bar')
|
|
213
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
214
|
+
done()
|
|
216
215
|
})
|
|
217
216
|
})
|
|
218
217
|
})
|
|
219
218
|
|
|
220
|
-
test('setting a custom 404 handler multiple times is an error', t => {
|
|
219
|
+
test('setting a custom 404 handler multiple times is an error', async t => {
|
|
221
220
|
t.plan(5)
|
|
222
221
|
|
|
223
|
-
t.test('at the root level', t => {
|
|
222
|
+
await t.test('at the root level', t => {
|
|
224
223
|
t.plan(2)
|
|
225
224
|
|
|
226
225
|
const fastify = Fastify()
|
|
@@ -229,14 +228,14 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
229
228
|
|
|
230
229
|
try {
|
|
231
230
|
fastify.setNotFoundHandler(() => {})
|
|
232
|
-
t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
231
|
+
t.assert.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
233
232
|
} catch (err) {
|
|
234
|
-
t.
|
|
235
|
-
t.
|
|
233
|
+
t.assert.ok(err instanceof Error)
|
|
234
|
+
t.assert.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'')
|
|
236
235
|
}
|
|
237
236
|
})
|
|
238
237
|
|
|
239
|
-
t.test('at the plugin level', t => {
|
|
238
|
+
await t.test('at the plugin level', (t, done) => {
|
|
240
239
|
t.plan(3)
|
|
241
240
|
|
|
242
241
|
const fastify = Fastify()
|
|
@@ -246,22 +245,23 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
246
245
|
|
|
247
246
|
try {
|
|
248
247
|
instance.setNotFoundHandler(() => {})
|
|
249
|
-
t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
248
|
+
t.assert.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
250
249
|
} catch (err) {
|
|
251
|
-
t.
|
|
252
|
-
t.
|
|
250
|
+
t.assert.ok(err instanceof Error)
|
|
251
|
+
t.assert.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'')
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
done()
|
|
256
255
|
}, { prefix: '/prefix' })
|
|
257
256
|
|
|
258
257
|
fastify.listen({ port: 0 }, err => {
|
|
259
|
-
t.
|
|
258
|
+
t.assert.ifError(err)
|
|
260
259
|
fastify.close()
|
|
260
|
+
done()
|
|
261
261
|
})
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
t.test('at multiple levels', t => {
|
|
264
|
+
await t.test('at multiple levels', (t, done) => {
|
|
265
265
|
t.plan(3)
|
|
266
266
|
|
|
267
267
|
const fastify = Fastify()
|
|
@@ -269,10 +269,10 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
269
269
|
fastify.register((instance, options, done) => {
|
|
270
270
|
try {
|
|
271
271
|
instance.setNotFoundHandler(() => {})
|
|
272
|
-
t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
272
|
+
t.assert.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
273
273
|
} catch (err) {
|
|
274
|
-
t.
|
|
275
|
-
t.
|
|
274
|
+
t.assert.ok(err instanceof Error)
|
|
275
|
+
t.assert.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'')
|
|
276
276
|
}
|
|
277
277
|
done()
|
|
278
278
|
})
|
|
@@ -280,12 +280,13 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
280
280
|
fastify.setNotFoundHandler(() => {})
|
|
281
281
|
|
|
282
282
|
fastify.listen({ port: 0 }, err => {
|
|
283
|
-
t.
|
|
283
|
+
t.assert.ifError(err)
|
|
284
284
|
fastify.close()
|
|
285
|
+
done()
|
|
285
286
|
})
|
|
286
287
|
})
|
|
287
288
|
|
|
288
|
-
t.test('at multiple levels / 2', t => {
|
|
289
|
+
await t.test('at multiple levels / 2', (t, done) => {
|
|
289
290
|
t.plan(3)
|
|
290
291
|
|
|
291
292
|
const fastify = Fastify()
|
|
@@ -296,10 +297,10 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
296
297
|
instance.register((instance2, options, done) => {
|
|
297
298
|
try {
|
|
298
299
|
instance2.setNotFoundHandler(() => {})
|
|
299
|
-
t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
300
|
+
t.assert.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
300
301
|
} catch (err) {
|
|
301
|
-
t.
|
|
302
|
-
t.
|
|
302
|
+
t.assert.ok(err instanceof Error)
|
|
303
|
+
t.assert.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'')
|
|
303
304
|
}
|
|
304
305
|
done()
|
|
305
306
|
})
|
|
@@ -310,12 +311,13 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
310
311
|
fastify.setNotFoundHandler(() => {})
|
|
311
312
|
|
|
312
313
|
fastify.listen({ port: 0 }, err => {
|
|
313
|
-
t.
|
|
314
|
+
t.assert.ifError(err)
|
|
314
315
|
fastify.close()
|
|
316
|
+
done()
|
|
315
317
|
})
|
|
316
318
|
})
|
|
317
319
|
|
|
318
|
-
t.test('in separate plugins at the same level', t => {
|
|
320
|
+
await t.test('in separate plugins at the same level', (t, done) => {
|
|
319
321
|
t.plan(3)
|
|
320
322
|
|
|
321
323
|
const fastify = Fastify()
|
|
@@ -329,10 +331,10 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
329
331
|
instance.register((instance2B, options, done) => {
|
|
330
332
|
try {
|
|
331
333
|
instance2B.setNotFoundHandler(() => {})
|
|
332
|
-
t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
334
|
+
t.assert.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw')
|
|
333
335
|
} catch (err) {
|
|
334
|
-
t.
|
|
335
|
-
t.
|
|
336
|
+
t.assert.ok(err instanceof Error)
|
|
337
|
+
t.assert.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'')
|
|
336
338
|
}
|
|
337
339
|
done()
|
|
338
340
|
})
|
|
@@ -343,16 +345,16 @@ test('setting a custom 404 handler multiple times is an error', t => {
|
|
|
343
345
|
fastify.setNotFoundHandler(() => {})
|
|
344
346
|
|
|
345
347
|
fastify.listen({ port: 0 }, err => {
|
|
346
|
-
t.
|
|
348
|
+
t.assert.ifError(err)
|
|
347
349
|
fastify.close()
|
|
350
|
+
done()
|
|
348
351
|
})
|
|
349
352
|
})
|
|
350
353
|
})
|
|
351
354
|
|
|
352
|
-
test('encapsulated 404', t => {
|
|
353
|
-
t.plan(
|
|
355
|
+
test('encapsulated 404', async t => {
|
|
356
|
+
t.plan(12)
|
|
354
357
|
|
|
355
|
-
const test = t.test
|
|
356
358
|
const fastify = Fastify()
|
|
357
359
|
|
|
358
360
|
fastify.get('/', function (req, reply) {
|
|
@@ -384,199 +386,209 @@ test('encapsulated 404', t => {
|
|
|
384
386
|
done()
|
|
385
387
|
}, { prefix: '/test3/' })
|
|
386
388
|
|
|
387
|
-
t.
|
|
389
|
+
t.after(() => { fastify.close() })
|
|
388
390
|
|
|
389
|
-
fastify.listen({ port: 0 }
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
})
|
|
391
|
+
await fastify.listen({ port: 0 })
|
|
392
|
+
|
|
393
|
+
await t.test('root unsupported method', (t, done) => {
|
|
394
|
+
t.plan(3)
|
|
395
|
+
sget({
|
|
396
|
+
method: 'PUT',
|
|
397
|
+
url: getServerUrl(fastify),
|
|
398
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
399
|
+
headers: { 'Content-Type': 'application/json' }
|
|
400
|
+
}, (err, response, body) => {
|
|
401
|
+
t.assert.ifError(err)
|
|
402
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
403
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
404
|
+
done()
|
|
404
405
|
})
|
|
406
|
+
})
|
|
405
407
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
408
|
+
await t.test('root framework-unsupported method', (t, done) => {
|
|
409
|
+
t.plan(3)
|
|
410
|
+
sget({
|
|
411
|
+
method: 'PROPFIND',
|
|
412
|
+
url: getServerUrl(fastify),
|
|
413
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
414
|
+
headers: { 'Content-Type': 'application/json' }
|
|
415
|
+
}, (err, response, body) => {
|
|
416
|
+
t.assert.ifError(err)
|
|
417
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
418
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
419
|
+
done()
|
|
418
420
|
})
|
|
421
|
+
})
|
|
419
422
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
423
|
+
await t.test('root unsupported route', (t, done) => {
|
|
424
|
+
t.plan(3)
|
|
425
|
+
sget({
|
|
426
|
+
method: 'GET',
|
|
427
|
+
url: getServerUrl(fastify) + '/notSupported'
|
|
428
|
+
}, (err, response, body) => {
|
|
429
|
+
t.assert.ifError(err)
|
|
430
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
431
|
+
t.assert.strictEqual(body.toString(), 'this was not found')
|
|
432
|
+
done()
|
|
430
433
|
})
|
|
434
|
+
})
|
|
431
435
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
436
|
+
await t.test('unsupported method', (t, done) => {
|
|
437
|
+
t.plan(3)
|
|
438
|
+
sget({
|
|
439
|
+
method: 'PUT',
|
|
440
|
+
url: getServerUrl(fastify) + '/test',
|
|
441
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
442
|
+
headers: { 'Content-Type': 'application/json' }
|
|
443
|
+
}, (err, response, body) => {
|
|
444
|
+
t.assert.ifError(err)
|
|
445
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
446
|
+
t.assert.strictEqual(body.toString(), 'this was not found 2')
|
|
447
|
+
done()
|
|
444
448
|
})
|
|
449
|
+
})
|
|
445
450
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
await t.test('framework-unsupported method', (t, done) => {
|
|
452
|
+
t.plan(3)
|
|
453
|
+
sget({
|
|
454
|
+
method: 'PROPFIND',
|
|
455
|
+
url: getServerUrl(fastify) + '/test',
|
|
456
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
457
|
+
headers: { 'Content-Type': 'application/json' }
|
|
458
|
+
}, (err, response, body) => {
|
|
459
|
+
t.assert.ifError(err)
|
|
460
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
461
|
+
t.assert.strictEqual(body.toString(), 'this was not found 2')
|
|
462
|
+
done()
|
|
458
463
|
})
|
|
464
|
+
})
|
|
459
465
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
466
|
+
await t.test('unsupported route', (t, done) => {
|
|
467
|
+
t.plan(3)
|
|
468
|
+
sget({
|
|
469
|
+
method: 'GET',
|
|
470
|
+
url: getServerUrl(fastify) + '/test/notSupported'
|
|
471
|
+
}, (err, response, body) => {
|
|
472
|
+
t.assert.ifError(err)
|
|
473
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
474
|
+
t.assert.strictEqual(body.toString(), 'this was not found 2')
|
|
475
|
+
done()
|
|
470
476
|
})
|
|
477
|
+
})
|
|
471
478
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
479
|
+
await t.test('unsupported method 2', (t, done) => {
|
|
480
|
+
t.plan(3)
|
|
481
|
+
sget({
|
|
482
|
+
method: 'PUT',
|
|
483
|
+
url: getServerUrl(fastify) + '/test2',
|
|
484
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
485
|
+
headers: { 'Content-Type': 'application/json' }
|
|
486
|
+
}, (err, response, body) => {
|
|
487
|
+
t.assert.ifError(err)
|
|
488
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
489
|
+
t.assert.strictEqual(body.toString(), 'this was not found 3')
|
|
490
|
+
done()
|
|
484
491
|
})
|
|
492
|
+
})
|
|
485
493
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
494
|
+
await t.test('framework-unsupported method 2', (t, done) => {
|
|
495
|
+
t.plan(3)
|
|
496
|
+
sget({
|
|
497
|
+
method: 'PROPFIND',
|
|
498
|
+
url: getServerUrl(fastify) + '/test2',
|
|
499
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
500
|
+
headers: { 'Content-Type': 'application/json' }
|
|
501
|
+
}, (err, response, body) => {
|
|
502
|
+
t.assert.ifError(err)
|
|
503
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
504
|
+
t.assert.strictEqual(body.toString(), 'this was not found 3')
|
|
505
|
+
done()
|
|
498
506
|
})
|
|
507
|
+
})
|
|
499
508
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
509
|
+
await t.test('unsupported route 2', (t, done) => {
|
|
510
|
+
t.plan(3)
|
|
511
|
+
sget({
|
|
512
|
+
method: 'GET',
|
|
513
|
+
url: getServerUrl(fastify) + '/test2/notSupported'
|
|
514
|
+
}, (err, response, body) => {
|
|
515
|
+
t.assert.ifError(err)
|
|
516
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
517
|
+
t.assert.strictEqual(body.toString(), 'this was not found 3')
|
|
518
|
+
done()
|
|
510
519
|
})
|
|
520
|
+
})
|
|
511
521
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
await t.test('unsupported method 3', (t, done) => {
|
|
523
|
+
t.plan(3)
|
|
524
|
+
sget({
|
|
525
|
+
method: 'PUT',
|
|
526
|
+
url: getServerUrl(fastify) + '/test3/',
|
|
527
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
528
|
+
headers: { 'Content-Type': 'application/json' }
|
|
529
|
+
}, (err, response, body) => {
|
|
530
|
+
t.assert.ifError(err)
|
|
531
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
532
|
+
t.assert.strictEqual(body.toString(), 'this was not found 4')
|
|
533
|
+
done()
|
|
524
534
|
})
|
|
535
|
+
})
|
|
525
536
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
537
|
+
await t.test('framework-unsupported method 3', (t, done) => {
|
|
538
|
+
t.plan(3)
|
|
539
|
+
sget({
|
|
540
|
+
method: 'PROPFIND',
|
|
541
|
+
url: getServerUrl(fastify) + '/test3/',
|
|
542
|
+
body: JSON.stringify({ hello: 'world' }),
|
|
543
|
+
headers: { 'Content-Type': 'application/json' }
|
|
544
|
+
}, (err, response, body) => {
|
|
545
|
+
t.assert.ifError(err)
|
|
546
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
547
|
+
t.assert.strictEqual(body.toString(), 'this was not found 4')
|
|
548
|
+
done()
|
|
538
549
|
})
|
|
550
|
+
})
|
|
539
551
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
552
|
+
await t.test('unsupported route 3', (t, done) => {
|
|
553
|
+
t.plan(3)
|
|
554
|
+
sget({
|
|
555
|
+
method: 'GET',
|
|
556
|
+
url: getServerUrl(fastify) + '/test3/notSupported'
|
|
557
|
+
}, (err, response, body) => {
|
|
558
|
+
t.assert.ifError(err)
|
|
559
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
560
|
+
t.assert.strictEqual(body.toString(), 'this was not found 4')
|
|
561
|
+
done()
|
|
550
562
|
})
|
|
551
563
|
})
|
|
552
564
|
})
|
|
553
565
|
|
|
554
|
-
test('custom 404 hook and handler context', t => {
|
|
555
|
-
t.plan(
|
|
566
|
+
test('custom 404 hook and handler context', async t => {
|
|
567
|
+
t.plan(19)
|
|
556
568
|
|
|
557
569
|
const fastify = Fastify()
|
|
558
570
|
|
|
559
571
|
fastify.decorate('foo', 42)
|
|
560
572
|
|
|
561
573
|
fastify.addHook('onRequest', function (req, res, done) {
|
|
562
|
-
t.
|
|
574
|
+
t.assert.strictEqual(this.foo, 42)
|
|
563
575
|
done()
|
|
564
576
|
})
|
|
565
577
|
fastify.addHook('preHandler', function (request, reply, done) {
|
|
566
|
-
t.
|
|
578
|
+
t.assert.strictEqual(this.foo, 42)
|
|
567
579
|
done()
|
|
568
580
|
})
|
|
569
581
|
fastify.addHook('onSend', function (request, reply, payload, done) {
|
|
570
|
-
t.
|
|
582
|
+
t.assert.strictEqual(this.foo, 42)
|
|
571
583
|
done()
|
|
572
584
|
})
|
|
573
585
|
fastify.addHook('onResponse', function (request, reply, done) {
|
|
574
|
-
t.
|
|
586
|
+
t.assert.strictEqual(this.foo, 42)
|
|
575
587
|
done()
|
|
576
588
|
})
|
|
577
589
|
|
|
578
590
|
fastify.setNotFoundHandler(function (req, reply) {
|
|
579
|
-
t.
|
|
591
|
+
t.assert.strictEqual(this.foo, 42)
|
|
580
592
|
reply.code(404).send('this was not found')
|
|
581
593
|
})
|
|
582
594
|
|
|
@@ -584,45 +596,45 @@ test('custom 404 hook and handler context', t => {
|
|
|
584
596
|
instance.decorate('bar', 84)
|
|
585
597
|
|
|
586
598
|
instance.addHook('onRequest', function (req, res, done) {
|
|
587
|
-
t.
|
|
599
|
+
t.assert.strictEqual(this.bar, 84)
|
|
588
600
|
done()
|
|
589
601
|
})
|
|
590
602
|
instance.addHook('preHandler', function (request, reply, done) {
|
|
591
|
-
t.
|
|
603
|
+
t.assert.strictEqual(this.bar, 84)
|
|
592
604
|
done()
|
|
593
605
|
})
|
|
594
606
|
instance.addHook('onSend', function (request, reply, payload, done) {
|
|
595
|
-
t.
|
|
607
|
+
t.assert.strictEqual(this.bar, 84)
|
|
596
608
|
done()
|
|
597
609
|
})
|
|
598
610
|
instance.addHook('onResponse', function (request, reply, done) {
|
|
599
|
-
t.
|
|
611
|
+
t.assert.strictEqual(this.bar, 84)
|
|
600
612
|
done()
|
|
601
613
|
})
|
|
602
614
|
|
|
603
615
|
instance.setNotFoundHandler(function (req, reply) {
|
|
604
|
-
t.
|
|
605
|
-
t.
|
|
616
|
+
t.assert.strictEqual(this.foo, 42)
|
|
617
|
+
t.assert.strictEqual(this.bar, 84)
|
|
606
618
|
reply.code(404).send('encapsulated was not found')
|
|
607
619
|
})
|
|
608
620
|
|
|
609
621
|
done()
|
|
610
622
|
}, { prefix: '/encapsulated' })
|
|
611
623
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
t.
|
|
615
|
-
t.
|
|
616
|
-
}
|
|
624
|
+
{
|
|
625
|
+
const res = await fastify.inject('/not-found')
|
|
626
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
627
|
+
t.assert.strictEqual(res.payload, 'this was not found')
|
|
628
|
+
}
|
|
617
629
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
t.
|
|
621
|
-
t.
|
|
622
|
-
}
|
|
630
|
+
{
|
|
631
|
+
const res = await fastify.inject('/encapsulated/not-found')
|
|
632
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
633
|
+
t.assert.strictEqual(res.payload, 'encapsulated was not found')
|
|
634
|
+
}
|
|
623
635
|
})
|
|
624
636
|
|
|
625
|
-
test('encapsulated custom 404 without - prefix hook and handler context', t => {
|
|
637
|
+
test('encapsulated custom 404 without - prefix hook and handler context', (t, done) => {
|
|
626
638
|
t.plan(13)
|
|
627
639
|
|
|
628
640
|
const fastify = Fastify()
|
|
@@ -633,29 +645,29 @@ test('encapsulated custom 404 without - prefix hook and handler context', t => {
|
|
|
633
645
|
instance.decorate('bar', 84)
|
|
634
646
|
|
|
635
647
|
instance.addHook('onRequest', function (req, res, done) {
|
|
636
|
-
t.
|
|
637
|
-
t.
|
|
648
|
+
t.assert.strictEqual(this.foo, 42)
|
|
649
|
+
t.assert.strictEqual(this.bar, 84)
|
|
638
650
|
done()
|
|
639
651
|
})
|
|
640
652
|
instance.addHook('preHandler', function (request, reply, done) {
|
|
641
|
-
t.
|
|
642
|
-
t.
|
|
653
|
+
t.assert.strictEqual(this.foo, 42)
|
|
654
|
+
t.assert.strictEqual(this.bar, 84)
|
|
643
655
|
done()
|
|
644
656
|
})
|
|
645
657
|
instance.addHook('onSend', function (request, reply, payload, done) {
|
|
646
|
-
t.
|
|
647
|
-
t.
|
|
658
|
+
t.assert.strictEqual(this.foo, 42)
|
|
659
|
+
t.assert.strictEqual(this.bar, 84)
|
|
648
660
|
done()
|
|
649
661
|
})
|
|
650
662
|
instance.addHook('onResponse', function (request, reply, done) {
|
|
651
|
-
t.
|
|
652
|
-
t.
|
|
663
|
+
t.assert.strictEqual(this.foo, 42)
|
|
664
|
+
t.assert.strictEqual(this.bar, 84)
|
|
653
665
|
done()
|
|
654
666
|
})
|
|
655
667
|
|
|
656
668
|
instance.setNotFoundHandler(function (request, reply) {
|
|
657
|
-
t.
|
|
658
|
-
t.
|
|
669
|
+
t.assert.strictEqual(this.foo, 42)
|
|
670
|
+
t.assert.strictEqual(this.bar, 84)
|
|
659
671
|
reply.code(404).send('custom not found')
|
|
660
672
|
})
|
|
661
673
|
|
|
@@ -663,34 +675,35 @@ test('encapsulated custom 404 without - prefix hook and handler context', t => {
|
|
|
663
675
|
})
|
|
664
676
|
|
|
665
677
|
fastify.inject('/not-found', (err, res) => {
|
|
666
|
-
t.
|
|
667
|
-
t.
|
|
668
|
-
t.
|
|
678
|
+
t.assert.ifError(err)
|
|
679
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
680
|
+
t.assert.strictEqual(res.payload, 'custom not found')
|
|
681
|
+
done()
|
|
669
682
|
})
|
|
670
683
|
})
|
|
671
684
|
|
|
672
|
-
test('run hooks on default 404', t => {
|
|
685
|
+
test('run hooks on default 404', (t, done) => {
|
|
673
686
|
t.plan(7)
|
|
674
687
|
|
|
675
688
|
const fastify = Fastify()
|
|
676
689
|
|
|
677
690
|
fastify.addHook('onRequest', function (req, res, done) {
|
|
678
|
-
t.
|
|
691
|
+
t.assert.ok(true, 'onRequest called')
|
|
679
692
|
done()
|
|
680
693
|
})
|
|
681
694
|
|
|
682
695
|
fastify.addHook('preHandler', function (request, reply, done) {
|
|
683
|
-
t.
|
|
696
|
+
t.assert.ok(true, 'preHandler called')
|
|
684
697
|
done()
|
|
685
698
|
})
|
|
686
699
|
|
|
687
700
|
fastify.addHook('onSend', function (request, reply, payload, done) {
|
|
688
|
-
t.
|
|
701
|
+
t.assert.ok(true, 'onSend called')
|
|
689
702
|
done()
|
|
690
703
|
})
|
|
691
704
|
|
|
692
705
|
fastify.addHook('onResponse', function (request, reply, done) {
|
|
693
|
-
t.
|
|
706
|
+
t.assert.ok(true, 'onResponse called')
|
|
694
707
|
done()
|
|
695
708
|
})
|
|
696
709
|
|
|
@@ -698,10 +711,10 @@ test('run hooks on default 404', t => {
|
|
|
698
711
|
reply.send({ hello: 'world' })
|
|
699
712
|
})
|
|
700
713
|
|
|
701
|
-
t.
|
|
714
|
+
t.after(() => { fastify.close() })
|
|
702
715
|
|
|
703
716
|
fastify.listen({ port: 0 }, err => {
|
|
704
|
-
t.
|
|
717
|
+
t.assert.ifError(err)
|
|
705
718
|
|
|
706
719
|
sget({
|
|
707
720
|
method: 'PUT',
|
|
@@ -709,35 +722,36 @@ test('run hooks on default 404', t => {
|
|
|
709
722
|
body: JSON.stringify({ hello: 'world' }),
|
|
710
723
|
headers: { 'Content-Type': 'application/json' }
|
|
711
724
|
}, (err, response, body) => {
|
|
712
|
-
t.
|
|
713
|
-
t.
|
|
725
|
+
t.assert.ifError(err)
|
|
726
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
727
|
+
done()
|
|
714
728
|
})
|
|
715
729
|
})
|
|
716
730
|
})
|
|
717
731
|
|
|
718
|
-
test('run non-encapsulated plugin hooks on default 404', t => {
|
|
732
|
+
test('run non-encapsulated plugin hooks on default 404', (t, done) => {
|
|
719
733
|
t.plan(6)
|
|
720
734
|
|
|
721
735
|
const fastify = Fastify()
|
|
722
736
|
|
|
723
737
|
fastify.register(fp(function (instance, options, done) {
|
|
724
738
|
instance.addHook('onRequest', function (req, res, done) {
|
|
725
|
-
t.
|
|
739
|
+
t.assert.ok(true, 'onRequest called')
|
|
726
740
|
done()
|
|
727
741
|
})
|
|
728
742
|
|
|
729
743
|
instance.addHook('preHandler', function (request, reply, done) {
|
|
730
|
-
t.
|
|
744
|
+
t.assert.ok(true, 'preHandler called')
|
|
731
745
|
done()
|
|
732
746
|
})
|
|
733
747
|
|
|
734
748
|
instance.addHook('onSend', function (request, reply, payload, done) {
|
|
735
|
-
t.
|
|
749
|
+
t.assert.ok(true, 'onSend called')
|
|
736
750
|
done()
|
|
737
751
|
})
|
|
738
752
|
|
|
739
753
|
instance.addHook('onResponse', function (request, reply, done) {
|
|
740
|
-
t.
|
|
754
|
+
t.assert.ok(true, 'onResponse called')
|
|
741
755
|
done()
|
|
742
756
|
})
|
|
743
757
|
|
|
@@ -753,34 +767,35 @@ test('run non-encapsulated plugin hooks on default 404', t => {
|
|
|
753
767
|
url: '/',
|
|
754
768
|
payload: { hello: 'world' }
|
|
755
769
|
}, (err, res) => {
|
|
756
|
-
t.
|
|
757
|
-
t.
|
|
770
|
+
t.assert.ifError(err)
|
|
771
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
772
|
+
done()
|
|
758
773
|
})
|
|
759
774
|
})
|
|
760
775
|
|
|
761
|
-
test('run non-encapsulated plugin hooks on custom 404', t => {
|
|
776
|
+
test('run non-encapsulated plugin hooks on custom 404', (t, done) => {
|
|
762
777
|
t.plan(11)
|
|
763
778
|
|
|
764
779
|
const fastify = Fastify()
|
|
765
780
|
|
|
766
781
|
const plugin = fp((instance, opts, done) => {
|
|
767
782
|
instance.addHook('onRequest', function (req, res, done) {
|
|
768
|
-
t.
|
|
783
|
+
t.assert.ok(true, 'onRequest called')
|
|
769
784
|
done()
|
|
770
785
|
})
|
|
771
786
|
|
|
772
787
|
instance.addHook('preHandler', function (request, reply, done) {
|
|
773
|
-
t.
|
|
788
|
+
t.assert.ok(true, 'preHandler called')
|
|
774
789
|
done()
|
|
775
790
|
})
|
|
776
791
|
|
|
777
792
|
instance.addHook('onSend', function (request, reply, payload, done) {
|
|
778
|
-
t.
|
|
793
|
+
t.assert.ok(true, 'onSend called')
|
|
779
794
|
done()
|
|
780
795
|
})
|
|
781
796
|
|
|
782
797
|
instance.addHook('onResponse', function (request, reply, done) {
|
|
783
|
-
t.
|
|
798
|
+
t.assert.ok(true, 'onResponse called')
|
|
784
799
|
done()
|
|
785
800
|
})
|
|
786
801
|
|
|
@@ -800,34 +815,35 @@ test('run non-encapsulated plugin hooks on custom 404', t => {
|
|
|
800
815
|
fastify.register(plugin) // Registering plugin after handler also works
|
|
801
816
|
|
|
802
817
|
fastify.inject({ url: '/not-found' }, (err, res) => {
|
|
803
|
-
t.
|
|
804
|
-
t.
|
|
805
|
-
t.
|
|
818
|
+
t.assert.ifError(err)
|
|
819
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
820
|
+
t.assert.strictEqual(res.payload, 'this was not found')
|
|
821
|
+
done()
|
|
806
822
|
})
|
|
807
823
|
})
|
|
808
824
|
|
|
809
|
-
test('run hook with encapsulated 404', t => {
|
|
825
|
+
test('run hook with encapsulated 404', (t, done) => {
|
|
810
826
|
t.plan(11)
|
|
811
827
|
|
|
812
828
|
const fastify = Fastify()
|
|
813
829
|
|
|
814
830
|
fastify.addHook('onRequest', function (req, res, done) {
|
|
815
|
-
t.
|
|
831
|
+
t.assert.ok(true, 'onRequest called')
|
|
816
832
|
done()
|
|
817
833
|
})
|
|
818
834
|
|
|
819
835
|
fastify.addHook('preHandler', function (request, reply, done) {
|
|
820
|
-
t.
|
|
836
|
+
t.assert.ok(true, 'preHandler called')
|
|
821
837
|
done()
|
|
822
838
|
})
|
|
823
839
|
|
|
824
840
|
fastify.addHook('onSend', function (request, reply, payload, done) {
|
|
825
|
-
t.
|
|
841
|
+
t.assert.ok(true, 'onSend called')
|
|
826
842
|
done()
|
|
827
843
|
})
|
|
828
844
|
|
|
829
845
|
fastify.addHook('onResponse', function (request, reply, done) {
|
|
830
|
-
t.
|
|
846
|
+
t.assert.ok(true, 'onResponse called')
|
|
831
847
|
done()
|
|
832
848
|
})
|
|
833
849
|
|
|
@@ -837,32 +853,32 @@ test('run hook with encapsulated 404', t => {
|
|
|
837
853
|
})
|
|
838
854
|
|
|
839
855
|
f.addHook('onRequest', function (req, res, done) {
|
|
840
|
-
t.
|
|
856
|
+
t.assert.ok(true, 'onRequest 2 called')
|
|
841
857
|
done()
|
|
842
858
|
})
|
|
843
859
|
|
|
844
860
|
f.addHook('preHandler', function (request, reply, done) {
|
|
845
|
-
t.
|
|
861
|
+
t.assert.ok(true, 'preHandler 2 called')
|
|
846
862
|
done()
|
|
847
863
|
})
|
|
848
864
|
|
|
849
865
|
f.addHook('onSend', function (request, reply, payload, done) {
|
|
850
|
-
t.
|
|
866
|
+
t.assert.ok(true, 'onSend 2 called')
|
|
851
867
|
done()
|
|
852
868
|
})
|
|
853
869
|
|
|
854
870
|
f.addHook('onResponse', function (request, reply, done) {
|
|
855
|
-
t.
|
|
871
|
+
t.assert.ok(true, 'onResponse 2 called')
|
|
856
872
|
done()
|
|
857
873
|
})
|
|
858
874
|
|
|
859
875
|
done()
|
|
860
876
|
}, { prefix: '/test' })
|
|
861
877
|
|
|
862
|
-
t.
|
|
878
|
+
t.after(() => { fastify.close() })
|
|
863
879
|
|
|
864
880
|
fastify.listen({ port: 0 }, err => {
|
|
865
|
-
t.
|
|
881
|
+
t.assert.ifError(err)
|
|
866
882
|
|
|
867
883
|
sget({
|
|
868
884
|
method: 'PUT',
|
|
@@ -870,34 +886,35 @@ test('run hook with encapsulated 404', t => {
|
|
|
870
886
|
body: JSON.stringify({ hello: 'world' }),
|
|
871
887
|
headers: { 'Content-Type': 'application/json' }
|
|
872
888
|
}, (err, response, body) => {
|
|
873
|
-
t.
|
|
874
|
-
t.
|
|
889
|
+
t.assert.ifError(err)
|
|
890
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
891
|
+
done()
|
|
875
892
|
})
|
|
876
893
|
})
|
|
877
894
|
})
|
|
878
895
|
|
|
879
|
-
test('run hook with encapsulated 404 and framework-unsupported method', t => {
|
|
896
|
+
test('run hook with encapsulated 404 and framework-unsupported method', (t, done) => {
|
|
880
897
|
t.plan(11)
|
|
881
898
|
|
|
882
899
|
const fastify = Fastify()
|
|
883
900
|
|
|
884
901
|
fastify.addHook('onRequest', function (req, res, done) {
|
|
885
|
-
t.
|
|
902
|
+
t.assert.ok(true, 'onRequest called')
|
|
886
903
|
done()
|
|
887
904
|
})
|
|
888
905
|
|
|
889
906
|
fastify.addHook('preHandler', function (request, reply, done) {
|
|
890
|
-
t.
|
|
907
|
+
t.assert.ok(true, 'preHandler called')
|
|
891
908
|
done()
|
|
892
909
|
})
|
|
893
910
|
|
|
894
911
|
fastify.addHook('onSend', function (request, reply, payload, done) {
|
|
895
|
-
t.
|
|
912
|
+
t.assert.ok(true, 'onSend called')
|
|
896
913
|
done()
|
|
897
914
|
})
|
|
898
915
|
|
|
899
916
|
fastify.addHook('onResponse', function (request, reply, done) {
|
|
900
|
-
t.
|
|
917
|
+
t.assert.ok(true, 'onResponse called')
|
|
901
918
|
done()
|
|
902
919
|
})
|
|
903
920
|
|
|
@@ -907,32 +924,32 @@ test('run hook with encapsulated 404 and framework-unsupported method', t => {
|
|
|
907
924
|
})
|
|
908
925
|
|
|
909
926
|
f.addHook('onRequest', function (req, res, done) {
|
|
910
|
-
t.
|
|
927
|
+
t.assert.ok(true, 'onRequest 2 called')
|
|
911
928
|
done()
|
|
912
929
|
})
|
|
913
930
|
|
|
914
931
|
f.addHook('preHandler', function (request, reply, done) {
|
|
915
|
-
t.
|
|
932
|
+
t.assert.ok(true, 'preHandler 2 called')
|
|
916
933
|
done()
|
|
917
934
|
})
|
|
918
935
|
|
|
919
936
|
f.addHook('onSend', function (request, reply, payload, done) {
|
|
920
|
-
t.
|
|
937
|
+
t.assert.ok(true, 'onSend 2 called')
|
|
921
938
|
done()
|
|
922
939
|
})
|
|
923
940
|
|
|
924
941
|
f.addHook('onResponse', function (request, reply, done) {
|
|
925
|
-
t.
|
|
942
|
+
t.assert.ok(true, 'onResponse 2 called')
|
|
926
943
|
done()
|
|
927
944
|
})
|
|
928
945
|
|
|
929
946
|
done()
|
|
930
947
|
}, { prefix: '/test' })
|
|
931
948
|
|
|
932
|
-
t.
|
|
949
|
+
t.after(() => { fastify.close() })
|
|
933
950
|
|
|
934
951
|
fastify.listen({ port: 0 }, err => {
|
|
935
|
-
t.
|
|
952
|
+
t.assert.ifError(err)
|
|
936
953
|
|
|
937
954
|
sget({
|
|
938
955
|
method: 'PROPFIND',
|
|
@@ -940,13 +957,14 @@ test('run hook with encapsulated 404 and framework-unsupported method', t => {
|
|
|
940
957
|
body: JSON.stringify({ hello: 'world' }),
|
|
941
958
|
headers: { 'Content-Type': 'application/json' }
|
|
942
959
|
}, (err, response, body) => {
|
|
943
|
-
t.
|
|
944
|
-
t.
|
|
960
|
+
t.assert.ifError(err)
|
|
961
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
962
|
+
done()
|
|
945
963
|
})
|
|
946
964
|
})
|
|
947
965
|
})
|
|
948
966
|
|
|
949
|
-
test('hooks check 404', t => {
|
|
967
|
+
test('hooks check 404', (t, done) => {
|
|
950
968
|
t.plan(13)
|
|
951
969
|
|
|
952
970
|
const fastify = Fastify()
|
|
@@ -956,23 +974,23 @@ test('hooks check 404', t => {
|
|
|
956
974
|
})
|
|
957
975
|
|
|
958
976
|
fastify.addHook('onSend', (req, reply, payload, done) => {
|
|
959
|
-
t.
|
|
960
|
-
t.ok('called
|
|
977
|
+
t.assert.deepStrictEqual(req.query, { foo: 'asd' })
|
|
978
|
+
t.assert.ok(true, 'called onSend')
|
|
961
979
|
done()
|
|
962
980
|
})
|
|
963
981
|
fastify.addHook('onRequest', (req, res, done) => {
|
|
964
|
-
t.ok('called
|
|
982
|
+
t.assert.ok(true, 'called onRequest')
|
|
965
983
|
done()
|
|
966
984
|
})
|
|
967
985
|
fastify.addHook('onResponse', (request, reply, done) => {
|
|
968
|
-
t.ok(
|
|
986
|
+
t.assert.ok(true, 'calledonResponse')
|
|
969
987
|
done()
|
|
970
988
|
})
|
|
971
989
|
|
|
972
|
-
t.
|
|
990
|
+
t.after(() => { fastify.close() })
|
|
973
991
|
|
|
974
992
|
fastify.listen({ port: 0 }, err => {
|
|
975
|
-
t.
|
|
993
|
+
t.assert.ifError(err)
|
|
976
994
|
|
|
977
995
|
sget({
|
|
978
996
|
method: 'PUT',
|
|
@@ -980,16 +998,17 @@ test('hooks check 404', t => {
|
|
|
980
998
|
body: JSON.stringify({ hello: 'world' }),
|
|
981
999
|
headers: { 'Content-Type': 'application/json' }
|
|
982
1000
|
}, (err, response, body) => {
|
|
983
|
-
t.
|
|
984
|
-
t.
|
|
1001
|
+
t.assert.ifError(err)
|
|
1002
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
985
1003
|
})
|
|
986
1004
|
|
|
987
1005
|
sget({
|
|
988
1006
|
method: 'GET',
|
|
989
1007
|
url: getServerUrl(fastify) + '/notSupported?foo=asd'
|
|
990
1008
|
}, (err, response, body) => {
|
|
991
|
-
t.
|
|
992
|
-
t.
|
|
1009
|
+
t.assert.ifError(err)
|
|
1010
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1011
|
+
done()
|
|
993
1012
|
})
|
|
994
1013
|
})
|
|
995
1014
|
})
|
|
@@ -1010,13 +1029,13 @@ test('setNotFoundHandler should not suppress duplicated routes checking', t => {
|
|
|
1010
1029
|
reply.code(404).send('this was not found')
|
|
1011
1030
|
})
|
|
1012
1031
|
|
|
1013
|
-
t.fail('setNotFoundHandler should not interfere duplicated route error')
|
|
1032
|
+
t.assert.fail('setNotFoundHandler should not interfere duplicated route error')
|
|
1014
1033
|
} catch (error) {
|
|
1015
|
-
t.ok(error)
|
|
1034
|
+
t.assert.ok(error)
|
|
1016
1035
|
}
|
|
1017
1036
|
})
|
|
1018
1037
|
|
|
1019
|
-
test('log debug for 404', t => {
|
|
1038
|
+
test('log debug for 404', async t => {
|
|
1020
1039
|
t.plan(1)
|
|
1021
1040
|
|
|
1022
1041
|
const Writable = require('node:stream').Writable
|
|
@@ -1039,28 +1058,29 @@ test('log debug for 404', t => {
|
|
|
1039
1058
|
reply.send({ hello: 'world' })
|
|
1040
1059
|
})
|
|
1041
1060
|
|
|
1042
|
-
t.
|
|
1061
|
+
t.after(() => { fastify.close() })
|
|
1043
1062
|
|
|
1044
|
-
t.test('log debug', t => {
|
|
1063
|
+
await t.test('log debug', (t, done) => {
|
|
1045
1064
|
t.plan(7)
|
|
1046
1065
|
fastify.inject({
|
|
1047
1066
|
method: 'GET',
|
|
1048
1067
|
url: '/not-found'
|
|
1049
1068
|
}, (err, response) => {
|
|
1050
|
-
t.
|
|
1051
|
-
t.
|
|
1069
|
+
t.assert.ifError(err)
|
|
1070
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1052
1071
|
|
|
1053
1072
|
const INFO_LEVEL = 30
|
|
1054
|
-
t.
|
|
1055
|
-
t.
|
|
1056
|
-
t.
|
|
1057
|
-
t.
|
|
1058
|
-
t.
|
|
1073
|
+
t.assert.strictEqual(JSON.parse(logStream.logs[0]).msg, 'incoming request')
|
|
1074
|
+
t.assert.strictEqual(JSON.parse(logStream.logs[1]).msg, 'Route GET:/not-found not found')
|
|
1075
|
+
t.assert.strictEqual(JSON.parse(logStream.logs[1]).level, INFO_LEVEL)
|
|
1076
|
+
t.assert.strictEqual(JSON.parse(logStream.logs[2]).msg, 'request completed')
|
|
1077
|
+
t.assert.strictEqual(logStream.logs.length, 3)
|
|
1078
|
+
done()
|
|
1059
1079
|
})
|
|
1060
1080
|
})
|
|
1061
1081
|
})
|
|
1062
1082
|
|
|
1063
|
-
test('Unknown method', t => {
|
|
1083
|
+
test('Unknown method', (t, done) => {
|
|
1064
1084
|
t.plan(5)
|
|
1065
1085
|
|
|
1066
1086
|
const fastify = Fastify()
|
|
@@ -1069,14 +1089,14 @@ test('Unknown method', t => {
|
|
|
1069
1089
|
reply.send({ hello: 'world' })
|
|
1070
1090
|
})
|
|
1071
1091
|
|
|
1072
|
-
t.
|
|
1092
|
+
t.after(() => { fastify.close() })
|
|
1073
1093
|
|
|
1074
1094
|
fastify.listen({ port: 0 }, err => {
|
|
1075
|
-
t.
|
|
1095
|
+
t.assert.ifError(err)
|
|
1076
1096
|
|
|
1077
1097
|
const handler = () => {}
|
|
1078
1098
|
// See https://github.com/fastify/light-my-request/pull/20
|
|
1079
|
-
t.throws(() => fastify.inject({
|
|
1099
|
+
t.assert.throws(() => fastify.inject({
|
|
1080
1100
|
method: 'UNKNOWN_METHOD',
|
|
1081
1101
|
url: '/'
|
|
1082
1102
|
}, handler), Error)
|
|
@@ -1085,18 +1105,19 @@ test('Unknown method', t => {
|
|
|
1085
1105
|
method: 'UNKNOWN_METHOD',
|
|
1086
1106
|
url: getServerUrl(fastify)
|
|
1087
1107
|
}, (err, response, body) => {
|
|
1088
|
-
t.
|
|
1089
|
-
t.
|
|
1090
|
-
t.
|
|
1108
|
+
t.assert.ifError(err)
|
|
1109
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
1110
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
1091
1111
|
error: 'Bad Request',
|
|
1092
1112
|
message: 'Client Error',
|
|
1093
1113
|
statusCode: 400
|
|
1094
1114
|
})
|
|
1115
|
+
done()
|
|
1095
1116
|
})
|
|
1096
1117
|
})
|
|
1097
1118
|
})
|
|
1098
1119
|
|
|
1099
|
-
test('recognizes errors from the http-errors module', t => {
|
|
1120
|
+
test('recognizes errors from the http-errors module', (t, done) => {
|
|
1100
1121
|
t.plan(5)
|
|
1101
1122
|
|
|
1102
1123
|
const fastify = Fastify()
|
|
@@ -1105,32 +1126,33 @@ test('recognizes errors from the http-errors module', t => {
|
|
|
1105
1126
|
reply.send(new errors.NotFound())
|
|
1106
1127
|
})
|
|
1107
1128
|
|
|
1108
|
-
t.
|
|
1129
|
+
t.after(() => { fastify.close() })
|
|
1109
1130
|
|
|
1110
1131
|
fastify.listen({ port: 0 }, err => {
|
|
1111
|
-
t.
|
|
1132
|
+
t.assert.ifError(err)
|
|
1112
1133
|
|
|
1113
1134
|
fastify.inject({
|
|
1114
1135
|
method: 'GET',
|
|
1115
1136
|
url: '/'
|
|
1116
1137
|
}, (err, res) => {
|
|
1117
|
-
t.
|
|
1118
|
-
t.
|
|
1138
|
+
t.assert.ifError(err)
|
|
1139
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1119
1140
|
|
|
1120
1141
|
sget(getServerUrl(fastify), (err, response, body) => {
|
|
1121
|
-
t.
|
|
1142
|
+
t.assert.ifError(err)
|
|
1122
1143
|
const obj = JSON.parse(body.toString())
|
|
1123
|
-
t.
|
|
1144
|
+
t.assert.deepStrictEqual(obj, {
|
|
1124
1145
|
error: 'Not Found',
|
|
1125
1146
|
message: 'Not Found',
|
|
1126
1147
|
statusCode: 404
|
|
1127
1148
|
})
|
|
1149
|
+
done()
|
|
1128
1150
|
})
|
|
1129
1151
|
})
|
|
1130
1152
|
})
|
|
1131
1153
|
})
|
|
1132
1154
|
|
|
1133
|
-
test('the default 404 handler can be invoked inside a prefixed plugin', t => {
|
|
1155
|
+
test('the default 404 handler can be invoked inside a prefixed plugin', (t, done) => {
|
|
1134
1156
|
t.plan(3)
|
|
1135
1157
|
|
|
1136
1158
|
const fastify = Fastify()
|
|
@@ -1144,17 +1166,18 @@ test('the default 404 handler can be invoked inside a prefixed plugin', t => {
|
|
|
1144
1166
|
}, { prefix: '/v1' })
|
|
1145
1167
|
|
|
1146
1168
|
fastify.inject('/v1/path', (err, res) => {
|
|
1147
|
-
t.
|
|
1148
|
-
t.
|
|
1149
|
-
t.
|
|
1169
|
+
t.assert.ifError(err)
|
|
1170
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1171
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
1150
1172
|
error: 'Not Found',
|
|
1151
1173
|
message: 'Not Found',
|
|
1152
1174
|
statusCode: 404
|
|
1153
1175
|
})
|
|
1176
|
+
done()
|
|
1154
1177
|
})
|
|
1155
1178
|
})
|
|
1156
1179
|
|
|
1157
|
-
test('an inherited custom 404 handler can be invoked inside a prefixed plugin', t => {
|
|
1180
|
+
test('an inherited custom 404 handler can be invoked inside a prefixed plugin', (t, done) => {
|
|
1158
1181
|
t.plan(3)
|
|
1159
1182
|
|
|
1160
1183
|
const fastify = Fastify()
|
|
@@ -1172,18 +1195,19 @@ test('an inherited custom 404 handler can be invoked inside a prefixed plugin',
|
|
|
1172
1195
|
}, { prefix: '/v1' })
|
|
1173
1196
|
|
|
1174
1197
|
fastify.inject('/v1/path', (err, res) => {
|
|
1175
|
-
t.
|
|
1176
|
-
t.
|
|
1177
|
-
t.
|
|
1198
|
+
t.assert.ifError(err)
|
|
1199
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1200
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
1178
1201
|
error: 'Not Found',
|
|
1179
1202
|
message: 'Not Found',
|
|
1180
1203
|
statusCode: 404
|
|
1181
1204
|
})
|
|
1205
|
+
done()
|
|
1182
1206
|
})
|
|
1183
1207
|
})
|
|
1184
1208
|
|
|
1185
|
-
test('encapsulated custom 404 handler without a prefix is the handler for the entire 404 level', t => {
|
|
1186
|
-
t.plan(
|
|
1209
|
+
test('encapsulated custom 404 handler without a prefix is the handler for the entire 404 level', async t => {
|
|
1210
|
+
t.plan(4)
|
|
1187
1211
|
|
|
1188
1212
|
const fastify = Fastify()
|
|
1189
1213
|
|
|
@@ -1206,38 +1230,39 @@ test('encapsulated custom 404 handler without a prefix is the handler for the en
|
|
|
1206
1230
|
done()
|
|
1207
1231
|
}, { prefix: 'prefixed' })
|
|
1208
1232
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
t.
|
|
1212
|
-
t.
|
|
1213
|
-
}
|
|
1233
|
+
{
|
|
1234
|
+
const res = await fastify.inject('/not-found')
|
|
1235
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1236
|
+
t.assert.strictEqual(res.payload, 'custom handler')
|
|
1237
|
+
}
|
|
1214
1238
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
t.
|
|
1218
|
-
t.
|
|
1219
|
-
}
|
|
1239
|
+
{
|
|
1240
|
+
const res = await fastify.inject('/prefixed/not-found')
|
|
1241
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1242
|
+
t.assert.strictEqual(res.payload, 'custom handler 2')
|
|
1243
|
+
}
|
|
1220
1244
|
})
|
|
1221
1245
|
|
|
1222
|
-
test('cannot set notFoundHandler after binding', t => {
|
|
1246
|
+
test('cannot set notFoundHandler after binding', (t, done) => {
|
|
1223
1247
|
t.plan(2)
|
|
1224
1248
|
|
|
1225
1249
|
const fastify = Fastify()
|
|
1226
|
-
t.
|
|
1250
|
+
t.after(() => { fastify.close() })
|
|
1227
1251
|
|
|
1228
1252
|
fastify.listen({ port: 0 }, err => {
|
|
1229
|
-
t.
|
|
1253
|
+
t.assert.ifError(err)
|
|
1230
1254
|
|
|
1231
1255
|
try {
|
|
1232
1256
|
fastify.setNotFoundHandler(() => { })
|
|
1233
|
-
t.fail()
|
|
1257
|
+
t.assert.fail()
|
|
1234
1258
|
} catch (e) {
|
|
1235
|
-
t.
|
|
1259
|
+
t.assert.ok(true)
|
|
1260
|
+
done()
|
|
1236
1261
|
}
|
|
1237
1262
|
})
|
|
1238
1263
|
})
|
|
1239
1264
|
|
|
1240
|
-
test('404 inside onSend', t => {
|
|
1265
|
+
test('404 inside onSend', (t, done) => {
|
|
1241
1266
|
t.plan(3)
|
|
1242
1267
|
|
|
1243
1268
|
const fastify = Fastify()
|
|
@@ -1257,29 +1282,30 @@ test('404 inside onSend', t => {
|
|
|
1257
1282
|
}
|
|
1258
1283
|
})
|
|
1259
1284
|
|
|
1260
|
-
t.
|
|
1285
|
+
t.after(() => { fastify.close() })
|
|
1261
1286
|
|
|
1262
1287
|
fastify.listen({ port: 0 }, err => {
|
|
1263
|
-
t.
|
|
1288
|
+
t.assert.ifError(err)
|
|
1264
1289
|
|
|
1265
1290
|
sget({
|
|
1266
1291
|
method: 'GET',
|
|
1267
1292
|
url: getServerUrl(fastify)
|
|
1268
1293
|
}, (err, response, body) => {
|
|
1269
|
-
t.
|
|
1270
|
-
t.
|
|
1294
|
+
t.assert.ifError(err)
|
|
1295
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1296
|
+
done()
|
|
1271
1297
|
})
|
|
1272
1298
|
})
|
|
1273
1299
|
})
|
|
1274
1300
|
|
|
1275
1301
|
// https://github.com/fastify/fastify/issues/868
|
|
1276
|
-
test('onSend hooks run when an encapsulated route invokes the notFound handler', t => {
|
|
1302
|
+
test('onSend hooks run when an encapsulated route invokes the notFound handler', (t, done) => {
|
|
1277
1303
|
t.plan(3)
|
|
1278
1304
|
const fastify = Fastify()
|
|
1279
1305
|
|
|
1280
1306
|
fastify.register((instance, options, done) => {
|
|
1281
1307
|
instance.addHook('onSend', (request, reply, payload, done) => {
|
|
1282
|
-
t.
|
|
1308
|
+
t.assert.ok(true, 'onSend hook called')
|
|
1283
1309
|
done()
|
|
1284
1310
|
})
|
|
1285
1311
|
|
|
@@ -1291,16 +1317,17 @@ test('onSend hooks run when an encapsulated route invokes the notFound handler',
|
|
|
1291
1317
|
})
|
|
1292
1318
|
|
|
1293
1319
|
fastify.inject('/', (err, res) => {
|
|
1294
|
-
t.
|
|
1295
|
-
t.
|
|
1320
|
+
t.assert.ifError(err)
|
|
1321
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1322
|
+
done()
|
|
1296
1323
|
})
|
|
1297
1324
|
})
|
|
1298
1325
|
|
|
1299
1326
|
// https://github.com/fastify/fastify/issues/713
|
|
1300
|
-
test('preHandler option for setNotFoundHandler', t => {
|
|
1327
|
+
test('preHandler option for setNotFoundHandler', async t => {
|
|
1301
1328
|
t.plan(10)
|
|
1302
1329
|
|
|
1303
|
-
t.test('preHandler option', t => {
|
|
1330
|
+
await t.test('preHandler option', (t, done) => {
|
|
1304
1331
|
t.plan(2)
|
|
1305
1332
|
const fastify = Fastify()
|
|
1306
1333
|
|
|
@@ -1318,14 +1345,15 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1318
1345
|
url: '/not-found',
|
|
1319
1346
|
payload: { hello: 'world' }
|
|
1320
1347
|
}, (err, res) => {
|
|
1321
|
-
t.
|
|
1348
|
+
t.assert.ifError(err)
|
|
1322
1349
|
const payload = JSON.parse(res.payload)
|
|
1323
|
-
t.
|
|
1350
|
+
t.assert.deepStrictEqual(payload, { preHandler: true, hello: 'world' })
|
|
1351
|
+
done()
|
|
1324
1352
|
})
|
|
1325
1353
|
})
|
|
1326
1354
|
|
|
1327
1355
|
// https://github.com/fastify/fastify/issues/2229
|
|
1328
|
-
t.test('preHandler hook in setNotFoundHandler should be called when callNotFound', { timeout: 40000 }, t => {
|
|
1356
|
+
await t.test('preHandler hook in setNotFoundHandler should be called when callNotFound', { timeout: 40000 }, (t, done) => {
|
|
1329
1357
|
t.plan(3)
|
|
1330
1358
|
const fastify = Fastify()
|
|
1331
1359
|
|
|
@@ -1339,7 +1367,7 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1339
1367
|
})
|
|
1340
1368
|
|
|
1341
1369
|
fastify.post('/', function (req, reply) {
|
|
1342
|
-
t.
|
|
1370
|
+
t.assert.strictEqual(reply.callNotFound(), reply)
|
|
1343
1371
|
})
|
|
1344
1372
|
|
|
1345
1373
|
fastify.inject({
|
|
@@ -1347,13 +1375,14 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1347
1375
|
url: '/',
|
|
1348
1376
|
payload: { hello: 'world' }
|
|
1349
1377
|
}, (err, res) => {
|
|
1350
|
-
t.
|
|
1378
|
+
t.assert.ifError(err)
|
|
1351
1379
|
const payload = JSON.parse(res.payload)
|
|
1352
|
-
t.
|
|
1380
|
+
t.assert.deepStrictEqual(payload, { preHandler: true, hello: 'world' })
|
|
1381
|
+
done()
|
|
1353
1382
|
})
|
|
1354
1383
|
})
|
|
1355
1384
|
|
|
1356
|
-
t.test('preHandler hook in setNotFoundHandler should accept an array of functions and be called when callNotFound', t => {
|
|
1385
|
+
await t.test('preHandler hook in setNotFoundHandler should accept an array of functions and be called when callNotFound', (t, done) => {
|
|
1357
1386
|
t.plan(2)
|
|
1358
1387
|
const fastify = Fastify()
|
|
1359
1388
|
|
|
@@ -1381,13 +1410,14 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1381
1410
|
url: '/',
|
|
1382
1411
|
payload: { hello: 'world' }
|
|
1383
1412
|
}, (err, res) => {
|
|
1384
|
-
t.
|
|
1413
|
+
t.assert.ifError(err)
|
|
1385
1414
|
const payload = JSON.parse(res.payload)
|
|
1386
|
-
t.
|
|
1415
|
+
t.assert.deepStrictEqual(payload, { preHandler1: true, preHandler2: true, hello: 'world' })
|
|
1416
|
+
done()
|
|
1387
1417
|
})
|
|
1388
1418
|
})
|
|
1389
1419
|
|
|
1390
|
-
t.test('preHandler option should be called after preHandler hook', t => {
|
|
1420
|
+
await t.test('preHandler option should be called after preHandler hook', (t, done) => {
|
|
1391
1421
|
t.plan(2)
|
|
1392
1422
|
const fastify = Fastify()
|
|
1393
1423
|
|
|
@@ -1410,14 +1440,15 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1410
1440
|
url: '/',
|
|
1411
1441
|
payload: { hello: 'world' }
|
|
1412
1442
|
}, (err, res) => {
|
|
1413
|
-
t.
|
|
1443
|
+
t.assert.ifError(err)
|
|
1414
1444
|
const payload = JSON.parse(res.payload)
|
|
1415
|
-
t.
|
|
1445
|
+
t.assert.deepStrictEqual(payload, { check: 'ab', hello: 'world' })
|
|
1446
|
+
done()
|
|
1416
1447
|
})
|
|
1417
1448
|
})
|
|
1418
1449
|
|
|
1419
|
-
t.test('preHandler option should be unique per prefix', t => {
|
|
1420
|
-
t.plan(
|
|
1450
|
+
await t.test('preHandler option should be unique per prefix', async t => {
|
|
1451
|
+
t.plan(2)
|
|
1421
1452
|
const fastify = Fastify()
|
|
1422
1453
|
|
|
1423
1454
|
fastify.setNotFoundHandler({
|
|
@@ -1437,28 +1468,30 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1437
1468
|
n()
|
|
1438
1469
|
}, { prefix: '/no' })
|
|
1439
1470
|
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1471
|
+
{
|
|
1472
|
+
const res = await fastify.inject({
|
|
1473
|
+
method: 'POST',
|
|
1474
|
+
url: '/not-found',
|
|
1475
|
+
payload: { hello: 'world' }
|
|
1476
|
+
})
|
|
1477
|
+
|
|
1446
1478
|
const payload = JSON.parse(res.payload)
|
|
1447
|
-
t.
|
|
1448
|
-
}
|
|
1479
|
+
t.assert.deepStrictEqual(payload, { hello: 'earth' })
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
{
|
|
1483
|
+
const res = await fastify.inject({
|
|
1484
|
+
method: 'POST',
|
|
1485
|
+
url: '/no/not-found',
|
|
1486
|
+
payload: { hello: 'world' }
|
|
1487
|
+
})
|
|
1449
1488
|
|
|
1450
|
-
fastify.inject({
|
|
1451
|
-
method: 'POST',
|
|
1452
|
-
url: '/no/not-found',
|
|
1453
|
-
payload: { hello: 'world' }
|
|
1454
|
-
}, (err, res) => {
|
|
1455
|
-
t.error(err)
|
|
1456
1489
|
const payload = JSON.parse(res.payload)
|
|
1457
|
-
t.
|
|
1458
|
-
}
|
|
1490
|
+
t.assert.deepStrictEqual(payload, { hello: 'world' })
|
|
1491
|
+
}
|
|
1459
1492
|
})
|
|
1460
1493
|
|
|
1461
|
-
t.test('preHandler option should handle errors', t => {
|
|
1494
|
+
await t.test('preHandler option should handle errors', (t, done) => {
|
|
1462
1495
|
t.plan(3)
|
|
1463
1496
|
const fastify = Fastify()
|
|
1464
1497
|
|
|
@@ -1475,18 +1508,19 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1475
1508
|
url: '/not-found',
|
|
1476
1509
|
payload: { hello: 'world' }
|
|
1477
1510
|
}, (err, res) => {
|
|
1478
|
-
t.
|
|
1511
|
+
t.assert.ifError(err)
|
|
1479
1512
|
const payload = JSON.parse(res.payload)
|
|
1480
|
-
t.
|
|
1481
|
-
t.
|
|
1513
|
+
t.assert.strictEqual(res.statusCode, 500)
|
|
1514
|
+
t.assert.deepStrictEqual(payload, {
|
|
1482
1515
|
message: 'kaboom',
|
|
1483
1516
|
error: 'Internal Server Error',
|
|
1484
1517
|
statusCode: 500
|
|
1485
1518
|
})
|
|
1519
|
+
done()
|
|
1486
1520
|
})
|
|
1487
1521
|
})
|
|
1488
1522
|
|
|
1489
|
-
t.test('preHandler option should handle errors with custom status code', t => {
|
|
1523
|
+
await t.test('preHandler option should handle errors with custom status code', (t, done) => {
|
|
1490
1524
|
t.plan(3)
|
|
1491
1525
|
const fastify = Fastify()
|
|
1492
1526
|
|
|
@@ -1504,18 +1538,19 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1504
1538
|
url: '/not-found',
|
|
1505
1539
|
payload: { hello: 'world' }
|
|
1506
1540
|
}, (err, res) => {
|
|
1507
|
-
t.
|
|
1541
|
+
t.assert.ifError(err)
|
|
1508
1542
|
const payload = JSON.parse(res.payload)
|
|
1509
|
-
t.
|
|
1510
|
-
t.
|
|
1543
|
+
t.assert.strictEqual(res.statusCode, 401)
|
|
1544
|
+
t.assert.deepStrictEqual(payload, {
|
|
1511
1545
|
message: 'go away',
|
|
1512
1546
|
error: 'Unauthorized',
|
|
1513
1547
|
statusCode: 401
|
|
1514
1548
|
})
|
|
1549
|
+
done()
|
|
1515
1550
|
})
|
|
1516
1551
|
})
|
|
1517
1552
|
|
|
1518
|
-
t.test('preHandler option could accept an array of functions', t => {
|
|
1553
|
+
await t.test('preHandler option could accept an array of functions', (t, done) => {
|
|
1519
1554
|
t.plan(2)
|
|
1520
1555
|
const fastify = Fastify()
|
|
1521
1556
|
|
|
@@ -1539,14 +1574,15 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1539
1574
|
url: '/not-found',
|
|
1540
1575
|
payload: { hello: 'world' }
|
|
1541
1576
|
}, (err, res) => {
|
|
1542
|
-
t.
|
|
1577
|
+
t.assert.ifError(err)
|
|
1543
1578
|
const payload = JSON.parse(res.payload)
|
|
1544
|
-
t.
|
|
1579
|
+
t.assert.deepStrictEqual(payload, { preHandler: 'ab', hello: 'world' })
|
|
1580
|
+
done()
|
|
1545
1581
|
})
|
|
1546
1582
|
})
|
|
1547
1583
|
|
|
1548
|
-
t.test('preHandler option does not interfere with preHandler', t => {
|
|
1549
|
-
t.plan(
|
|
1584
|
+
await t.test('preHandler option does not interfere with preHandler', async t => {
|
|
1585
|
+
t.plan(2)
|
|
1550
1586
|
const fastify = Fastify()
|
|
1551
1587
|
|
|
1552
1588
|
fastify.addHook('preHandler', (req, reply, done) => {
|
|
@@ -1571,28 +1607,30 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1571
1607
|
n()
|
|
1572
1608
|
}, { prefix: '/no' })
|
|
1573
1609
|
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1610
|
+
{
|
|
1611
|
+
const res = await fastify.inject({
|
|
1612
|
+
method: 'post',
|
|
1613
|
+
url: '/not-found',
|
|
1614
|
+
payload: { hello: 'world' }
|
|
1615
|
+
})
|
|
1616
|
+
|
|
1580
1617
|
const payload = JSON.parse(res.payload)
|
|
1581
|
-
t.
|
|
1582
|
-
}
|
|
1618
|
+
t.assert.deepStrictEqual(payload, { check: 'ab', hello: 'world' })
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
{
|
|
1622
|
+
const res = await fastify.inject({
|
|
1623
|
+
method: 'post',
|
|
1624
|
+
url: '/no/not-found',
|
|
1625
|
+
payload: { hello: 'world' }
|
|
1626
|
+
})
|
|
1583
1627
|
|
|
1584
|
-
fastify.inject({
|
|
1585
|
-
method: 'post',
|
|
1586
|
-
url: '/no/not-found',
|
|
1587
|
-
payload: { hello: 'world' }
|
|
1588
|
-
}, (err, res) => {
|
|
1589
|
-
t.error(err)
|
|
1590
1628
|
const payload = JSON.parse(res.payload)
|
|
1591
|
-
t.
|
|
1592
|
-
}
|
|
1629
|
+
t.assert.deepStrictEqual(payload, { check: 'a', hello: 'world' })
|
|
1630
|
+
}
|
|
1593
1631
|
})
|
|
1594
1632
|
|
|
1595
|
-
t.test('preHandler option should keep the context', t => {
|
|
1633
|
+
await t.test('preHandler option should keep the context', (t, done) => {
|
|
1596
1634
|
t.plan(3)
|
|
1597
1635
|
const fastify = Fastify()
|
|
1598
1636
|
|
|
@@ -1600,7 +1638,7 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1600
1638
|
|
|
1601
1639
|
fastify.setNotFoundHandler({
|
|
1602
1640
|
preHandler: function (req, reply, done) {
|
|
1603
|
-
t.
|
|
1641
|
+
t.assert.strictEqual(this.foo, 42)
|
|
1604
1642
|
this.foo += 1
|
|
1605
1643
|
req.body.foo = this.foo
|
|
1606
1644
|
done()
|
|
@@ -1614,14 +1652,15 @@ test('preHandler option for setNotFoundHandler', t => {
|
|
|
1614
1652
|
url: '/not-found',
|
|
1615
1653
|
payload: { hello: 'world' }
|
|
1616
1654
|
}, (err, res) => {
|
|
1617
|
-
t.
|
|
1655
|
+
t.assert.ifError(err)
|
|
1618
1656
|
const payload = JSON.parse(res.payload)
|
|
1619
|
-
t.
|
|
1657
|
+
t.assert.deepStrictEqual(payload, { foo: 43, hello: 'world' })
|
|
1658
|
+
done()
|
|
1620
1659
|
})
|
|
1621
1660
|
})
|
|
1622
1661
|
})
|
|
1623
1662
|
|
|
1624
|
-
test('reply.notFound invoked the notFound handler', t => {
|
|
1663
|
+
test('reply.notFound invoked the notFound handler', (t, done) => {
|
|
1625
1664
|
t.plan(3)
|
|
1626
1665
|
|
|
1627
1666
|
const fastify = Fastify()
|
|
@@ -1638,30 +1677,31 @@ test('reply.notFound invoked the notFound handler', t => {
|
|
|
1638
1677
|
url: '/',
|
|
1639
1678
|
method: 'GET'
|
|
1640
1679
|
}, (err, res) => {
|
|
1641
|
-
t.
|
|
1642
|
-
t.
|
|
1643
|
-
t.
|
|
1680
|
+
t.assert.ifError(err)
|
|
1681
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1682
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
1644
1683
|
error: 'Not Found',
|
|
1645
1684
|
message: 'kaboom',
|
|
1646
1685
|
statusCode: 404
|
|
1647
1686
|
})
|
|
1687
|
+
done()
|
|
1648
1688
|
})
|
|
1649
1689
|
})
|
|
1650
1690
|
|
|
1651
|
-
test('The custom error handler should be invoked after the custom not found handler', t => {
|
|
1691
|
+
test('The custom error handler should be invoked after the custom not found handler', (t, done) => {
|
|
1652
1692
|
t.plan(6)
|
|
1653
1693
|
|
|
1654
1694
|
const fastify = Fastify()
|
|
1655
1695
|
const order = [1, 2]
|
|
1656
1696
|
|
|
1657
1697
|
fastify.setErrorHandler((err, req, reply) => {
|
|
1658
|
-
t.
|
|
1659
|
-
t.
|
|
1698
|
+
t.assert.strictEqual(order.shift(), 2)
|
|
1699
|
+
t.assert.ok(err instanceof Error)
|
|
1660
1700
|
reply.send(err)
|
|
1661
1701
|
})
|
|
1662
1702
|
|
|
1663
1703
|
fastify.setNotFoundHandler((req, reply) => {
|
|
1664
|
-
t.
|
|
1704
|
+
t.assert.strictEqual(order.shift(), 1)
|
|
1665
1705
|
reply.code(404).send(new Error('kaboom'))
|
|
1666
1706
|
})
|
|
1667
1707
|
|
|
@@ -1673,23 +1713,24 @@ test('The custom error handler should be invoked after the custom not found hand
|
|
|
1673
1713
|
url: '/',
|
|
1674
1714
|
method: 'GET'
|
|
1675
1715
|
}, (err, res) => {
|
|
1676
|
-
t.
|
|
1677
|
-
t.
|
|
1678
|
-
t.
|
|
1716
|
+
t.assert.ifError(err)
|
|
1717
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1718
|
+
t.assert.deepStrictEqual(JSON.parse(res.payload), {
|
|
1679
1719
|
error: 'Not Found',
|
|
1680
1720
|
message: 'kaboom',
|
|
1681
1721
|
statusCode: 404
|
|
1682
1722
|
})
|
|
1723
|
+
done()
|
|
1683
1724
|
})
|
|
1684
1725
|
})
|
|
1685
1726
|
|
|
1686
|
-
test('If the custom not found handler does not use an Error, the custom error handler should not be called', t => {
|
|
1727
|
+
test('If the custom not found handler does not use an Error, the custom error handler should not be called', (t, done) => {
|
|
1687
1728
|
t.plan(3)
|
|
1688
1729
|
|
|
1689
1730
|
const fastify = Fastify()
|
|
1690
1731
|
|
|
1691
1732
|
fastify.setErrorHandler((_err, req, reply) => {
|
|
1692
|
-
t.fail('Should not be called')
|
|
1733
|
+
t.assert.fail('Should not be called')
|
|
1693
1734
|
})
|
|
1694
1735
|
|
|
1695
1736
|
fastify.setNotFoundHandler((req, reply) => {
|
|
@@ -1704,13 +1745,14 @@ test('If the custom not found handler does not use an Error, the custom error ha
|
|
|
1704
1745
|
url: '/',
|
|
1705
1746
|
method: 'GET'
|
|
1706
1747
|
}, (err, res) => {
|
|
1707
|
-
t.
|
|
1708
|
-
t.
|
|
1709
|
-
t.
|
|
1748
|
+
t.assert.ifError(err)
|
|
1749
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1750
|
+
t.assert.strictEqual(res.payload, 'kaboom')
|
|
1751
|
+
done()
|
|
1710
1752
|
})
|
|
1711
1753
|
})
|
|
1712
1754
|
|
|
1713
|
-
test('preValidation option', t => {
|
|
1755
|
+
test('preValidation option', (t, done) => {
|
|
1714
1756
|
t.plan(3)
|
|
1715
1757
|
const fastify = Fastify()
|
|
1716
1758
|
|
|
@@ -1718,7 +1760,7 @@ test('preValidation option', t => {
|
|
|
1718
1760
|
|
|
1719
1761
|
fastify.setNotFoundHandler({
|
|
1720
1762
|
preValidation: function (req, reply, done) {
|
|
1721
|
-
t.ok(this.foo)
|
|
1763
|
+
t.assert.ok(this.foo)
|
|
1722
1764
|
done()
|
|
1723
1765
|
}
|
|
1724
1766
|
}, function (req, reply) {
|
|
@@ -1730,24 +1772,25 @@ test('preValidation option', t => {
|
|
|
1730
1772
|
url: '/not-found',
|
|
1731
1773
|
payload: { hello: 'world' }
|
|
1732
1774
|
}, (err, res) => {
|
|
1733
|
-
t.
|
|
1775
|
+
t.assert.ifError(err)
|
|
1734
1776
|
const payload = JSON.parse(res.payload)
|
|
1735
|
-
t.
|
|
1777
|
+
t.assert.deepStrictEqual(payload, { hello: 'world' })
|
|
1778
|
+
done()
|
|
1736
1779
|
})
|
|
1737
1780
|
})
|
|
1738
1781
|
|
|
1739
|
-
|
|
1782
|
+
test('preValidation option could accept an array of functions', (t, done) => {
|
|
1740
1783
|
t.plan(4)
|
|
1741
1784
|
const fastify = Fastify()
|
|
1742
1785
|
|
|
1743
1786
|
fastify.setNotFoundHandler({
|
|
1744
1787
|
preValidation: [
|
|
1745
1788
|
(req, reply, done) => {
|
|
1746
|
-
t.ok('called')
|
|
1789
|
+
t.assert.ok('called')
|
|
1747
1790
|
done()
|
|
1748
1791
|
},
|
|
1749
1792
|
(req, reply, done) => {
|
|
1750
|
-
t.ok('called')
|
|
1793
|
+
t.assert.ok('called')
|
|
1751
1794
|
done()
|
|
1752
1795
|
}
|
|
1753
1796
|
]
|
|
@@ -1760,13 +1803,14 @@ t.test('preValidation option could accept an array of functions', t => {
|
|
|
1760
1803
|
url: '/not-found',
|
|
1761
1804
|
payload: { hello: 'world' }
|
|
1762
1805
|
}, (err, res) => {
|
|
1763
|
-
t.
|
|
1806
|
+
t.assert.ifError(err)
|
|
1764
1807
|
const payload = JSON.parse(res.payload)
|
|
1765
|
-
t.
|
|
1808
|
+
t.assert.deepStrictEqual(payload, { hello: 'world' })
|
|
1809
|
+
done()
|
|
1766
1810
|
})
|
|
1767
1811
|
})
|
|
1768
1812
|
|
|
1769
|
-
test('Should fail to invoke callNotFound inside a 404 handler', t => {
|
|
1813
|
+
test('Should fail to invoke callNotFound inside a 404 handler', (t, done) => {
|
|
1770
1814
|
t.plan(5)
|
|
1771
1815
|
|
|
1772
1816
|
let fastify = null
|
|
@@ -1779,7 +1823,7 @@ test('Should fail to invoke callNotFound inside a 404 handler', t => {
|
|
|
1779
1823
|
}
|
|
1780
1824
|
})
|
|
1781
1825
|
} catch (e) {
|
|
1782
|
-
t.fail()
|
|
1826
|
+
t.assert.fail()
|
|
1783
1827
|
}
|
|
1784
1828
|
|
|
1785
1829
|
fastify.setNotFoundHandler((req, reply) => {
|
|
@@ -1791,95 +1835,100 @@ test('Should fail to invoke callNotFound inside a 404 handler', t => {
|
|
|
1791
1835
|
})
|
|
1792
1836
|
|
|
1793
1837
|
logStream.once('data', line => {
|
|
1794
|
-
t.
|
|
1795
|
-
t.
|
|
1838
|
+
t.assert.strictEqual(line.msg, 'Trying to send a NotFound error inside a 404 handler. Sending basic 404 response.')
|
|
1839
|
+
t.assert.strictEqual(line.level, 40)
|
|
1796
1840
|
})
|
|
1797
1841
|
|
|
1798
1842
|
fastify.inject({
|
|
1799
1843
|
url: '/',
|
|
1800
1844
|
method: 'GET'
|
|
1801
1845
|
}, (err, res) => {
|
|
1802
|
-
t.
|
|
1803
|
-
t.
|
|
1804
|
-
t.
|
|
1846
|
+
t.assert.ifError(err)
|
|
1847
|
+
t.assert.strictEqual(res.statusCode, 404)
|
|
1848
|
+
t.assert.strictEqual(res.payload, '404 Not Found')
|
|
1849
|
+
done()
|
|
1805
1850
|
})
|
|
1806
1851
|
})
|
|
1807
1852
|
|
|
1808
|
-
test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => {
|
|
1809
|
-
t.test('Dynamic route', t => {
|
|
1853
|
+
test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', async t => {
|
|
1854
|
+
await t.test('Dynamic route', (t, done) => {
|
|
1810
1855
|
t.plan(3)
|
|
1811
1856
|
const fastify = Fastify()
|
|
1812
|
-
fastify.get('/hello/:id', () => t.fail('we should not be here'))
|
|
1857
|
+
fastify.get('/hello/:id', () => t.assert.fail('we should not be here'))
|
|
1813
1858
|
fastify.inject({
|
|
1814
1859
|
url: '/hello/%world',
|
|
1815
1860
|
method: 'GET'
|
|
1816
1861
|
}, (err, response) => {
|
|
1817
|
-
t.
|
|
1818
|
-
t.
|
|
1819
|
-
t.
|
|
1862
|
+
t.assert.ifError(err)
|
|
1863
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
1864
|
+
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
|
1820
1865
|
error: 'Bad Request',
|
|
1821
1866
|
message: "'/hello/%world' is not a valid url component",
|
|
1822
1867
|
statusCode: 400,
|
|
1823
1868
|
code: 'FST_ERR_BAD_URL'
|
|
1824
1869
|
})
|
|
1870
|
+
done()
|
|
1825
1871
|
})
|
|
1826
1872
|
})
|
|
1827
1873
|
|
|
1828
|
-
t.test('Wildcard', t => {
|
|
1874
|
+
await t.test('Wildcard', (t, done) => {
|
|
1829
1875
|
t.plan(3)
|
|
1830
1876
|
const fastify = Fastify()
|
|
1831
|
-
fastify.get('*', () => t.fail('we should not be here'))
|
|
1877
|
+
fastify.get('*', () => t.assert.fail('we should not be here'))
|
|
1832
1878
|
fastify.inject({
|
|
1833
1879
|
url: '/hello/%world',
|
|
1834
1880
|
method: 'GET'
|
|
1835
1881
|
}, (err, response) => {
|
|
1836
|
-
t.
|
|
1837
|
-
t.
|
|
1838
|
-
t.
|
|
1882
|
+
t.assert.ifError(err)
|
|
1883
|
+
t.assert.strictEqual(response.statusCode, 400)
|
|
1884
|
+
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
|
1839
1885
|
error: 'Bad Request',
|
|
1840
1886
|
message: "'/hello/%world' is not a valid url component",
|
|
1841
1887
|
statusCode: 400,
|
|
1842
1888
|
code: 'FST_ERR_BAD_URL'
|
|
1843
1889
|
})
|
|
1890
|
+
done()
|
|
1844
1891
|
})
|
|
1845
1892
|
})
|
|
1846
1893
|
|
|
1847
|
-
t.test('No route registered', t => {
|
|
1894
|
+
await t.test('No route registered', (t, done) => {
|
|
1848
1895
|
t.plan(3)
|
|
1849
1896
|
const fastify = Fastify()
|
|
1850
1897
|
fastify.inject({
|
|
1851
1898
|
url: '/%c0',
|
|
1852
1899
|
method: 'GET'
|
|
1853
1900
|
}, (err, response) => {
|
|
1854
|
-
t.
|
|
1855
|
-
t.
|
|
1856
|
-
t.
|
|
1901
|
+
t.assert.ifError(err)
|
|
1902
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1903
|
+
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
|
1857
1904
|
error: 'Not Found',
|
|
1858
1905
|
message: 'Route GET:/%c0 not found',
|
|
1859
1906
|
statusCode: 404
|
|
1860
1907
|
})
|
|
1908
|
+
done()
|
|
1861
1909
|
})
|
|
1862
1910
|
})
|
|
1863
1911
|
|
|
1864
|
-
t.test('Only / is registered', t => {
|
|
1912
|
+
await t.test('Only / is registered', (t, done) => {
|
|
1865
1913
|
t.plan(3)
|
|
1866
1914
|
const fastify = Fastify()
|
|
1867
|
-
fastify.get('/', () => t.fail('we should not be here'))
|
|
1915
|
+
fastify.get('/', () => t.assert.fail('we should not be here'))
|
|
1868
1916
|
fastify.inject({
|
|
1869
1917
|
url: '/non-existing',
|
|
1870
1918
|
method: 'GET'
|
|
1871
1919
|
}, (err, response) => {
|
|
1872
|
-
t.
|
|
1873
|
-
t.
|
|
1874
|
-
t.
|
|
1920
|
+
t.assert.ifError(err)
|
|
1921
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1922
|
+
t.assert.deepStrictEqual(JSON.parse(response.payload), {
|
|
1875
1923
|
error: 'Not Found',
|
|
1876
1924
|
message: 'Route GET:/non-existing not found',
|
|
1877
1925
|
statusCode: 404
|
|
1878
1926
|
})
|
|
1927
|
+
done()
|
|
1879
1928
|
})
|
|
1880
1929
|
})
|
|
1881
1930
|
|
|
1882
|
-
t.test('customized 404', t => {
|
|
1931
|
+
await t.test('customized 404', (t, done) => {
|
|
1883
1932
|
t.plan(3)
|
|
1884
1933
|
const fastify = Fastify({ logger: true })
|
|
1885
1934
|
fastify.setNotFoundHandler(function (req, reply) {
|
|
@@ -1889,18 +1938,17 @@ test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => {
|
|
|
1889
1938
|
url: '/%c0',
|
|
1890
1939
|
method: 'GET'
|
|
1891
1940
|
}, (err, response) => {
|
|
1892
|
-
t.
|
|
1893
|
-
t.
|
|
1894
|
-
t.
|
|
1941
|
+
t.assert.ifError(err)
|
|
1942
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1943
|
+
t.assert.deepStrictEqual(response.payload, 'this was not found')
|
|
1944
|
+
done()
|
|
1895
1945
|
})
|
|
1896
1946
|
})
|
|
1897
|
-
|
|
1898
|
-
t.end()
|
|
1899
1947
|
})
|
|
1900
1948
|
|
|
1901
|
-
test('setNotFoundHandler should be chaining fastify instance', t => {
|
|
1902
|
-
t.test('Register route after setNotFoundHandler', t => {
|
|
1903
|
-
t.plan(
|
|
1949
|
+
test('setNotFoundHandler should be chaining fastify instance', async t => {
|
|
1950
|
+
await t.test('Register route after setNotFoundHandler', async t => {
|
|
1951
|
+
t.plan(4)
|
|
1904
1952
|
const fastify = Fastify()
|
|
1905
1953
|
fastify.setNotFoundHandler(function (_req, reply) {
|
|
1906
1954
|
reply.code(404).send('this was not found')
|
|
@@ -1908,52 +1956,50 @@ test('setNotFoundHandler should be chaining fastify instance', t => {
|
|
|
1908
1956
|
reply.send('valid route')
|
|
1909
1957
|
})
|
|
1910
1958
|
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
t.
|
|
1917
|
-
t.
|
|
1918
|
-
}
|
|
1959
|
+
{
|
|
1960
|
+
const response = await fastify.inject({
|
|
1961
|
+
url: '/invalid-route',
|
|
1962
|
+
method: 'GET'
|
|
1963
|
+
})
|
|
1964
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1965
|
+
t.assert.strictEqual(response.payload, 'this was not found')
|
|
1966
|
+
}
|
|
1919
1967
|
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
t.equal(response.statusCode, 200)
|
|
1926
|
-
t.equal(response.payload, 'valid route')
|
|
1927
|
-
})
|
|
1928
|
-
})
|
|
1968
|
+
{
|
|
1969
|
+
const response = await fastify.inject({
|
|
1970
|
+
url: '/valid-route',
|
|
1971
|
+
method: 'GET'
|
|
1972
|
+
})
|
|
1929
1973
|
|
|
1930
|
-
|
|
1974
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
1975
|
+
t.assert.strictEqual(response.payload, 'valid route')
|
|
1976
|
+
}
|
|
1977
|
+
})
|
|
1931
1978
|
})
|
|
1932
1979
|
|
|
1933
|
-
test('Send 404 when frameworkError calls reply.callNotFound', t => {
|
|
1934
|
-
t.test('Dynamic route', t => {
|
|
1980
|
+
test('Send 404 when frameworkError calls reply.callNotFound', async t => {
|
|
1981
|
+
await t.test('Dynamic route', (t, done) => {
|
|
1935
1982
|
t.plan(4)
|
|
1936
1983
|
const fastify = Fastify({
|
|
1937
1984
|
frameworkErrors: (error, req, reply) => {
|
|
1938
|
-
t.
|
|
1985
|
+
t.assert.strictEqual(error.message, "'/hello/%world' is not a valid url component")
|
|
1939
1986
|
return reply.callNotFound()
|
|
1940
1987
|
}
|
|
1941
1988
|
})
|
|
1942
|
-
fastify.get('/hello/:id', () => t.fail('we should not be here'))
|
|
1989
|
+
fastify.get('/hello/:id', () => t.assert.fail('we should not be here'))
|
|
1943
1990
|
fastify.inject({
|
|
1944
1991
|
url: '/hello/%world',
|
|
1945
1992
|
method: 'GET'
|
|
1946
1993
|
}, (err, response) => {
|
|
1947
|
-
t.
|
|
1948
|
-
t.
|
|
1949
|
-
t.
|
|
1994
|
+
t.assert.ifError(err)
|
|
1995
|
+
t.assert.strictEqual(response.statusCode, 404)
|
|
1996
|
+
t.assert.strictEqual(response.payload, '404 Not Found')
|
|
1997
|
+
done()
|
|
1950
1998
|
})
|
|
1951
1999
|
})
|
|
1952
|
-
|
|
1953
|
-
t.end()
|
|
1954
2000
|
})
|
|
1955
2001
|
|
|
1956
|
-
test('hooks are applied to not found handlers /1', async
|
|
2002
|
+
test('hooks are applied to not found handlers /1', async t => {
|
|
1957
2003
|
const fastify = Fastify()
|
|
1958
2004
|
|
|
1959
2005
|
// adding await here is fundamental for this test
|
|
@@ -1969,10 +2015,10 @@ test('hooks are applied to not found handlers /1', async ({ equal }) => {
|
|
|
1969
2015
|
})
|
|
1970
2016
|
|
|
1971
2017
|
const { statusCode } = await fastify.inject('/')
|
|
1972
|
-
|
|
2018
|
+
t.assert.strictEqual(statusCode, 401)
|
|
1973
2019
|
})
|
|
1974
2020
|
|
|
1975
|
-
test('hooks are applied to not found handlers /2', async
|
|
2021
|
+
test('hooks are applied to not found handlers /2', async t => {
|
|
1976
2022
|
const fastify = Fastify()
|
|
1977
2023
|
|
|
1978
2024
|
async function plugin (fastify) {
|
|
@@ -1990,15 +2036,15 @@ test('hooks are applied to not found handlers /2', async ({ equal }) => {
|
|
|
1990
2036
|
})
|
|
1991
2037
|
|
|
1992
2038
|
const { statusCode } = await fastify.inject('/')
|
|
1993
|
-
|
|
2039
|
+
t.assert.strictEqual(statusCode, 401)
|
|
1994
2040
|
})
|
|
1995
2041
|
|
|
1996
|
-
test('hooks are applied to not found handlers /3', async
|
|
2042
|
+
test('hooks are applied to not found handlers /3', async t => {
|
|
1997
2043
|
const fastify = Fastify()
|
|
1998
2044
|
|
|
1999
2045
|
async function plugin (fastify) {
|
|
2000
2046
|
fastify.setNotFoundHandler({ errorHandler }, async () => {
|
|
2001
|
-
fail('this should never be called')
|
|
2047
|
+
t.assert.fail('this should never be called')
|
|
2002
2048
|
})
|
|
2003
2049
|
|
|
2004
2050
|
function errorHandler (_, request, reply) {
|
|
@@ -2015,5 +2061,5 @@ test('hooks are applied to not found handlers /3', async ({ equal, fail }) => {
|
|
|
2015
2061
|
})
|
|
2016
2062
|
|
|
2017
2063
|
const { statusCode } = await fastify.inject('/')
|
|
2018
|
-
|
|
2064
|
+
t.assert.strictEqual(statusCode, 401)
|
|
2019
2065
|
})
|