Skip to content

Commit 38307dc

Browse files
committed
http: fixing tests
test-http-header-overflow.js: the llhttp doesn't count space and separator, so to generate a breaking number of chars, just add +1 to the maxHeaderSize test-http-max-http-headers.js: remove the +1 that was referring to the slash of the uri, because it's not being counted anymore
1 parent 710e830 commit 38307dc

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

test/parallel/test-http-header-overflow.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1+
// Flags: --expose-internals
12
'use strict';
3+
const { expectsError, mustCall } = require('../common');
24
const assert = require('assert');
35
const { createServer, maxHeaderSize } = require('http');
46
const { createConnection } = require('net');
5-
const { expectsError, mustCall } = require('../common');
7+
8+
const { getOptionValue } = require('internal/options');
9+
10+
const currentParser = getOptionValue('--http-parser');
11+
12+
const sumOfLengths = (strings) => strings
13+
.map((string) => string.length)
14+
.reduce((a, b) => a + b);
15+
16+
const getBreakingLength = () => {
17+
if (currentParser === 'llhttp') {
18+
return maxHeaderSize - HEADER_NAME.length + 1;
19+
} else {
20+
return maxHeaderSize - HEADER_NAME.length - HEADER_SEPARATOR -
21+
(2 * CRLF.length) + 1;
22+
}
23+
};
624

725
const CRLF = '\r\n';
8-
const DUMMY_HEADER_NAME = 'Cookie: ';
9-
const DUMMY_HEADER_VALUE = 'a'.repeat(
10-
// Plus one is to make it 1 byte too big
11-
maxHeaderSize - DUMMY_HEADER_NAME.length - (2 * CRLF.length) + 1
12-
);
26+
const HEADER_NAME = 'Cookie';
27+
const HEADER_SEPARATOR = ': ';
28+
const HEADER_VALUE = 'a'.repeat(getBreakingLength());
1329
const PAYLOAD_GET = 'GET /blah HTTP/1.1';
1430
const PAYLOAD = PAYLOAD_GET + CRLF +
15-
DUMMY_HEADER_NAME + DUMMY_HEADER_VALUE + CRLF.repeat(2);
31+
HEADER_NAME + HEADER_SEPARATOR + HEADER_VALUE + CRLF.repeat(2);
1632

1733
const server = createServer();
1834

@@ -21,7 +37,13 @@ server.on('connection', mustCall((socket) => {
2137
type: Error,
2238
message: 'Parse Error',
2339
code: 'HPE_HEADER_OVERFLOW',
24-
bytesParsed: maxHeaderSize + PAYLOAD_GET.length,
40+
bytesParsed: sumOfLengths([
41+
PAYLOAD_GET,
42+
CRLF,
43+
HEADER_NAME,
44+
HEADER_SEPARATOR,
45+
HEADER_VALUE
46+
]) + 1,
2547
rawPacket: Buffer.from(PAYLOAD)
2648
}));
2749
}));

test/sequential/test-http-max-http-headers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const test2 = common.mustCall(() => {
123123
'X-CRASH: ';
124124

125125
// /, Host, localhost, Agent, node, X-CRASH, a...
126-
const currentSize = 1 + 4 + 9 + 5 + 4 + 7;
126+
const currentSize = 4 + 9 + 5 + 4 + 7;
127127
headers = fillHeaders(headers, currentSize);
128128

129129
const server = http.createServer(common.mustNotCall());

0 commit comments

Comments
 (0)