diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-07-17 21:06:31 +0100 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-07-17 21:06:31 +0100 |
commit | d5c2f00bf967666cc923fff8f8fe776036f337c1 (patch) | |
tree | 4490a6d123340d01933782d6a38bde1811b74719 /test | |
parent | 1386abcfc2fcbb217b7ba9bc69f8a5c522231855 (diff) | |
download | rspamd-d5c2f00bf967666cc923fff8f8fe776036f337c1.tar.gz rspamd-d5c2f00bf967666cc923fff8f8fe776036f337c1.zip |
[Test] Add test for pre & post filters
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/cases/lua.robot | 6 | ||||
-rw-r--r-- | test/functional/lua/prepostfilters.lua | 65 |
2 files changed, 71 insertions, 0 deletions
diff --git a/test/functional/cases/lua.robot b/test/functional/cases/lua.robot index f3a3567ec..5e5dff6c8 100644 --- a/test/functional/cases/lua.robot +++ b/test/functional/cases/lua.robot @@ -22,6 +22,12 @@ Dependencies ${result} = Scan Message With Rspamc ${MESSAGE} Check Rspamc ${result} DEP10 +Pre and Post Filters + [Setup] Lua Setup ${TESTDIR}/lua/prepostfilters.lua + ${result} = Scan Message With Rspamc ${MESSAGE} + Check Rspamc ${result} TEST_PRE + Check Rspamc ${result} TEST_POST rc_nocheck=1 + *** Keywords *** Lua Setup [Arguments] ${LUA_SCRIPT} diff --git a/test/functional/lua/prepostfilters.lua b/test/functional/lua/prepostfilters.lua new file mode 100644 index 000000000..4f14d0222 --- /dev/null +++ b/test/functional/lua/prepostfilters.lua @@ -0,0 +1,65 @@ +for i = 1,10 do + local name = string.format('DEP_TEST%d', i) + local dep_name = string.format('DEP_TEST%d', i - 1) + rspamd_config:register_symbol({ + type = 'normal', + name = name, + callback = function(task) + local function dns_cb() + if i ~= 1 then + if task:has_symbol(dep_name) then + task:insert_result(name, 1.0) + end + else + task:insert_result(name, 1.0) + end + end + if task:has_symbol('TEST_PRE') then + local r = task:get_resolver() + r:resolve_a(task:get_session(), task:get_mempool(), 'example.com', dns_cb) + end + end + }) + + if i ~= 1 then + rspamd_config:register_dependency(name, dep_name) + end + + rspamd_config:set_metric_symbol({ + name = name, + score = 1.0 + }) +end + + +rspamd_config:register_symbol({ + type = 'postfilter', + name = 'TEST_POST', + callback = function(task) + for i = 1,10 do + local name = string.format('DEP_TEST%d', i) + if not task:has_symbol(name) then + return + end + end + if task:has_symbol('TEST_PRE') then + task:insert_result('TEST_POST', 1.0) + end + end +}) +rspamd_config:set_metric_symbol({ + name = 'TEST_POST', + score = 1.0 +}) + +rspamd_config:register_symbol({ + type = 'prefilter', + name = 'TEST_PRE', + callback = function(task) + task:insert_result('TEST_PRE', 1.0) + end +}) +rspamd_config:set_metric_symbol({ + name = 'TEST_PRE', + score = 1.0 +}) |