Skip to content

Commit

Permalink
Add a test for line length.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 15, 2024
1 parent 60929d0 commit 56460bc
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions test/protocol/http1/connection/bad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 56460bc

Please sign in to comment.