]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add unit test for keepalive timeout parsing
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 Jul 2022 19:45:19 +0000 (20:45 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 Jul 2022 19:45:19 +0000 (20:45 +0100)
test/rspamd_cxx_unit_utils.hxx

index c853153793aab4262eed90d246697b5111422934..602b32a7e8e39e57846636f849d2ee21cbfb6af2 100644 (file)
@@ -28,6 +28,8 @@
 #include <utility>
 #include <string>
 
+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<std::pair<std::string, long>> 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