From d4bab2f70adbabf14e734f4c9bc497843c298f5c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 28 Jul 2016 13:57:55 +0100 Subject: [PATCH] [Test] Reorder tests --- src/plugins/lua/multimap.lua | 173 ++++++------------ .../{general.robot => 100_general.robot} | 0 .../cases/{lua.robot => 101_lua.robot} | 0 .../{archives.robot => 105_archives.robot} | 0 .../compat-keyed.robot | 0 .../compat-plain.robot | 0 .../{statistics => 110_statistics}/lib.robot | 0 .../redis-keyed-siphash.robot | 0 .../redis-keyed-xxhash.robot | 0 .../redis-plain-siphash.robot | 0 .../redis-plain-xxhash.robot | 0 .../sqlite-broken-stats-dir.robot | 0 .../sqlite-keyed-siphash.robot | 0 .../sqlite-keyed-xxhash.robot | 0 .../sqlite-plain-siphash.robot | 0 .../sqlite-plain-xxhash.robot | 0 .../{fuzzy => 120_fuzzy}/encrypted.robot | 0 .../cases/{fuzzy => 120_fuzzy}/lib.robot | 0 .../cases/{fuzzy => 120_fuzzy}/plain.robot | 0 19 files changed, 61 insertions(+), 112 deletions(-) rename test/functional/cases/{general.robot => 100_general.robot} (100%) rename test/functional/cases/{lua.robot => 101_lua.robot} (100%) rename test/functional/cases/{archives.robot => 105_archives.robot} (100%) rename test/functional/cases/{statistics => 110_statistics}/compat-keyed.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/compat-plain.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/lib.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/redis-keyed-siphash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/redis-keyed-xxhash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/redis-plain-siphash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/redis-plain-xxhash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/sqlite-broken-stats-dir.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/sqlite-keyed-siphash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/sqlite-keyed-xxhash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/sqlite-plain-siphash.robot (100%) rename test/functional/cases/{statistics => 110_statistics}/sqlite-plain-xxhash.robot (100%) rename test/functional/cases/{fuzzy => 120_fuzzy}/encrypted.robot (100%) rename test/functional/cases/{fuzzy => 120_fuzzy}/lib.robot (100%) rename test/functional/cases/{fuzzy => 120_fuzzy}/plain.robot (100%) diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 3851e26c4..d4fcee6e4 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -29,7 +29,9 @@ local function ip_to_rbl(ip, rbl) return table.concat(ip:inversed_str_octets(), ".") .. '.' .. rbl end -local function multimap_callback(task, pre_filter) +local function multimap_callback(task, rule) + local pre_filter = rule['prefilter'] + -- Applies specific filter for input local function apply_filter(filter, input, rule) if filter == 'email:addr' or filter == 'email' then @@ -345,97 +347,16 @@ local function multimap_callback(task, pre_filter) end end - -- IP rules - local ip = task:get_from_ip() - if ip:is_valid() then - each(function(r) match_rule(r, ip) end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'ip' - end, rules)) - end - - -- Header rules - each(function(r) - local hv = task:get_header_full(r['header']) - match_list(r, hv, {'decoded'}) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'header' - end, rules)) - - -- Rcpt rules - if task:has_recipients() then - local rcpts = task:get_recipients() - each(function(r) - match_addr(r, rcpts) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'rcpt' - end, rules)) - end - - -- From rules - if task:has_from() then - local from = task:get_from() - if from then - each(function(r) - match_addr(r, from) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'from' - end, rules)) - end - end - -- URL rules - if task:has_urls() then - local urls = task:get_urls() - for i,url in ipairs(urls) do - each(function(r) - match_url(r, url) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'url' - end, rules)) - end - end - -- Filename rules - local function check_file(fn) - each(function(r) - match_filename(r, fn) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'filename' - end, rules)) - end - -- Body rules - each(function(r) - match_content(r) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'content' - end, rules)) - - local parts = task:get_parts() - for i,p in ipairs(parts) do - if p:is_archive() then - local fnames = p:get_archive():get_files() - - for ii,fn in ipairs(fnames) do - check_file(fn) - end - end - - local fn = p:get_filename() - if fn then - check_file(fn) - end - end - -- RBL rules - if ip:is_valid() then - each(function(r) + local rt = rule['type'] + if rt == 'ip' or rt == 'dnsbl' then + local ip = task:get_from_ip() + if ip:is_valid() then + if rt == 'ip' then + match_rule(rule, ip) + else local cb = function (resolver, to_resolve, results, err, rbl) if results then - task:insert_result(r['symbol'], 1, r['map']) + task:insert_result(rule['symbol'], 1, r['map']) if pre_filter then task:set_pre_result(r['action'], 'Matched map: ' .. r['symbol']) @@ -444,22 +365,56 @@ local function multimap_callback(task, pre_filter) end task:get_resolver():resolve_a({task = task, - name = ip_to_rbl(ip, r['map']), + name = ip_to_rbl(ip, rule['map']), callback = cb, - }) - end, - filter(function(r) - return pre_filter == r['prefilter'] and r['type'] == 'dnsbl' - end, rules)) - end -end + }) + end + end + elseif rt == 'header' then + local hv = task:get_header_full(r['header']) + match_list(rule, hv, {'decoded'}) + elseif rt == 'rcpt' then + if task:has_recipients('smtp') then + local rcpts = task:get_recipients('smtp') + match_addr(rule, rcpts) + end + elseif rt == 'from' then + if task:has_from('smtp') then + local from = task:get_from('smtp') + match_addr(rule, from) + end + elseif rt == 'url' then + if task:has_urls() then + local urls = task:get_urls() + for i,url in ipairs(urls) do + match_url(rule, url) + end + end + elseif rt == 'filename' then + local parts = task:get_parts() + for i,p in ipairs(parts) do + if p:is_archive() then + local fnames = p:get_archive():get_files() + + for ii,fn in ipairs(fnames) do + match_filename(rule, fn) + end + end -local function multimap_filter_callback(task) - multimap_callback(task, false) + local fn = p:get_filename() + if fn then + match_filename(rule, fn) + end + end + elseif rt == 'content' then + match_content(rule) + end end -local function multimap_prefilter_callback(task) - multimap_callback(task, true) +local function gen_multimap_callback(rule) + return function(task) + multimap_callback(task, rule) + end end local function add_multimap_rule(key, newrule) @@ -587,17 +542,11 @@ if opts and type(opts) == 'table' then end -- add fake symbol to check all maps inside a single callback if any(function(r) return not r['prefilter'] end, rules) then - local id = rspamd_config:register_symbol({ - type = 'callback', - priority = -1, - callback = multimap_filter_callback, - flags = 'empty' - }) for i,rule in ipairs(rules) do rspamd_config:register_symbol({ - type = 'virtual', + type = 'normal', name = rule['symbol'], - parent = id, + callback = gen_multimap_callback(rule), }) end end @@ -605,8 +554,8 @@ if opts and type(opts) == 'table' then if any(function(r) return r['prefilter'] end, rules) then rspamd_config:register_symbol({ type = 'prefilter', - name = 'MULTIMAP_PREFILTERS', - callback = multimap_prefilter_callback + name = rule['symbol'], + callback = gen_multimap_callback(rule), }) end end diff --git a/test/functional/cases/general.robot b/test/functional/cases/100_general.robot similarity index 100% rename from test/functional/cases/general.robot rename to test/functional/cases/100_general.robot diff --git a/test/functional/cases/lua.robot b/test/functional/cases/101_lua.robot similarity index 100% rename from test/functional/cases/lua.robot rename to test/functional/cases/101_lua.robot diff --git a/test/functional/cases/archives.robot b/test/functional/cases/105_archives.robot similarity index 100% rename from test/functional/cases/archives.robot rename to test/functional/cases/105_archives.robot diff --git a/test/functional/cases/statistics/compat-keyed.robot b/test/functional/cases/110_statistics/compat-keyed.robot similarity index 100% rename from test/functional/cases/statistics/compat-keyed.robot rename to test/functional/cases/110_statistics/compat-keyed.robot diff --git a/test/functional/cases/statistics/compat-plain.robot b/test/functional/cases/110_statistics/compat-plain.robot similarity index 100% rename from test/functional/cases/statistics/compat-plain.robot rename to test/functional/cases/110_statistics/compat-plain.robot diff --git a/test/functional/cases/statistics/lib.robot b/test/functional/cases/110_statistics/lib.robot similarity index 100% rename from test/functional/cases/statistics/lib.robot rename to test/functional/cases/110_statistics/lib.robot diff --git a/test/functional/cases/statistics/redis-keyed-siphash.robot b/test/functional/cases/110_statistics/redis-keyed-siphash.robot similarity index 100% rename from test/functional/cases/statistics/redis-keyed-siphash.robot rename to test/functional/cases/110_statistics/redis-keyed-siphash.robot diff --git a/test/functional/cases/statistics/redis-keyed-xxhash.robot b/test/functional/cases/110_statistics/redis-keyed-xxhash.robot similarity index 100% rename from test/functional/cases/statistics/redis-keyed-xxhash.robot rename to test/functional/cases/110_statistics/redis-keyed-xxhash.robot diff --git a/test/functional/cases/statistics/redis-plain-siphash.robot b/test/functional/cases/110_statistics/redis-plain-siphash.robot similarity index 100% rename from test/functional/cases/statistics/redis-plain-siphash.robot rename to test/functional/cases/110_statistics/redis-plain-siphash.robot diff --git a/test/functional/cases/statistics/redis-plain-xxhash.robot b/test/functional/cases/110_statistics/redis-plain-xxhash.robot similarity index 100% rename from test/functional/cases/statistics/redis-plain-xxhash.robot rename to test/functional/cases/110_statistics/redis-plain-xxhash.robot diff --git a/test/functional/cases/statistics/sqlite-broken-stats-dir.robot b/test/functional/cases/110_statistics/sqlite-broken-stats-dir.robot similarity index 100% rename from test/functional/cases/statistics/sqlite-broken-stats-dir.robot rename to test/functional/cases/110_statistics/sqlite-broken-stats-dir.robot diff --git a/test/functional/cases/statistics/sqlite-keyed-siphash.robot b/test/functional/cases/110_statistics/sqlite-keyed-siphash.robot similarity index 100% rename from test/functional/cases/statistics/sqlite-keyed-siphash.robot rename to test/functional/cases/110_statistics/sqlite-keyed-siphash.robot diff --git a/test/functional/cases/statistics/sqlite-keyed-xxhash.robot b/test/functional/cases/110_statistics/sqlite-keyed-xxhash.robot similarity index 100% rename from test/functional/cases/statistics/sqlite-keyed-xxhash.robot rename to test/functional/cases/110_statistics/sqlite-keyed-xxhash.robot diff --git a/test/functional/cases/statistics/sqlite-plain-siphash.robot b/test/functional/cases/110_statistics/sqlite-plain-siphash.robot similarity index 100% rename from test/functional/cases/statistics/sqlite-plain-siphash.robot rename to test/functional/cases/110_statistics/sqlite-plain-siphash.robot diff --git a/test/functional/cases/statistics/sqlite-plain-xxhash.robot b/test/functional/cases/110_statistics/sqlite-plain-xxhash.robot similarity index 100% rename from test/functional/cases/statistics/sqlite-plain-xxhash.robot rename to test/functional/cases/110_statistics/sqlite-plain-xxhash.robot diff --git a/test/functional/cases/fuzzy/encrypted.robot b/test/functional/cases/120_fuzzy/encrypted.robot similarity index 100% rename from test/functional/cases/fuzzy/encrypted.robot rename to test/functional/cases/120_fuzzy/encrypted.robot diff --git a/test/functional/cases/fuzzy/lib.robot b/test/functional/cases/120_fuzzy/lib.robot similarity index 100% rename from test/functional/cases/fuzzy/lib.robot rename to test/functional/cases/120_fuzzy/lib.robot diff --git a/test/functional/cases/fuzzy/plain.robot b/test/functional/cases/120_fuzzy/plain.robot similarity index 100% rename from test/functional/cases/fuzzy/plain.robot rename to test/functional/cases/120_fuzzy/plain.robot -- 2.39.5