Skip to content

Commit

Permalink
warp/test: adjusted tests to confirm that multiline headers are not s…
Browse files Browse the repository at this point in the history
…upported anymore

I checked the parsing of headers functions and we apparently do not throw or abort
on any invalid header formats. Do we want to do that? Or do we defer that judgement
to any user of 'warp'?
  • Loading branch information
Vlix committed Jan 14, 2024
1 parent f50d400 commit 049cfe1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
12 changes: 7 additions & 5 deletions warp/test/RequestSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,24 @@ spec = do
parseHeaderLine ["Status: 200", "\r\nContent-Type: text/plain", "\r\n\r\n"]

it "can handle a nasty case (2)" $ do
parseHeaderLine ["Status: 200", "\r", "\nContent-Type: text/plain", "\r", "\n\r\n"]
parseHeaderLine
["Status: 200", "\r", "\nContent-Type: text/plain", "\r", "\n\r\n"]

it "can handle a nasty case (3)" $ do
parseHeaderLine ["Status: 200", "\r", "\n", "Content-Type: text/plain", "\r", "\n", "\r", "\n"]
parseHeaderLine
["Status: 200", "\r", "\n", "Content-Type: text/plain", "\r", "\n", "\r", "\n"]

it "can handle a stupid case (3)" $
parseHeaderLine $
(S8.pack . (:[])) <$> "Status: 200\r\nContent-Type: text/plain\r\n\r\n"
(S8.pack . (: [])) <$> "Status: 200\r\nContent-Type: text/plain\r\n\r\n"

it "can handle an illegal case (1)" $ do
it "can (not) handle an illegal case (1)" $ do
let chunks = ["\nStatus:", "\n 200", "\nContent-Type: text/plain", "\r\n\r\n"]
src <- mkSourceFunc chunks >>= mkSource
x <- headerLines defaultMaxTotalHeaderLength True src
x `shouldBe` []
y <- headerLines defaultMaxTotalHeaderLength True src
y `shouldBe` ["Status: 200", "Content-Type: text/plain"]
y `shouldBe` ["Status:", " 200", "Content-Type: text/plain"]

-- Length is 39, this shouldn't fail
let testLengthHeaders = ["Sta", "tus: 200\r", "\n", "Content-Type: ", "text/plain\r\n\r\n"]
Expand Down
17 changes: 9 additions & 8 deletions warp/test/RunSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,27 @@ spec = do
threadDelay 5000
headers <- I.readIORef iheaders
headers
`shouldBe` [ ("foo", "bar baz\tbin")
`shouldBe` [ ("foo", "bar")
, (" baz", "")
, ("\tbin", "")
]
it "no space between colon and value" $ do
appWithSocket $ \iheaders ms -> do
let input = "GET / HTTP/1.1\r\nfoo:bar\r\n\r\n"
msWrite ms input
threadDelay 5000
headers <- I.readIORef iheaders
headers `shouldBe`
[ ("foo", "bar")
]
it "recognizes multiline headers" $ do
headers `shouldBe` [("foo", "bar")]
it "does not recognize multiline headers" $ do
appWithSocket $ \iheaders ms -> do
msWrite ms "GET / HTTP/1.1\r\nfoo: and\r\n"
msWrite ms " baz as well\r\n\r\n"
threadDelay 5000
headers <- I.readIORef iheaders
headers `shouldBe`
[ ("foo", "and baz as well")
]
headers
`shouldBe` [ ("foo", "and")
, (" baz as well", "")
]

describe "chunked bodies" $ do
it "works" $ do
Expand Down

0 comments on commit 049cfe1

Please sign in to comment.