Projektstart
This commit is contained in:
172
backend/node_modules/fastify/test/http2/closing.test.js
generated
vendored
Normal file
172
backend/node_modules/fastify/test/http2/closing.test.js
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const Fastify = require('../..')
|
||||
const http2 = require('node:http2')
|
||||
const { promisify } = require('node:util')
|
||||
const connect = promisify(http2.connect)
|
||||
const { once } = require('node:events')
|
||||
const { buildCertificate } = require('../build-certificate')
|
||||
const { getServerUrl } = require('../helper')
|
||||
|
||||
t.before(buildCertificate)
|
||||
|
||||
t.test('http/2 request while fastify closing', t => {
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true
|
||||
})
|
||||
t.pass('http2 successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('http2 loading failed', e)
|
||||
}
|
||||
|
||||
fastify.get('/', () => Promise.resolve({}))
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
t.test('return 200', t => {
|
||||
const url = getServerUrl(fastify)
|
||||
const session = http2.connect(url, function () {
|
||||
this.request({
|
||||
':method': 'GET',
|
||||
':path': '/'
|
||||
}).on('response', headers => {
|
||||
t.equal(headers[':status'], 503)
|
||||
t.end()
|
||||
this.destroy()
|
||||
}).on('error', () => {
|
||||
// Nothing to do here,
|
||||
// we are not interested in this error that might
|
||||
// happen or not
|
||||
})
|
||||
fastify.close()
|
||||
})
|
||||
session.on('error', () => {
|
||||
// Nothing to do here,
|
||||
// we are not interested in this error that might
|
||||
// happen or not
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('http/2 request while fastify closing - return503OnClosing: false', t => {
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true,
|
||||
return503OnClosing: false
|
||||
})
|
||||
t.pass('http2 successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('http2 loading failed', e)
|
||||
}
|
||||
|
||||
fastify.get('/', () => Promise.resolve({}))
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
t.test('return 200', t => {
|
||||
const url = getServerUrl(fastify)
|
||||
const session = http2.connect(url, function () {
|
||||
this.request({
|
||||
':method': 'GET',
|
||||
':path': '/'
|
||||
}).on('response', headers => {
|
||||
t.equal(headers[':status'], 200)
|
||||
t.end()
|
||||
this.destroy()
|
||||
}).on('error', () => {
|
||||
// Nothing to do here,
|
||||
// we are not interested in this error that might
|
||||
// happen or not
|
||||
})
|
||||
fastify.close()
|
||||
})
|
||||
session.on('error', () => {
|
||||
// Nothing to do here,
|
||||
// we are not interested in this error that might
|
||||
// happen or not
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('http/2 closes successfully with async await', async t => {
|
||||
const fastify = Fastify({
|
||||
http2SessionTimeout: 100,
|
||||
http2: true
|
||||
})
|
||||
|
||||
await fastify.listen({ port: 0 })
|
||||
|
||||
const url = getServerUrl(fastify)
|
||||
const session = await connect(url)
|
||||
// An error might or might not happen, as it's OS dependent.
|
||||
session.on('error', () => {})
|
||||
await fastify.close()
|
||||
})
|
||||
|
||||
t.test('https/2 closes successfully with async await', async t => {
|
||||
const fastify = Fastify({
|
||||
http2SessionTimeout: 100,
|
||||
http2: true,
|
||||
https: {
|
||||
key: global.context.key,
|
||||
cert: global.context.cert
|
||||
}
|
||||
})
|
||||
|
||||
await fastify.listen({ port: 0 })
|
||||
|
||||
const url = getServerUrl(fastify)
|
||||
const session = await connect(url)
|
||||
// An error might or might not happen, as it's OS dependent.
|
||||
session.on('error', () => {})
|
||||
await fastify.close()
|
||||
})
|
||||
|
||||
t.test('http/2 server side session emits a timeout event', async t => {
|
||||
let _resolve
|
||||
const p = new Promise((resolve) => { _resolve = resolve })
|
||||
|
||||
const fastify = Fastify({
|
||||
http2SessionTimeout: 100,
|
||||
http2: true
|
||||
})
|
||||
|
||||
fastify.get('/', async (req) => {
|
||||
req.raw.stream.session.on('timeout', () => _resolve())
|
||||
return {}
|
||||
})
|
||||
|
||||
await fastify.listen({ port: 0 })
|
||||
|
||||
const url = getServerUrl(fastify)
|
||||
const session = await connect(url)
|
||||
const req = session.request({
|
||||
':method': 'GET',
|
||||
':path': '/'
|
||||
}).end()
|
||||
|
||||
const [headers] = await once(req, 'response')
|
||||
t.equal(headers[':status'], 200)
|
||||
req.resume()
|
||||
|
||||
// An error might or might not happen, as it's OS dependent.
|
||||
session.on('error', () => {})
|
||||
await p
|
||||
await fastify.close()
|
||||
})
|
||||
91
backend/node_modules/fastify/test/http2/constraint.test.js
generated
vendored
Normal file
91
backend/node_modules/fastify/test/http2/constraint.test.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
|
||||
const alpha = { res: 'alpha' }
|
||||
const beta = { res: 'beta' }
|
||||
|
||||
const { buildCertificate } = require('../build-certificate')
|
||||
t.before(buildCertificate)
|
||||
|
||||
test('A route supports host constraints under http2 protocol and secure connection', (t) => {
|
||||
t.plan(5)
|
||||
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true,
|
||||
https: {
|
||||
key: global.context.key,
|
||||
cert: global.context.cert
|
||||
}
|
||||
})
|
||||
t.pass('Key/cert successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('Key/cert loading failed', e)
|
||||
}
|
||||
|
||||
const constrain = 'fastify.dev'
|
||||
|
||||
fastify.route({
|
||||
method: 'GET',
|
||||
url: '/',
|
||||
handler: function (_, reply) {
|
||||
reply.code(200).send(alpha)
|
||||
}
|
||||
})
|
||||
fastify.route({
|
||||
method: 'GET',
|
||||
url: '/beta',
|
||||
constraints: { host: constrain },
|
||||
handler: function (_, reply) {
|
||||
reply.code(200).send(beta)
|
||||
}
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
t.test('https get request - no constrain', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.equal(res.headers['content-length'], '' + JSON.stringify(alpha).length)
|
||||
t.same(JSON.parse(res.body), alpha)
|
||||
})
|
||||
|
||||
t.test('https get request - constrain', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}/beta`
|
||||
const res = await h2url.concat({
|
||||
url,
|
||||
headers: {
|
||||
':authority': constrain
|
||||
}
|
||||
})
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.equal(res.headers['content-length'], '' + JSON.stringify(beta).length)
|
||||
t.same(JSON.parse(res.body), beta)
|
||||
})
|
||||
|
||||
t.test('https get request - constrain - not found', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}/beta`
|
||||
const res = await h2url.concat({
|
||||
url
|
||||
})
|
||||
|
||||
t.equal(res.headers[':status'], 404)
|
||||
})
|
||||
})
|
||||
})
|
||||
35
backend/node_modules/fastify/test/http2/head.test.js
generated
vendored
Normal file
35
backend/node_modules/fastify/test/http2/head.test.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
const msg = { hello: 'world' }
|
||||
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true
|
||||
})
|
||||
t.pass('http2 successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('http2 loading failed', e)
|
||||
}
|
||||
|
||||
fastify.all('/', function (req, reply) {
|
||||
reply.code(200).send(msg)
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
test('http HEAD request', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const url = `http://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url, method: 'HEAD' })
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
})
|
||||
})
|
||||
18
backend/node_modules/fastify/test/http2/missing-http2-module.test.js
generated
vendored
Normal file
18
backend/node_modules/fastify/test/http2/missing-http2-module.test.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const proxyquire = require('proxyquire')
|
||||
const server = proxyquire('../../lib/server', { 'node:http2': null })
|
||||
const Fastify = proxyquire('../..', { './lib/server.js': server })
|
||||
|
||||
test('should throw when http2 module cannot be found', t => {
|
||||
t.plan(2)
|
||||
try {
|
||||
Fastify({ http2: true })
|
||||
t.fail('fastify did not throw expected error')
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'FST_ERR_HTTP2_INVALID_VERSION')
|
||||
t.equal(err.message, 'HTTP2 is available only from node >= 8.8.1')
|
||||
}
|
||||
})
|
||||
53
backend/node_modules/fastify/test/http2/plain.test.js
generated
vendored
Normal file
53
backend/node_modules/fastify/test/http2/plain.test.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
const msg = { hello: 'world' }
|
||||
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true
|
||||
})
|
||||
t.pass('http2 successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('http2 loading failed', e)
|
||||
}
|
||||
|
||||
fastify.get('/', function (req, reply) {
|
||||
reply.code(200).send(msg)
|
||||
})
|
||||
|
||||
fastify.get('/hostname', function (req, reply) {
|
||||
reply.code(200).send(req.hostname)
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
test('http get request', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const url = `http://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length)
|
||||
|
||||
t.same(JSON.parse(res.body), msg)
|
||||
})
|
||||
|
||||
test('http hostname', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const hostname = `localhost:${fastify.server.address().port}`
|
||||
|
||||
const url = `http://${hostname}/hostname`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.body, hostname)
|
||||
})
|
||||
})
|
||||
110
backend/node_modules/fastify/test/http2/secure-with-fallback.test.js
generated
vendored
Normal file
110
backend/node_modules/fastify/test/http2/secure-with-fallback.test.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
const sget = require('simple-get').concat
|
||||
const msg = { hello: 'world' }
|
||||
|
||||
const { buildCertificate } = require('../build-certificate')
|
||||
t.before(buildCertificate)
|
||||
|
||||
test('secure with fallback', (t) => {
|
||||
t.plan(7)
|
||||
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true,
|
||||
https: {
|
||||
allowHTTP1: true,
|
||||
key: global.context.key,
|
||||
cert: global.context.cert
|
||||
}
|
||||
})
|
||||
t.pass('Key/cert successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('Key/cert loading failed', e)
|
||||
}
|
||||
|
||||
fastify.get('/', function (req, reply) {
|
||||
reply.code(200).send(msg)
|
||||
})
|
||||
|
||||
fastify.post('/', function (req, reply) {
|
||||
reply.code(200).send(req.body)
|
||||
})
|
||||
|
||||
fastify.get('/error', async function (req, reply) {
|
||||
throw new Error('kaboom')
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
t.test('https get error', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}/error`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.headers[':status'], 500)
|
||||
})
|
||||
|
||||
t.test('https post', async (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({
|
||||
url,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ hello: 'http2' }),
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.same(JSON.parse(res.body), { hello: 'http2' })
|
||||
})
|
||||
|
||||
t.test('https get request', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length)
|
||||
t.same(JSON.parse(res.body), msg)
|
||||
})
|
||||
|
||||
t.test('http1 get request', t => {
|
||||
t.plan(4)
|
||||
sget({
|
||||
method: 'GET',
|
||||
url: 'https://localhost:' + fastify.server.address().port,
|
||||
rejectUnauthorized: false
|
||||
}, (err, response, body) => {
|
||||
t.error(err)
|
||||
t.equal(response.statusCode, 200)
|
||||
t.equal(response.headers['content-length'], '' + body.length)
|
||||
t.same(JSON.parse(body), { hello: 'world' })
|
||||
})
|
||||
})
|
||||
|
||||
t.test('http1 get error', (t) => {
|
||||
t.plan(2)
|
||||
sget({
|
||||
method: 'GET',
|
||||
url: 'https://localhost:' + fastify.server.address().port + '/error',
|
||||
rejectUnauthorized: false
|
||||
}, (err, response, body) => {
|
||||
t.error(err)
|
||||
t.equal(response.statusCode, 500)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
59
backend/node_modules/fastify/test/http2/secure.test.js
generated
vendored
Normal file
59
backend/node_modules/fastify/test/http2/secure.test.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
const msg = { hello: 'world' }
|
||||
|
||||
const { buildCertificate } = require('../build-certificate')
|
||||
t.before(buildCertificate)
|
||||
|
||||
test('secure', (t) => {
|
||||
t.plan(4)
|
||||
|
||||
let fastify
|
||||
try {
|
||||
fastify = Fastify({
|
||||
http2: true,
|
||||
https: {
|
||||
key: global.context.key,
|
||||
cert: global.context.cert
|
||||
}
|
||||
})
|
||||
t.pass('Key/cert successfully loaded')
|
||||
} catch (e) {
|
||||
t.fail('Key/cert loading failed', e)
|
||||
}
|
||||
|
||||
fastify.get('/', function (req, reply) {
|
||||
reply.code(200).send(msg)
|
||||
})
|
||||
fastify.get('/proto', function (req, reply) {
|
||||
reply.code(200).send({ proto: req.protocol })
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
t.test('https get request', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url })
|
||||
|
||||
t.equal(res.headers[':status'], 200)
|
||||
t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length)
|
||||
t.same(JSON.parse(res.body), msg)
|
||||
})
|
||||
|
||||
t.test('https get request without trust proxy - protocol', async (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const url = `https://localhost:${fastify.server.address().port}/proto`
|
||||
t.same(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' })
|
||||
t.same(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' })
|
||||
})
|
||||
})
|
||||
})
|
||||
35
backend/node_modules/fastify/test/http2/unknown-http-method.test.js
generated
vendored
Normal file
35
backend/node_modules/fastify/test/http2/unknown-http-method.test.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const Fastify = require('../..')
|
||||
const h2url = require('h2url')
|
||||
const msg = { hello: 'world' }
|
||||
|
||||
const fastify = Fastify({
|
||||
http2: true
|
||||
})
|
||||
|
||||
fastify.get('/', function (req, reply) {
|
||||
reply.code(200).send(msg)
|
||||
})
|
||||
|
||||
fastify.listen({ port: 0 }, err => {
|
||||
t.error(err)
|
||||
t.teardown(() => { fastify.close() })
|
||||
|
||||
test('http UNKNOWN_METHOD request', async (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const url = `http://localhost:${fastify.server.address().port}`
|
||||
const res = await h2url.concat({ url, method: 'UNKNOWN_METHOD' })
|
||||
|
||||
t.equal(res.headers[':status'], 404)
|
||||
t.same(JSON.parse(res.body), {
|
||||
statusCode: 404,
|
||||
code: 'FST_ERR_NOT_FOUND',
|
||||
error: 'Not Found',
|
||||
message: 'Not Found'
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user