aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-02-12 15:36:29 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2024-02-12 15:36:29 +0000
commitf8210a5ba96334cc88ea876c1e496b132c1236c5 (patch)
treea91530a9c1828f9698bb94ada41bee535abcd823 /test
parentd3a56d950947a01e0a932cf103631033373c57f5 (diff)
downloadrspamd-f8210a5ba96334cc88ea876c1e496b132c1236c5.tar.gz
rspamd-f8210a5ba96334cc88ea876c1e496b132c1236c5.zip
[Test] Add unit tests
Diffstat (limited to 'test')
-rw-r--r--test/rspamd_cxx_unit_utils.hxx29
1 files changed, 28 insertions, 1 deletions
diff --git a/test/rspamd_cxx_unit_utils.hxx b/test/rspamd_cxx_unit_utils.hxx
index 126253fd6..1dea7af9d 100644
--- a/test/rspamd_cxx_unit_utils.hxx
+++ b/test/rspamd_cxx_unit_utils.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
#include "libmime/mime_headers.h"
#include "contrib/libottery/ottery.h"
#include "libcryptobox/cryptobox.h"
+#include "libserver/http/http_message.h"
#include <vector>
#include <utility>
@@ -204,6 +205,32 @@ TEST_SUITE("rspamd_utils")
}
}
}
+
+ TEST_CASE("rspamd_http_message_from_url")
+ {
+ std::vector<std::pair<std::string, std::string>> cases{
+ {"http://example.com", "/"},
+ {"http://example.com/", "/"},
+ {"http://example.com/lol", "/lol"},
+ {"http://example.com/lol#keke", "/lol"},
+ {"http://example.com/lol?omg=huh&oh", "/lol?omg=huh&oh"},
+ {"http://example.com/lol?omg=huh&oh#", "/lol?omg=huh&oh"},
+ {"http://example.com/lol?omg=huh&oh#keke", "/lol?omg=huh&oh"},
+ {"http://example.com/lol?", "/lol"},
+ {"http://example.com/lol?#", "/lol"},
+ };
+
+ for (const auto &c: cases) {
+ SUBCASE(("rspamd_http_message_from_url: " + c.first).c_str())
+ {
+ auto *msg = rspamd_http_message_from_url(c.first.c_str());
+ std::size_t nlen;
+ auto *path = rspamd_http_message_get_url(msg, &nlen);
+ CHECK(std::string{path, nlen} == c.second);
+ rspamd_http_message_unref(msg);
+ }
+ }
+ }
}
#endif