From: Vsevolod Stakhov Date: Sat, 9 Jul 2022 19:45:19 +0000 (+0100) Subject: [Test] Add unit test for keepalive timeout parsing X-Git-Tag: 3.3~134 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1335e6359797e4e3fa1a6590b407d92281686c8e;p=rspamd.git [Test] Add unit test for keepalive timeout parsing --- 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