Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,7 +1,6 @@
'use strict'
const t = require('tap')
const test = t.test
const { test } = require('node:test')
const Fastify = require('../..')
const h2url = require('h2url')
@@ -9,9 +8,9 @@ const alpha = { res: 'alpha' }
const beta = { res: 'beta' }
const { buildCertificate } = require('../build-certificate')
t.before(buildCertificate)
test.before(buildCertificate)
test('A route supports host constraints under http2 protocol and secure connection', (t) => {
test('A route supports host constraints under http2 protocol and secure connection', async (t) => {
t.plan(5)
let fastify
@@ -23,9 +22,9 @@ test('A route supports host constraints under http2 protocol and secure connecti
cert: global.context.cert
}
})
t.pass('Key/cert successfully loaded')
t.assert.ok(true, 'Key/cert successfully loaded')
} catch (e) {
t.fail('Key/cert loading failed', e)
t.assert.fail('Key/cert loading failed')
}
const constrain = 'fastify.dev'
@@ -45,47 +44,66 @@ test('A route supports host constraints under http2 protocol and secure connecti
reply.code(200).send(beta)
}
})
fastify.route({
method: 'GET',
url: '/hostname_port',
constraints: { host: constrain },
handler: function (req, reply) {
reply.code(200).send({ ...beta, hostname: req.hostname })
}
})
t.after(() => { fastify.close() })
fastify.listen({ port: 0 }, err => {
t.error(err)
t.teardown(() => { fastify.close() })
await fastify.listen({ port: 0 })
t.test('https get request - no constrain', async (t) => {
t.plan(3)
await 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 })
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.assert.strictEqual(res.headers[':status'], 200)
t.assert.strictEqual(res.headers['content-length'], '' + JSON.stringify(alpha).length)
t.assert.deepStrictEqual(JSON.parse(res.body), alpha)
})
await 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.test('https get request - constrain', async (t) => {
t.plan(3)
t.assert.strictEqual(res.headers[':status'], 200)
t.assert.strictEqual(res.headers['content-length'], '' + JSON.stringify(beta).length)
t.assert.deepStrictEqual(JSON.parse(res.body), beta)
})
const url = `https://localhost:${fastify.server.address().port}/beta`
const res = await h2url.concat({
url,
headers: {
':authority': constrain
}
})
await t.test('https get request - constrain - not found', async (t) => {
t.plan(1)
t.equal(res.headers[':status'], 200)
t.equal(res.headers['content-length'], '' + JSON.stringify(beta).length)
t.same(JSON.parse(res.body), beta)
const url = `https://localhost:${fastify.server.address().port}/beta`
const res = await h2url.concat({
url
})
t.test('https get request - constrain - not found', async (t) => {
t.plan(1)
t.assert.strictEqual(res.headers[':status'], 404)
})
await t.test('https get request - constrain - verify hostname and port from request', 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)
const url = `https://localhost:${fastify.server.address().port}/hostname_port`
const res = await h2url.concat({
url,
headers: {
':authority': constrain
}
})
const body = JSON.parse(res.body)
t.assert.strictEqual(body.hostname, constrain)
})
})