cgi_test.ml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (*
  2. * cgi_test.ml
  3. *
  4. * Created by Marcus Rohrmoser on 27.05.20.
  5. * Copyright © 2020-2021 Marcus Rohrmoser mobile Software http://mro.name/~me. All rights reserved.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *)
  20. open Lib.Cgi
  21. let ra =
  22. {
  23. host = "example.com";
  24. http_cookie = "";
  25. path_info = "";
  26. query_string = "badly";
  27. request_method = "GET";
  28. (* request_uri = "/sub/wrong.cgi?badly"; *)
  29. scheme = "http";
  30. script_name = "/sub/wrong.cgi";
  31. server_port = "80";
  32. }
  33. (* https://tools.ietf.org/html/rfc3875#section-4.1.5 *)
  34. let test_consolidate_path_info_workaround () =
  35. let re =
  36. Ok { ra with path_info = "/sub/wrong.cgi" } |> consolidate |> Result.get_ok
  37. in
  38. Assert2.equals_string "test_consolidate_path_info_workaround" "" re.path_info
  39. (* https://tools.ietf.org/html/rfc3875#section-4.1.5 *)
  40. let test_consolidate_path_info_buggy_workaround () =
  41. let re =
  42. Ok
  43. {
  44. ra with
  45. path_info =
  46. "/sub/wrong.cgi" (* request_uri = "/sub/wrong.cgi/sub/wrong.cgi"; *);
  47. }
  48. |> consolidate |> Result.get_ok
  49. in
  50. Assert2.equals_string
  51. "wrong but accepted until 1and1 fixes their shit (prbly never)." ""
  52. re.path_info
  53. let test_request_uri () =
  54. let uri = { ra with path_info = "/dir/" } |> request_uri in
  55. Assert2.equals_string "." "/sub/wrong.cgi/dir/?badly" uri
  56. let () =
  57. test_consolidate_path_info_workaround ();
  58. test_consolidate_path_info_buggy_workaround ();
  59. test_request_uri ()