From 56460bc65dd682290501f199e70e88eade126437 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Wed, 16 Oct 2024 01:02:53 +1300 Subject: [PATCH] Add a test for line length. --- test/protocol/http1/connection/bad.rb | 33 +++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/protocol/http1/connection/bad.rb b/test/protocol/http1/connection/bad.rb index 33ed71f..56e57a2 100644 --- a/test/protocol/http1/connection/bad.rb +++ b/test/protocol/http1/connection/bad.rb @@ -9,11 +9,16 @@ describe Protocol::HTTP1::Connection do include_context ConnectionContext - def before - super - - client.stream.write(input) - client.stream.close + before do + # We use a thread here, as writing to the stream may block, e.g. if the input is big enough. + @writer = Thread.new do + client.stream.write(input) + client.stream.close + end + end + + after do + @writer.join end with "invalid hexadecimal content-length" do @@ -122,4 +127,22 @@ def input end.to raise_exception(Protocol::HTTP1::BadRequest) end end + + with "line length exceeding the limit" do + def input + <<~HTTP.gsub("\n", "\r\n") + POST / HTTP/1.1 + Host: a.com + Connection: close + Long-Header: #{'a' * 8192} + + HTTP + end + + it "should fail to parse the request" do + expect do + server.read_request + end.to raise_exception(Protocol::HTTP1::LineLengthError) + end + end end