aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-15 17:14:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-04-15 17:14:55 +0100
commitb2d60bca95218992b832738984ef009f7639bb09 (patch)
treea83094fe3c3d2374629bb4bdffd77e3954b3a1e2 /test/lua
parent0c94da7bd85622fc0a7576bc3c94b635933fb0e7 (diff)
downloadrspamd-b2d60bca95218992b832738984ef009f7639bb09.tar.gz
rspamd-b2d60bca95218992b832738984ef009f7639bb09.zip
Fix unit tests.
Diffstat (limited to 'test/lua')
-rw-r--r--test/lua/unit/url.lua57
-rw-r--r--test/lua/unit/utf.lua4
2 files changed, 16 insertions, 45 deletions
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
index e0b229131..85723b741 100644
--- a/test/lua/unit/url.lua
+++ b/test/lua/unit/url.lua
@@ -2,56 +2,21 @@
context("URL check functions", function()
local mpool = require("rspamd_mempool")
+ local url = require("rspamd_url")
+ local logger = require("rspamd_logger")
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_config;
- struct rspamd_url* rspamd_url_get_next (void *pool,
- const char *start, char const **pos, int *statep);
- void * rspamd_mempool_new (unsigned long size);
void rspamd_url_init (const char *tld_file);
]]
-
+
test("Extract urls from text", function()
- local pool = ffi.C.rspamd_mempool_new(4096)
+ local pool = mpool.create()
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@тест2.РФ:18 text", {"тест2.рф", "user"}},
+ {"somebody@example.com", {"example.com", "somebody"}},
}
local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
@@ -59,14 +24,20 @@ context("URL check functions", function()
ffi.C.rspamd_url_init(string.format('%s/%s', test_dir, "test_tld.dat"))
for _,c in ipairs(cases) do
- local res = ffi.C.rspamd_url_get_next(pool, c[1], nil, nil)
+ local res = url.create(pool, c[1])
assert_not_nil(res, "cannot parse " .. c[1])
- assert_equal(c[2][1], ffi.string(res.host, res.hostlen))
+ local t = res:to_table()
+ --local s = logger.slog("%1 -> %2", c[1], t)
+ --print(s)
+ assert_not_nil(t, "cannot convert to table " .. c[1])
+ assert_equal(c[2][1], t['host'])
if c[2][2] then
- assert_equal(c[2][2], ffi.string(res.user, res.userlen))
+ assert_equal(c[2][2], t['user'])
end
end
+
+ pool:destroy()
end)
end) \ No newline at end of file
diff --git a/test/lua/unit/utf.lua b/test/lua/unit/utf.lua
index 27988f918..e22eb2a2f 100644
--- a/test/lua/unit/utf.lua
+++ b/test/lua/unit/utf.lua
@@ -14,7 +14,7 @@ context("UTF8 check functions", function()
}
for _,c in ipairs(cases) do
- local buf = ffi.new("char[?]", #c[1])
+ local buf = ffi.new("char[?]", #c[1] + 1)
ffi.copy(buf, c[1])
ffi.C.rspamd_str_lc_utf8(buf, #c[1])
local s = ffi.string(buf)
@@ -30,7 +30,7 @@ context("UTF8 check functions", function()
}
for _,c in ipairs(cases) do
- local buf = ffi.new("char[?]", #c[1])
+ local buf = ffi.new("char[?]", #c[1] + 1)
ffi.copy(buf, c[1])
ffi.C.rspamd_str_lc(buf, #c[1])
local s = ffi.string(buf)