commit 1335e63: [Test] Add unit test for keepalive timeout parsing

Vsevolod Stakhov vsevolod at rspamd.com
Sat Jul 9 19:49:07 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-07-09 20:45:19 +0100
URL: https://github.com/rspamd/rspamd/commit/1335e6359797e4e3fa1a6590b407d92281686c8e (HEAD -> master)

[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 <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


More information about the Commits mailing list