fastify 5.3.1 → 5.3.2
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/docs/Guides/Benchmarking.md +1 -1
- package/fastify.js +1 -1
- package/lib/validation.js +1 -1
- package/package.json +1 -1
- package/test/schema-validation.test.js +31 -15
- package/.vscode/settings.json +0 -22
|
@@ -12,7 +12,7 @@ The modules we will use:
|
|
|
12
12
|
tool written in node.
|
|
13
13
|
- [Branch-comparer](https://github.com/StarpTech/branch-comparer): Checkout
|
|
14
14
|
multiple git branches, execute scripts, and log the results.
|
|
15
|
-
- [Concurrently](https://github.com/
|
|
15
|
+
- [Concurrently](https://github.com/open-cli-tools/concurrently): Run commands
|
|
16
16
|
concurrently.
|
|
17
17
|
- [Npx](https://github.com/npm/npx): NPM package runner used to run scripts
|
|
18
18
|
against different Node.js Versions and execute local binaries. Shipped with
|
package/fastify.js
CHANGED
package/lib/validation.js
CHANGED
|
@@ -261,7 +261,7 @@ function wrapValidationError (result, dataVar, schemaErrorFormatter) {
|
|
|
261
261
|
*/
|
|
262
262
|
function getEssenceMediaType (header) {
|
|
263
263
|
if (!header) return ''
|
|
264
|
-
return header.split(
|
|
264
|
+
return header.split(/[ ;]/, 1)[0].trim().toLowerCase()
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { test } = require('tap')
|
|
4
4
|
const Fastify = require('..')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
|
|
6
7
|
const AJV = require('ajv')
|
|
7
8
|
const Schema = require('fluent-json-schema')
|
|
@@ -1342,7 +1343,7 @@ test('Schema validation when no content type is provided', async t => {
|
|
|
1342
1343
|
})
|
|
1343
1344
|
|
|
1344
1345
|
test('Schema validation will not be bypass by different content type', async t => {
|
|
1345
|
-
t.plan(
|
|
1346
|
+
t.plan(10)
|
|
1346
1347
|
|
|
1347
1348
|
const fastify = Fastify()
|
|
1348
1349
|
|
|
@@ -1365,58 +1366,73 @@ test('Schema validation will not be bypass by different content type', async t =
|
|
|
1365
1366
|
}
|
|
1366
1367
|
}, async () => 'ok')
|
|
1367
1368
|
|
|
1368
|
-
await fastify.
|
|
1369
|
+
await fastify.listen({ port: 0 })
|
|
1370
|
+
t.teardown(() => fastify.close())
|
|
1371
|
+
const address = fastify.listeningOrigin
|
|
1369
1372
|
|
|
1370
|
-
const correct1 = await
|
|
1373
|
+
const correct1 = await request(address, {
|
|
1371
1374
|
method: 'POST',
|
|
1372
1375
|
url: '/',
|
|
1373
1376
|
headers: {
|
|
1374
1377
|
'content-type': 'application/json'
|
|
1375
1378
|
},
|
|
1376
|
-
body: { foo: 'string' }
|
|
1379
|
+
body: JSON.stringify({ foo: 'string' })
|
|
1377
1380
|
})
|
|
1378
1381
|
t.equal(correct1.statusCode, 200)
|
|
1382
|
+
await correct1.body.dump()
|
|
1379
1383
|
|
|
1380
|
-
const correct2 = await
|
|
1384
|
+
const correct2 = await request(address, {
|
|
1381
1385
|
method: 'POST',
|
|
1382
1386
|
url: '/',
|
|
1383
1387
|
headers: {
|
|
1384
1388
|
'content-type': 'application/json; charset=utf-8'
|
|
1385
1389
|
},
|
|
1386
|
-
body: { foo: 'string' }
|
|
1390
|
+
body: JSON.stringify({ foo: 'string' })
|
|
1387
1391
|
})
|
|
1388
1392
|
t.equal(correct2.statusCode, 200)
|
|
1393
|
+
await correct2.body.dump()
|
|
1389
1394
|
|
|
1390
|
-
const invalid1 = await
|
|
1395
|
+
const invalid1 = await request(address, {
|
|
1391
1396
|
method: 'POST',
|
|
1392
1397
|
url: '/',
|
|
1393
1398
|
headers: {
|
|
1394
1399
|
'content-type': 'application/json ;'
|
|
1395
1400
|
},
|
|
1396
|
-
body: { invalid: 'string' }
|
|
1401
|
+
body: JSON.stringify({ invalid: 'string' })
|
|
1397
1402
|
})
|
|
1398
1403
|
t.equal(invalid1.statusCode, 400)
|
|
1399
|
-
t.equal(invalid1.json().code, 'FST_ERR_VALIDATION')
|
|
1404
|
+
t.equal((await invalid1.body.json()).code, 'FST_ERR_VALIDATION')
|
|
1400
1405
|
|
|
1401
|
-
const invalid2 = await
|
|
1406
|
+
const invalid2 = await request(address, {
|
|
1402
1407
|
method: 'POST',
|
|
1403
1408
|
url: '/',
|
|
1404
1409
|
headers: {
|
|
1405
1410
|
'content-type': 'ApPlIcAtIoN/JsOn;'
|
|
1406
1411
|
},
|
|
1407
|
-
body: { invalid: 'string' }
|
|
1412
|
+
body: JSON.stringify({ invalid: 'string' })
|
|
1408
1413
|
})
|
|
1409
1414
|
t.equal(invalid2.statusCode, 400)
|
|
1410
|
-
t.equal(invalid2.json().code, 'FST_ERR_VALIDATION')
|
|
1415
|
+
t.equal((await invalid2.body.json()).code, 'FST_ERR_VALIDATION')
|
|
1411
1416
|
|
|
1412
|
-
const invalid3 = await
|
|
1417
|
+
const invalid3 = await request(address, {
|
|
1413
1418
|
method: 'POST',
|
|
1414
1419
|
url: '/',
|
|
1415
1420
|
headers: {
|
|
1416
1421
|
'content-type': 'ApPlIcAtIoN/JsOn ;'
|
|
1417
1422
|
},
|
|
1418
|
-
body: { invalid: 'string' }
|
|
1423
|
+
body: JSON.stringify({ invalid: 'string' })
|
|
1419
1424
|
})
|
|
1420
1425
|
t.equal(invalid3.statusCode, 400)
|
|
1421
|
-
t.equal(invalid3.json().code, 'FST_ERR_VALIDATION')
|
|
1426
|
+
t.equal((await invalid3.body.json()).code, 'FST_ERR_VALIDATION')
|
|
1427
|
+
|
|
1428
|
+
const invalid4 = await request(address, {
|
|
1429
|
+
method: 'POST',
|
|
1430
|
+
url: '/',
|
|
1431
|
+
headers: {
|
|
1432
|
+
'content-type': 'ApPlIcAtIoN/JsOn foo;'
|
|
1433
|
+
},
|
|
1434
|
+
body: JSON.stringify({ invalid: 'string' })
|
|
1435
|
+
})
|
|
1436
|
+
t.equal(invalid4.statusCode, 400)
|
|
1437
|
+
t.equal((await invalid4.body.json()).code, 'FST_ERR_VALIDATION')
|
|
1422
1438
|
})
|
package/.vscode/settings.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"workbench.colorCustomizations": {
|
|
3
|
-
"[GitHub Dark]": {
|
|
4
|
-
"tab.activeBackground": "#0d0d0d",
|
|
5
|
-
"tab.activeBorder": "#ffff00"
|
|
6
|
-
},
|
|
7
|
-
"activityBar.background": "#FBE7B2",
|
|
8
|
-
"activityBar.foreground": "#52358C",
|
|
9
|
-
"activityBar.inactiveForeground": "#616161",
|
|
10
|
-
"activityBar.activeBorder": "#04184d",
|
|
11
|
-
"activityBar.activeBackground": "#C3B48B",
|
|
12
|
-
"activityBar.border": "#C3B48B",
|
|
13
|
-
"titleBar.activeBackground": "#D2BE88",
|
|
14
|
-
"titleBar.activeForeground": "#52358C",
|
|
15
|
-
"titleBar.inactiveBackground": "#bdb59c",
|
|
16
|
-
"titleBar.inactiveForeground": "#616161",
|
|
17
|
-
"titleBar.border": "#C3B48B",
|
|
18
|
-
"statusBar.background": "#E9DBB7",
|
|
19
|
-
"statusBar.foreground": "#52358C",
|
|
20
|
-
"statusBar.border": "#C3B48B"
|
|
21
|
-
}
|
|
22
|
-
}
|