1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
|