aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-02 13:24:05 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-02 13:24:05 +0000
commit0884acfc39332637b9fb52bc957cb9fc8306257a (patch)
tree2ecf279459541ece08b58e11aa0afea4d69e3443 /test
parent49b2f29ae1fbabe6612f4c64d977de6df3471759 (diff)
downloadrspamd-0884acfc39332637b9fb52bc957cb9fc8306257a.tar.gz
rspamd-0884acfc39332637b9fb52bc957cb9fc8306257a.zip
Add unit test for url extraction.
Diffstat (limited to 'test')
-rw-r--r--test/lua/unit/url.lua66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
new file mode 100644
index 000000000..afc4db2f2
--- /dev/null
+++ b/test/lua/unit/url.lua
@@ -0,0 +1,66 @@
+-- URL parser tests
+
+context("URL check functions", function()
+ local mpool = require("rspamd_mempool")
+ local ffi = require("ffi")
+
+ ffi.cdef[[
+ struct rspamd_url {
+ char *string;
+ int protocol;
+
+ int ip_family;
+
+ char *user;
+ char *password;
+ char *host;
+ char *port;
+ char *data;
+ char *query;
+ char *fragment;
+ char *post;
+ char *surbl;
+
+ struct rspamd_url *phished_url;
+
+ unsigned int protocollen;
+ unsigned int userlen;
+ unsigned int passwordlen;
+ unsigned int hostlen;
+ unsigned int portlen;
+ unsigned int datalen;
+ unsigned int querylen;
+ unsigned int fragmentlen;
+ unsigned int surbllen;
+
+ /* Flags */
+ int ipv6; /* URI contains IPv6 host */
+ int form; /* URI originated from form */
+ int is_phished; /* URI maybe phishing */
+ };
+ struct rspamd_url* rspamd_url_get_next (void *pool,
+ const char *start, char const **pos);
+ void * rspamd_mempool_new (unsigned long size);
+ ]]
+
+ test("Extract urls from text", function()
+ local pool = ffi.C.rspamd_mempool_new(4096)
+ local cases = {
+ {"test.com text", {"test.com", nil}},
+ {"mailto:A.User@example.com text", {"example.com", "A.User"}},
+ {"http://тест.рф:18 text", {"тест.рф", nil}},
+ {"http://user:password@тест.рф:18 text", {"тест.рф", "user"}},
+ }
+
+ for _,c in ipairs(cases) do
+ local res = ffi.C.rspamd_url_get_next(pool, c[1], nil)
+
+ assert_not_nil(res)
+ assert_equal(c[2][1], ffi.string(res.host, res.hostlen))
+
+ if c[2][2] then
+ assert_equal(c[2][2], ffi.string(res.user, res.userlen))
+ end
+ end
+ end)
+end) \ No newline at end of file