mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2026-03-08 06:47:59 -04:00
test: add test for header size limit enforcement
This commit is contained in:
parent
1f357e495a
commit
d19c461e61
2 changed files with 26 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
(tests
|
||||
(names t_util t_buf t_server t_io t_response)
|
||||
(names t_util t_buf t_server t_io t_response t_headers)
|
||||
(package tiny_httpd)
|
||||
(libraries tiny_httpd.core qcheck-core qcheck-core.runner test_util))
|
||||
|
|
|
|||
25
tests/unit/t_headers.ml
Normal file
25
tests/unit/t_headers.ml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
open Test_util
|
||||
open Tiny_httpd_core
|
||||
|
||||
(* Test that header size limits are enforced *)
|
||||
let test_header_too_large () =
|
||||
(* Create a header that's larger than 16KB *)
|
||||
let large_value = String.make 20000 'x' in
|
||||
let q =
|
||||
"GET / HTTP/1.1\r\n\
|
||||
Host: example.com\r\n\
|
||||
X-Large: " ^ large_value ^ "\r\n\
|
||||
\r\n"
|
||||
in
|
||||
let str = IO.Input.of_string q in
|
||||
let client_addr = Unix.(ADDR_INET (inet_addr_loopback, 1024)) in
|
||||
let buf = Buf.create () in
|
||||
try
|
||||
let _ = Request.Private_.parse_req_start_exn ~client_addr ~buf
|
||||
~get_time_s:(fun _ -> 0.) str in
|
||||
failwith "should have failed with 431"
|
||||
with Common_.Bad_req (431, _) ->
|
||||
() (* expected *)
|
||||
|
||||
let () =
|
||||
test_header_too_large ()
|
||||
Loading…
Add table
Reference in a new issue