From 3960832b25e491c6b801786b58734d4986008edc Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 20 Feb 2024 02:43:54 +0100 Subject: [PATCH 1/3] chore: reduce necessity of internet connection for test --- test/client-node-max-header-size.js | 59 ++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/test/client-node-max-header-size.js b/test/client-node-max-header-size.js index 227f6705084..379c5e6970a 100644 --- a/test/client-node-max-header-size.js +++ b/test/client-node-max-header-size.js @@ -1,21 +1,44 @@ 'use strict' -const { execSync } = require('node:child_process') -const { throws, doesNotThrow } = require('node:assert') -const { test } = require('node:test') - -const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"' - -test("respect Node.js' --max-http-header-size", () => { - throws( - () => execSync(`${command} --max-http-header-size=1`, { stdio: 'pipe' }), - /UND_ERR_HEADERS_OVERFLOW/, - 'max-http-header-size=1 should throw' - ) - - doesNotThrow( - () => execSync(command), - /UND_ERR_HEADERS_OVERFLOW/, - 'default max-http-header-size should not throw' - ) +const { tspl } = require('@matteo.collina/tspl') +const { once } = require('node:events') +const { exec } = require('node:child_process') +const { test, before, after, describe } = require('node:test') +const { createServer } = require('node:http') + +describe("Node.js' --max-http-header-size cli option", () => { + let server + + before(async () => { + server = createServer((req, res) => { + res.writeHead(200, 'OK', { + 'Content-Length': 2 + }) + res.write('OK') + res.end() + }).listen(0) + + await once(server, 'listening') + }) + + after(() => server.close()) + + test("respect Node.js' --max-http-header-size", async (t) => { + t = tspl(t, { plan: 6 }) + const command = 'node -e "require(\'.\').request(\'http://localhost:' + server.address().port + '\')"' + + exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => { + t.strictEqual(err.code, 1) + t.strictEqual(stdout, '') + t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw') + }) + + exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => { + t.ifError(err) + t.strictEqual(stdout, '') + t.strictEqual(stderr, '', 'default max-http-header-size should not throw') + }) + + await t.completed + }) }) From f9679ccbeef894575a37a03ca27774aa77d9c131 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 20 Feb 2024 02:52:08 +0100 Subject: [PATCH 2/3] fix wrong description of test --- test/issue-1670.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/issue-1670.js b/test/issue-1670.js index 7a0cda32669..26904d4da8f 100644 --- a/test/issue-1670.js +++ b/test/issue-1670.js @@ -3,7 +3,7 @@ const { test } = require('node:test') const { request } = require('..') -test('https://github.com/mcollina/undici/issues/810', async () => { +test('https://github.com/mcollina/undici/issues/1670', async () => { const { body } = await request('https://api.github.com/user/emails') await body.text() From 2b5d7830fbe114a349b9ad3701e8af57f36b9f8a Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 20 Feb 2024 02:52:41 +0100 Subject: [PATCH 3/3] make connect-timeout test work when no internet connection --- test/connect-timeout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/connect-timeout.js b/test/connect-timeout.js index d8ff177504c..1378de82cf5 100644 --- a/test/connect-timeout.js +++ b/test/connect-timeout.js @@ -16,7 +16,7 @@ describe('prioritize socket errors over timeouts', () => { client.request({ method: 'GET', path: '/foobar' }) .then(() => t.fail()) .catch((err) => { - t.strictEqual(err.code, 'ENOTFOUND') + t.strictEqual(['ENOTFOUND', 'EAI_AGAIN'].includes(err.code), true) }) // block for 1s which is enough for the dns lookup to complete and TO to fire