Skip to content

Commit

Permalink
chore: bump find-my-way to 5.1.0 (#3515)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Dec 9, 2021
1 parent e488a09 commit b045c7e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
"fast-json-stringify": "^2.7.9",
"fastify-error": "^0.3.1",
"fastify-warning": "^0.2.0",
"find-my-way": "^4.3.3",
"find-my-way": "^5.1.0",
"light-my-request": "^4.4.4",
"pino": "^7.0.3",
"proxy-addr": "^2.0.7",
Expand Down
63 changes: 36 additions & 27 deletions test/404s.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const errors = require('http-errors')
const split = require('split2')
const Fastify = require('..')

function getUrl (app) {
const { address, port } = app.server.address()
if (address === '::1') {
return `http://[${address}]:${port}`
} else {
return `http://${address}:${port}`
}
}

test('default 404', t => {
t.plan(3)

Expand All @@ -28,7 +37,7 @@ test('default 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: {},
json: true
}, (err, response, body) => {
Expand All @@ -42,7 +51,7 @@ test('default 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/notSupported',
url: getUrl(fastify) + '/notSupported',
body: {},
json: true
}, (err, response, body) => {
Expand Down Expand Up @@ -87,7 +96,7 @@ test('customized 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -101,7 +110,7 @@ test('customized 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/notSupported'
url: getUrl(fastify) + '/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand All @@ -113,7 +122,7 @@ test('customized 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/with-error'
url: getUrl(fastify) + '/with-error'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand All @@ -129,7 +138,7 @@ test('customized 404', t => {
t.plan(4)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/with-error-custom-header'
url: getUrl(fastify) + '/with-error-custom-header'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -163,7 +172,7 @@ test('custom header in notFound handler', t => {
t.plan(4)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/notSupported'
url: getUrl(fastify) + '/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -350,7 +359,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -364,7 +373,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/notSupported'
url: getUrl(fastify) + '/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand All @@ -376,7 +385,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port + '/test',
url: getUrl(fastify) + '/test',
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -390,7 +399,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/test/notSupported'
url: getUrl(fastify) + '/test/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand All @@ -402,7 +411,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port + '/test2',
url: getUrl(fastify) + '/test2',
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -416,7 +425,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/test2/notSupported'
url: getUrl(fastify) + '/test2/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand All @@ -428,7 +437,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port + '/test3/',
url: getUrl(fastify) + '/test3/',
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -442,7 +451,7 @@ test('encapsulated 404', t => {
t.plan(3)
sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/test3/notSupported'
url: getUrl(fastify) + '/test3/notSupported'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -606,7 +615,7 @@ test('run hooks on default 404', t => {

sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port,
url: getUrl(fastify),
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand Down Expand Up @@ -767,7 +776,7 @@ test('run hook with encapsulated 404', t => {

sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port + '/test',
url: getUrl(fastify) + '/test',
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand Down Expand Up @@ -807,7 +816,7 @@ test('hooks check 404', t => {

sget({
method: 'PUT',
url: 'http://localhost:' + fastify.server.address().port + '?foo=asd',
url: getUrl(fastify) + '?foo=asd',
body: JSON.stringify({ hello: 'world' }),
headers: { 'Content-Type': 'application/json' }
}, (err, response, body) => {
Expand All @@ -817,7 +826,7 @@ test('hooks check 404', t => {

sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port + '/notSupported?foo=asd'
url: getUrl(fastify) + '/notSupported?foo=asd'
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -914,7 +923,7 @@ test('Unknown method', t => {

sget({
method: 'UNKNWON_METHOD',
url: 'http://localhost:' + fastify.server.address().port
url: getUrl(fastify)
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 400)
Expand Down Expand Up @@ -948,7 +957,7 @@ test('recognizes errors from the http-errors module', t => {
t.error(err)
t.equal(res.statusCode, 404)

sget('http://localhost:' + fastify.server.address().port, (err, response, body) => {
sget(getUrl(fastify), (err, response, body) => {
t.error(err)
const obj = JSON.parse(body.toString())
t.strictSame(obj, {
Expand Down Expand Up @@ -1095,7 +1104,7 @@ test('404 inside onSend', t => {

sget({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port
url: getUrl(fastify)
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -1126,7 +1135,7 @@ test('Not found on supported method (should return a 404)', t => {

sget({
method: 'POST',
url: 'http://localhost:' + fastify.server.address().port
url: getUrl(fastify)
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -1159,7 +1168,7 @@ test('Not found on unsupported method (should return a 404)', t => {

sget({
method: 'PROPFIND',
url: 'http://localhost:' + fastify.server.address().port
url: getUrl(fastify)
}, (err, response, body) => {
t.error(err)
t.equal(response.statusCode, 404)
Expand Down Expand Up @@ -1714,7 +1723,7 @@ test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => {
t.equal(response.statusCode, 400)
t.same(JSON.parse(response.payload), {
error: 'Bad Request',
message: "'%world' is not a valid url component",
message: "'/hello/%world' is not a valid url component",
statusCode: 400
})
})
Expand Down Expand Up @@ -1760,14 +1769,14 @@ test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => {
const fastify = Fastify()
fastify.get('/', () => t.fail('we should not be here'))
fastify.inject({
url: '/%c0',
url: '/non-existing',
method: 'GET'
}, (err, response) => {
t.error(err)
t.equal(response.statusCode, 404)
t.same(JSON.parse(response.payload), {
error: 'Not Found',
message: 'Route GET:/%c0 not found',
message: 'Route GET:/non-existing not found',
statusCode: 404
})
})
Expand Down

0 comments on commit b045c7e

Please sign in to comment.