|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -const { execSync } = require('node:child_process') |
4 |
| -const { throws, doesNotThrow } = require('node:assert') |
5 |
| -const { test } = require('node:test') |
6 |
| - |
7 |
| -const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"' |
8 |
| - |
9 |
| -test("respect Node.js' --max-http-header-size", () => { |
10 |
| - throws( |
11 |
| - () => execSync(`${command} --max-http-header-size=1`, { stdio: 'pipe' }), |
12 |
| - /UND_ERR_HEADERS_OVERFLOW/, |
13 |
| - 'max-http-header-size=1 should throw' |
14 |
| - ) |
15 |
| - |
16 |
| - doesNotThrow( |
17 |
| - () => execSync(command), |
18 |
| - /UND_ERR_HEADERS_OVERFLOW/, |
19 |
| - 'default max-http-header-size should not throw' |
20 |
| - ) |
| 3 | +const { tspl } = require('@matteo.collina/tspl') |
| 4 | +const { once } = require('node:events') |
| 5 | +const { exec } = require('node:child_process') |
| 6 | +const { test, before, after, describe } = require('node:test') |
| 7 | +const { createServer } = require('node:http') |
| 8 | + |
| 9 | +describe("Node.js' --max-http-header-size cli option", () => { |
| 10 | + let server |
| 11 | + |
| 12 | + before(async () => { |
| 13 | + server = createServer((req, res) => { |
| 14 | + res.writeHead(200, 'OK', { |
| 15 | + 'Content-Length': 2 |
| 16 | + }) |
| 17 | + res.write('OK') |
| 18 | + res.end() |
| 19 | + }).listen(0) |
| 20 | + |
| 21 | + await once(server, 'listening') |
| 22 | + }) |
| 23 | + |
| 24 | + after(() => server.close()) |
| 25 | + |
| 26 | + test("respect Node.js' --max-http-header-size", async (t) => { |
| 27 | + t = tspl(t, { plan: 6 }) |
| 28 | + const command = 'node -e "require(\'.\').request(\'http://localhost:' + server.address().port + '\')"' |
| 29 | + |
| 30 | + exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => { |
| 31 | + t.strictEqual(err.code, 1) |
| 32 | + t.strictEqual(stdout, '') |
| 33 | + t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw') |
| 34 | + }) |
| 35 | + |
| 36 | + exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => { |
| 37 | + t.ifError(err) |
| 38 | + t.strictEqual(stdout, '') |
| 39 | + t.strictEqual(stderr, '', 'default max-http-header-size should not throw') |
| 40 | + }) |
| 41 | + |
| 42 | + await t.completed |
| 43 | + }) |
21 | 44 | })
|
0 commit comments