From 341b6d9b944de34ffdbf68af8709637d265db874 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 17 Sep 2024 11:45:08 +0200 Subject: [PATCH] test: deflake test-http-header-overflow Skip the network and push the data directly to the receiving socket so that it is guaranteed to be received as a single chunk. Fixes: https://github.com/nodejs/node/issues/46291 PR-URL: https://github.com/nodejs/node/pull/54978 Reviewed-By: Robert Nagy Reviewed-By: James M Snell --- test/parallel/test-http-header-overflow.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-http-header-overflow.js b/test/parallel/test-http-header-overflow.js index 6abbf2bafc545d..0d0dffed89b089 100644 --- a/test/parallel/test-http-header-overflow.js +++ b/test/parallel/test-http-header-overflow.js @@ -1,5 +1,3 @@ -// Flags: --expose-internals - 'use strict'; const { expectsError, mustCall } = require('../common'); const assert = require('assert'); @@ -10,11 +8,10 @@ const CRLF = '\r\n'; const DUMMY_HEADER_NAME = 'Cookie: '; const DUMMY_HEADER_VALUE = 'a'.repeat( // Plus one is to make it 1 byte too big - maxHeaderSize - DUMMY_HEADER_NAME.length + 2 + maxHeaderSize - DUMMY_HEADER_NAME.length + 1 ); const PAYLOAD_GET = 'GET /blah HTTP/1.1'; -const PAYLOAD = PAYLOAD_GET + CRLF + - DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE + CRLF.repeat(2); +const PAYLOAD = PAYLOAD_GET + CRLF + DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE; const server = createServer(); @@ -23,18 +20,19 @@ server.on('connection', mustCall((socket) => { name: 'Error', message: 'Parse Error: Header overflow', code: 'HPE_HEADER_OVERFLOW', - bytesParsed: maxHeaderSize + PAYLOAD_GET.length + (CRLF.length * 2) + 1, + bytesParsed: PAYLOAD.length, rawPacket: Buffer.from(PAYLOAD) })); + + // The data is not sent from the client to ensure that it is received as a + // single chunk. + socket.push(PAYLOAD); })); server.listen(0, mustCall(() => { const c = createConnection(server.address().port); let received = ''; - c.on('connect', mustCall(() => { - c.write(PAYLOAD); - })); c.on('data', mustCall((data) => { received += data.toString(); }));