Debian Codegraph @

test/lua/rspamd_test_helper.lua

raw
1 -- Load FFI: try LuaJIT's built-in ffi first, then cffi-lua for standard Lua
2 local ok, ffi = pcall(require, "ffi")
3 if not ok then
4 ffi = require("cffi")
5 end
6 local cfg = rspamd_config
7
8 ffi.cdef[[
9 void rspamd_url_init (const char *tld_file);
10 ]]
11 local exports = {}
12 -- Export ffi so tests can use it without their own require
13 exports.ffi = ffi
14
15 local function default_tld_file()
16 local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1")
17 return string.format('%s/unit/%s', test_dir, "test_tld.dat")
18 end
19
20 function exports.init_url_parser(file)
21 ffi.C.rspamd_url_init(file or default_tld_file())
22 end
23
24 function exports.default_config()
25 local tld_file = default_tld_file()
26
27 local config = {
28 options = {
29 filters = {'spf', 'dkim', 'regexp'},
30 url_tld = tld_file,
31 dns = {
32 nameserver = {'8.8.8.8'}
33 },
34 },
35 logging = {
36 type = 'console',
37 level = 'debug'
38 },
39 metric = {
40 name = 'default',
41 actions = {
42 reject = 100500,
43 },
44 unknown_weight = 1
45 }
46 }
47
48 return config
49 end
50
51 return exports