Skip to content

Commit

Permalink
separate describes for better output
Browse files Browse the repository at this point in the history
Signed-off-by: shirady <[email protected]>
  • Loading branch information
shirady committed Feb 5, 2025
1 parent 06c5c7f commit 141aa75
Showing 1 changed file with 69 additions and 50 deletions.
119 changes: 69 additions & 50 deletions src/test/unit_tests/jest_tests/test_chunked_content_decoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,52 @@ describe('ChunkedContentDecoder', function() {
// 0\r\n
// \r\n

test_parse_output({
name: 'two_chunks',
input:
'3\r\n' +
'foo\r\n' +
'3\r\n' +
'bar\r\n' +
'0\r\n' +
'\r\n',
output: 'foobar',
});
describe('expected to parse the input', function() {
test_parse_output({
name: 'two_chunks',
input:
'3\r\n' +
'foo\r\n' +
'3\r\n' +
'bar\r\n' +
'0\r\n' +
'\r\n',
output: 'foobar',
});

test_parse_output({
name: 'three_chunks_with_trailers',
input:
'3\r\n' +
'foo\r\n' +
'6\r\n' +
'barbaz\r\n' +
'ff\r\n' +
'f'.repeat(255) + '\r\n' +
'0\r\n' +
'x-trailer-1: value\r\n' +
'x-trailer-2: value\r\n' +
'\r\n',
output: 'foobarbaz' + 'f'.repeat(255),
check: decoder => {
assert.deepStrictEqual(decoder.trailers, [
'x-trailer-1: value',
'x-trailer-2: value',
]);
},
});
test_parse_output({
name: 'two_chunks',
input:
'3\r\n' +
'foo\r\n' +
'3\r\n' +
'bar\r\n' +
'0\r\n' +
'\r\n',
output: 'foobar',
});

test_parse_output({
name: 'three_chunks_with_trailers',
input:
'3\r\n' +
'foo\r\n' +
'6\r\n' +
'barbaz\r\n' +
'ff\r\n' +
'f'.repeat(255) + '\r\n' +
'0\r\n' +
'x-trailer-1: value\r\n' +
'x-trailer-2: value\r\n' +
'\r\n',
output: 'foobarbaz' + 'f'.repeat(255),
check: decoder => {
assert.deepStrictEqual(decoder.trailers, [
'x-trailer-1: value',
'x-trailer-2: value',
]);
},
});

test_parse_output({
name: 'no_chunk_with_trailers',
Expand Down Expand Up @@ -85,24 +98,6 @@ describe('ChunkedContentDecoder', function() {
output: 'EXT',
});

test_parse_error({
name: 'chunk_size_not_hex',
input: 'invalid\r\n\r\n',
error_pos: 7, // end of header
});

test_parse_error({
name: 'chunk_size_too_big',
input: '10000000001\r\n\r\n',
error_pos: 11, // end of header
});

test_parse_error({
name: 'header_too_long',
input: '0' + ';'.repeat(1024) + '\r\n\r\n',
error_pos: 1025, // end of header
});

test_parse_output({
name: 'one_chunk_with_ext',
input:
Expand All @@ -113,6 +108,30 @@ describe('ChunkedContentDecoder', function() {
output: 'EXT',
});

});

describe('expected to have an error on parse', function() {

test_parse_error({
name: 'chunk_size_not_hex',
input: 'invalid\r\n\r\n',
error_pos: 7, // end of header
});

test_parse_error({
name: 'chunk_size_too_big',
input: '10000000001\r\n\r\n',
error_pos: 11, // end of header
});

test_parse_error({
name: 'header_too_long', // according to MAX_CHUNK_HEADER_SIZE
input: '0' + ';'.repeat(1024) + '\r\n\r\n',
error_pos: 1025, // end of header
});

});

/**
* @param {{
* name: string,
Expand Down

0 comments on commit 141aa75

Please sign in to comment.