From 66f87b7bdac80b4cab55c9998317700419f72357 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 2 Dec 2024 14:45:41 -0500 Subject: [PATCH] more tests --- tests/multipart_form/dune | 5 ++- .../{t1.expected => t_chunk.expected} | 0 tests/multipart_form/{t1.ml => t_chunk.ml} | 0 tests/multipart_form/t_content_type.expected | 3 ++ tests/multipart_form/t_content_type.ml | 32 +++++++++++++++++++ .../{t2.expected => t_parse.expected} | 0 tests/multipart_form/{t2.ml => t_parse.ml} | 0 7 files changed, 37 insertions(+), 3 deletions(-) rename tests/multipart_form/{t1.expected => t_chunk.expected} (100%) rename tests/multipart_form/{t1.ml => t_chunk.ml} (100%) create mode 100644 tests/multipart_form/t_content_type.expected create mode 100644 tests/multipart_form/t_content_type.ml rename tests/multipart_form/{t2.expected => t_parse.expected} (100%) rename tests/multipart_form/{t2.ml => t_parse.ml} (100%) diff --git a/tests/multipart_form/dune b/tests/multipart_form/dune index e45df39e..48e31cbb 100644 --- a/tests/multipart_form/dune +++ b/tests/multipart_form/dune @@ -1,4 +1,3 @@ - (tests - (names t1 t2) - (libraries tiny_httpd tiny_httpd.multipart-form-data)) + (names t_chunk t_parse t_content_type) + (libraries tiny_httpd tiny_httpd.multipart-form-data)) diff --git a/tests/multipart_form/t1.expected b/tests/multipart_form/t_chunk.expected similarity index 100% rename from tests/multipart_form/t1.expected rename to tests/multipart_form/t_chunk.expected diff --git a/tests/multipart_form/t1.ml b/tests/multipart_form/t_chunk.ml similarity index 100% rename from tests/multipart_form/t1.ml rename to tests/multipart_form/t_chunk.ml diff --git a/tests/multipart_form/t_content_type.expected b/tests/multipart_form/t_content_type.expected new file mode 100644 index 00000000..4f4a6a83 --- /dev/null +++ b/tests/multipart_form/t_content_type.expected @@ -0,0 +1,3 @@ +h: ["content-type": "yolo";"other": "whatev"], no content type +h ["content-type": "multipart/form-data; boundary=helloworld; junk";"other": "whatev"]: got "helloworld", expected "helloworld", same=true +h ["content-type": "multipart/form-data; lol=mdr; boundary=\"some quoted boundary\""]: got "some quoted boundary", expected "some quoted boundary", same=true diff --git a/tests/multipart_form/t_content_type.ml b/tests/multipart_form/t_content_type.ml new file mode 100644 index 00000000..9159ba45 --- /dev/null +++ b/tests/multipart_form/t_content_type.ml @@ -0,0 +1,32 @@ +module MFD = Tiny_httpd_multipart_form_data + +let pf = Printf.printf +let spf = Printf.sprintf + +let pp_headers hs = + spf "[%s]" (String.concat ";" @@ List.map (fun (k, v) -> spf "%S: %S" k v) hs) + +let test_headers h (exp : string option) = + match MFD.parse_content_type h, exp with + | Some (`boundary c1), Some c2 -> + pf "h %s: got %S, expected %S, same=%b\n" (pp_headers h) c1 c2 (c1 = c2) + | Some (`boundary c1), None -> + pf "h: %s, unexpected content type %S\n" (pp_headers h) c1 + | None, Some c2 -> pf "h: %s, expected content type %S\n" (pp_headers h) c2 + | None, None -> pf "h: %s, no content type\n" (pp_headers h) + +let () = + test_headers [ "content-type", "yolo"; "other", "whatev" ] None; + test_headers + [ + "content-type", "multipart/form-data; boundary=helloworld; junk"; + "other", "whatev"; + ] + (Some "helloworld"); + test_headers + [ + ( "content-type", + "multipart/form-data; lol=mdr; boundary=\"some quoted boundary\"" ); + ] + (Some "some quoted boundary"); + () diff --git a/tests/multipart_form/t2.expected b/tests/multipart_form/t_parse.expected similarity index 100% rename from tests/multipart_form/t2.expected rename to tests/multipart_form/t_parse.expected diff --git a/tests/multipart_form/t2.ml b/tests/multipart_form/t_parse.ml similarity index 100% rename from tests/multipart_form/t2.ml rename to tests/multipart_form/t_parse.ml