aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-28 13:57:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-07-28 13:57:55 +0100
commitd4bab2f70adbabf14e734f4c9bc497843c298f5c (patch)
tree753fc2f88f493c249d25bc180b282098340b3d8b
parentd7ea09ea1f70fb94fb6f8510af16805c3f71b70f (diff)
downloadrspamd-d4bab2f70adbabf14e734f4c9bc497843c298f5c.tar.gz
rspamd-d4bab2f70adbabf14e734f4c9bc497843c298f5c.zip
[Test] Reorder tests
-rw-r--r--src/plugins/lua/multimap.lua173
-rw-r--r--test/functional/cases/100_general.robot (renamed from test/functional/cases/general.robot)0
-rw-r--r--test/functional/cases/101_lua.robot (renamed from test/functional/cases/lua.robot)0
-rw-r--r--test/functional/cases/105_archives.robot (renamed from test/functional/cases/archives.robot)0
-rw-r--r--test/functional/cases/110_statistics/compat-keyed.robot (renamed from test/functional/cases/statistics/compat-keyed.robot)0
-rw-r--r--test/functional/cases/110_statistics/compat-plain.robot (renamed from test/functional/cases/statistics/compat-plain.robot)0
-rw-r--r--test/functional/cases/110_statistics/lib.robot (renamed from test/functional/cases/statistics/lib.robot)0
-rw-r--r--test/functional/cases/110_statistics/redis-keyed-siphash.robot (renamed from test/functional/cases/statistics/redis-keyed-siphash.robot)0
-rw-r--r--test/functional/cases/110_statistics/redis-keyed-xxhash.robot (renamed from test/functional/cases/statistics/redis-keyed-xxhash.robot)0
-rw-r--r--test/functional/cases/110_statistics/redis-plain-siphash.robot (renamed from test/functional/cases/statistics/redis-plain-siphash.robot)0
-rw-r--r--test/functional/cases/110_statistics/redis-plain-xxhash.robot (renamed from test/functional/cases/statistics/redis-plain-xxhash.robot)0
-rw-r--r--test/functional/cases/110_statistics/sqlite-broken-stats-dir.robot (renamed from test/functional/cases/statistics/sqlite-broken-stats-dir.robot)0
-rw-r--r--test/functional/cases/110_statistics/sqlite-keyed-siphash.robot (renamed from test/functional/cases/statistics/sqlite-keyed-siphash.robot)0
-rw-r--r--test/functional/cases/110_statistics/sqlite-keyed-xxhash.robot (renamed from test/functional/cases/statistics/sqlite-keyed-xxhash.robot)0
-rw-r--r--test/functional/cases/110_statistics/sqlite-plain-siphash.robot (renamed from test/functional/cases/statistics/sqlite-plain-siphash.robot)0
-rw-r--r--test/functional/cases/110_statistics/sqlite-plain-xxhash.robot (renamed from test/functional/cases/statistics/sqlite-plain-xxhash.robot)0
-rw-r--r--test/functional/cases/120_fuzzy/encrypted.robot (renamed from test/functional/cases/fuzzy/encrypted.robot)0
-rw-r--r--test/functional/cases/120_fuzzy/lib.robot (renamed from test/functional/cases/fuzzy/lib.robot)0
-rw-r--r--test/functional/cases/120_fuzzy/plain.robot (renamed from test/functional/cases/fuzzy/plain.robot)0
19 files changed, 61 insertions, 112 deletions
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
index 8876ef980..8876ef980 100644
--- a/test/functional/cases/general.robot
+++ b/test/functional/cases/100_general.robot
diff --git a/test/functional/cases/lua.robot b/test/functional/cases/101_lua.robot
index 5e5dff6c8..5e5dff6c8 100644
--- a/test/functional/cases/lua.robot
+++ b/test/functional/cases/101_lua.robot
diff --git a/test/functional/cases/archives.robot b/test/functional/cases/105_archives.robot
index 16a14bfda..16a14bfda 100644
--- a/test/functional/cases/archives.robot
+++ b/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
index 1242df12c..1242df12c 100644
--- a/test/functional/cases/statistics/compat-keyed.robot
+++ b/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
index 12bbaedcd..12bbaedcd 100644
--- a/test/functional/cases/statistics/compat-plain.robot
+++ b/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
index 5f9e96038..5f9e96038 100644
--- a/test/functional/cases/statistics/lib.robot
+++ b/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
index ec95efcd1..ec95efcd1 100644
--- a/test/functional/cases/statistics/redis-keyed-siphash.robot
+++ b/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
index 5a7b2daf3..5a7b2daf3 100644
--- a/test/functional/cases/statistics/redis-keyed-xxhash.robot
+++ b/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
index d436b1a68..d436b1a68 100644
--- a/test/functional/cases/statistics/redis-plain-siphash.robot
+++ b/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
index 0c45ac16b..0c45ac16b 100644
--- a/test/functional/cases/statistics/redis-plain-xxhash.robot
+++ b/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
index 57d75c294..57d75c294 100644
--- a/test/functional/cases/statistics/sqlite-broken-stats-dir.robot
+++ b/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
index 8b9661a9a..8b9661a9a 100644
--- a/test/functional/cases/statistics/sqlite-keyed-siphash.robot
+++ b/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
index 7a51e93ae..7a51e93ae 100644
--- a/test/functional/cases/statistics/sqlite-keyed-xxhash.robot
+++ b/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
index 2f88e0a95..2f88e0a95 100644
--- a/test/functional/cases/statistics/sqlite-plain-siphash.robot
+++ b/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
index dd8198222..dd8198222 100644
--- a/test/functional/cases/statistics/sqlite-plain-xxhash.robot
+++ b/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
index 45408d7f8..45408d7f8 100644
--- a/test/functional/cases/fuzzy/encrypted.robot
+++ b/test/functional/cases/120_fuzzy/encrypted.robot
diff --git a/test/functional/cases/fuzzy/lib.robot b/test/functional/cases/120_fuzzy/lib.robot
index e5e9cbcb7..e5e9cbcb7 100644
--- a/test/functional/cases/fuzzy/lib.robot
+++ b/test/functional/cases/120_fuzzy/lib.robot
diff --git a/test/functional/cases/fuzzy/plain.robot b/test/functional/cases/120_fuzzy/plain.robot
index 2fc2fd5ef..2fc2fd5ef 100644
--- a/test/functional/cases/fuzzy/plain.robot
+++ b/test/functional/cases/120_fuzzy/plain.robot