package-rebuilds/pkgs/node-undici/node-undici-5.28.4+dfsg1+~cs23.12.11/test/https.js
Fabian Grünbichler afee63929c add node-undici for libgit2 1.8.1
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-09-10 11:23:24 +02:00

75 lines
1.9 KiB
JavaScript

'use strict'
const { test } = require('tap')
const { Client } = require('..')
const { createServer } = require('https')
const pem = require('https-pem')
test('https get with tls opts', (t) => {
t.plan(6)
const server = createServer(pem, (req, res) => {
t.equal('/', req.url)
t.equal('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`https://localhost:${server.address().port}`, {
tls: {
rejectUnauthorized: false
}
})
t.teardown(client.close.bind(client))
client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})
})
})
test('https get with tls opts ip', (t) => {
t.plan(6)
const server = createServer(pem, (req, res) => {
t.equal('/', req.url)
t.equal('GET', req.method)
res.setHeader('content-type', 'text/plain')
res.end('hello')
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`https://127.0.0.1:${server.address().port}`, {
tls: {
rejectUnauthorized: false
}
})
t.teardown(client.close.bind(client))
client.request({ path: '/', method: 'GET' }, (err, { statusCode, headers, body }) => {
t.error(err)
t.equal(statusCode, 200)
t.equal(headers['content-type'], 'text/plain')
const bufs = []
body.on('data', (buf) => {
bufs.push(buf)
})
body.on('end', () => {
t.equal('hello', Buffer.concat(bufs).toString('utf8'))
})
})
})
})