From 5ad963ef0a34e2f9ed562ddb76c10508673fead8 Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Mon, 15 Jul 2024 09:50:34 +0100 Subject: [PATCH] CA-395626: Add a unit test to detect incorrect cookie parsing Signed-off-by: Andrii Sultanov --- ocaml/libs/http-lib/test_client.ml | 29 +++++++++++++++++++++++++++++ ocaml/libs/http-lib/test_server.ml | 16 ++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ocaml/libs/http-lib/test_client.ml b/ocaml/libs/http-lib/test_client.ml index 16d9d79cc09..041e08b0db4 100644 --- a/ocaml/libs/http-lib/test_client.ml +++ b/ocaml/libs/http-lib/test_client.ml @@ -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} @@ -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 () -> diff --git a/ocaml/libs/http-lib/test_server.ml b/ocaml/libs/http-lib/test_server.ml index 51e4f559e59..a1f703042ee 100644 --- a/ocaml/libs/http-lib/test_server.ml +++ b/ocaml/libs/http-lib/test_server.ml @@ -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