From 1335e6359797e4e3fa1a6590b407d92281686c8e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 9 Jul 2022 20:45:19 +0100 Subject: [PATCH] [Test] Add unit test for keepalive timeout parsing --- test/rspamd_cxx_unit_utils.hxx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/rspamd_cxx_unit_utils.hxx b/test/rspamd_cxx_unit_utils.hxx index c85315379..602b32a7e 100644 --- a/test/rspamd_cxx_unit_utils.hxx +++ b/test/rspamd_cxx_unit_utils.hxx @@ -28,6 +28,8 @@ #include #include +extern "C" long rspamd_http_parse_keepalive_timeout (const rspamd_ftok_t *tok); + TEST_SUITE("rspamd_utils") { TEST_CASE("rspamd_strip_smtp_comments_inplace") @@ -58,6 +60,30 @@ TEST_CASE("rspamd_strip_smtp_comments_inplace") } } +TEST_CASE("rspamd_http_parse_keepalive_timeout") +{ + std::vector> cases { + {"timeout=5, max=1000", 5}, + {"max=1000, timeout=5", 5}, + {"max=1000, timeout=", -1}, + {"max=1000, timeout=0", 0}, + {"max=1000, timeout=-5", -1}, + {"timeout=5", 5}, + {" timeout=5; ", 5}, + {"timeout = 5", 5}, + }; + + for (const auto &c : cases) { + SUBCASE (("parse http keepalive header " + c.first).c_str()) { + rspamd_ftok_t t; + t.begin = c.first.data(); + t.len = c.first.size(); + auto res = rspamd_http_parse_keepalive_timeout(&t); + CHECK(res == c.second); + } + } +} + } #endif -- 2.39.5