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,17 +1,16 @@
'use strict'
const t = require('tap')
const test = t.test
const { test } = require('node: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)
const { Agent } = require('undici')
test.before(buildCertificate)
test('secure with fallback', (t) => {
t.plan(7)
test('secure with fallback', async (t) => {
t.plan(6)
let fastify
try {
@@ -23,9 +22,9 @@ test('secure with fallback', (t) => {
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')
}
fastify.get('/', function (req, reply) {
@@ -40,71 +39,75 @@ test('secure with fallback', (t) => {
throw new Error('kaboom')
})
fastify.listen({ port: 0 }, err => {
t.error(err)
t.teardown(() => { fastify.close() })
t.after(() => fastify.close())
t.test('https get error', async (t) => {
t.plan(1)
const fastifyServer = await fastify.listen({ port: 0 })
const url = `https://localhost:${fastify.server.address().port}/error`
const res = await h2url.concat({ url })
await t.test('https get error', async (t) => {
t.plan(1)
t.equal(res.headers[':status'], 500)
const url = `${fastifyServer}/error`
const res = await h2url.concat({ url })
t.assert.strictEqual(res.headers[':status'], 500)
})
await t.test('https post', async (t) => {
t.plan(2)
const res = await h2url.concat({
url: fastifyServer,
method: 'POST',
body: JSON.stringify({ hello: 'http2' }),
headers: {
'content-type': 'application/json'
}
})
t.test('https post', async (t) => {
t.plan(2)
t.assert.strictEqual(res.headers[':status'], 200)
t.assert.deepStrictEqual(JSON.parse(res.body), { hello: 'http2' })
})
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'
await t.test('https get request', async (t) => {
t.plan(3)
const res = await h2url.concat({ url: fastifyServer })
t.assert.strictEqual(res.headers[':status'], 200)
t.assert.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length)
t.assert.deepStrictEqual(JSON.parse(res.body), msg)
})
await t.test('http1 get request', async t => {
t.plan(4)
const result = await fetch(fastifyServer, {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false
}
})
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 body = await result.text()
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 200)
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
t.assert.deepStrictEqual(JSON.parse(body), msg)
})
const url = `https://localhost:${fastify.server.address().port}`
const res = await h2url.concat({ url })
await t.test('http1 get error', async t => {
t.plan(2)
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' })
const result = await fetch(`${fastifyServer}/error`, {
dispatcher: new Agent({
connect: {
rejectUnauthorized: false
}
})
})
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)
})
})
t.assert.ok(!result.ok)
t.assert.strictEqual(result.status, 500)
})
})