Skip to content

Commit

Permalink
CA-395626: Add a unit test to detect incorrect cookie parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius authored and minglumlu committed Jul 16, 2024
1 parent a97da2d commit 5ad963e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ocaml/libs/http-lib/test_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ let one ~use_fastpath ~use_framing keep_alive s =
failwith "Need a content length"
)

let query ~use_fastpath ~use_framing keep_alive s =
let query_string = "v1,v2,v3,<>`" in
Http_client.rpc ~use_fastpath s
(Http.Request.make ~frame:use_framing ~version:"1.1" ~keep_alive ~user_agent
~query:[("k1", query_string)]
Http.Get "/query"
)
(fun response s ->
match response.Http.Response.content_length with
| Some l ->
let s = Unixext.really_read_string s (Int64.to_int l) in
if s <> query_string then
failwith "Incorrectly parsed query string"
else
()
| None ->
failwith "Need a content length"
)

module Normal_population = struct
(** Stats on a normally-distributed population *)
type t = {sigma_x: float; sigma_xx: float; n: int}
Expand Down Expand Up @@ -122,6 +141,16 @@ let _ =
)
in
Printf.printf "%s RPCs/sec\n%!" (Normal_population.to_string nonpersistent) ;
Printf.printf "1 thread non-persistent connections (query): " ;
let nonpersistent_query =
sample 1 (fun () ->
per_nsec 1. (fun () ->
transport !ip !port (query ~use_fastpath ~use_framing false)
)
)
in
Printf.printf "%s RPCs/sec\n%!"
(Normal_population.to_string nonpersistent_query) ;
Printf.printf "10 threads non-persistent connections: " ;
let thread_nonpersistent =
sample 1 (fun () ->
Expand Down
16 changes: 16 additions & 0 deletions ocaml/libs/http-lib/test_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ let _ =
Unixext.really_write_string s r
)
) ;
Server.add_handler server Http.Get "/query"
(FdIO
(fun request s _ ->
match request.Http.Request.query with
| (_, v) :: _ ->
Unixext.really_write_string s
(Http.Response.to_wire_string
(Http.Response.make ~body:v "200" "OK")
)
| _ ->
Unixext.really_write_string s
(Http.Response.to_wire_string
(Http.Response.make "404" "Query string missing")
)
)
) ;
let ip = "0.0.0.0" in
let inet_addr = Unix.inet_addr_of_string ip in
let addr = Unix.ADDR_INET (inet_addr, !port) in
Expand Down

0 comments on commit 5ad963e

Please sign in to comment.