Ver código fonte

[Minor] Lint rspamadm & test suite scripts

tags/1.4.0
Andrew Lewis 7 anos atrás
pai
commit
da83f5296a

+ 10
- 6
.luacheckrc Ver arquivo

@@ -2,11 +2,16 @@ codes = true
std = 'min'

exclude_files = {
'/**/contrib/**',
'/**/test/lua/**',
}

globals = {
'check_header_delimiter_empty',
'check_header_delimiter_tab',
'classifiers',
'config',
'kmail_msgid',
'rspamd_config',
'rspamd_count_metatokens',
'rspamd_gen_metatokens',
@@ -21,13 +26,12 @@ globals = {
ignore = {
}

files['/**/rules/regexp/headers.lua'].globals = {
'check_header_delimiter_empty',
'check_header_delimiter_tab',
'kmail_msgid',
}

files['/**/src/plugins/lua/spamassassin.lua'].globals = {
'ffi',
'jit',
}

files['/**/src/rspamadm/*'].globals = {
'ansicolors',
'getopt',
}

+ 3
- 4
src/rspamadm/confighelp.lua Ver arquivo

@@ -1,4 +1,3 @@
local util = require "rspamd_util"
local opts = {}
local known_attrs = {
data = 1,
@@ -20,7 +19,7 @@ local function maybe_print_color(key)
end
end

local function sort_values(tbl, opts)
local function sort_values(tbl)
local res = {}
for k, v in pairs(tbl) do
table.insert(res, { key = k, value = v })
@@ -91,7 +90,7 @@ local function print_help(key, value, tabs)
end

local sorted = sort_values(value)
for i, v in ipairs(sorted) do
for _, v in ipairs(sorted) do
if not known_attrs[v['key']] then
-- We need to go deeper
print_help(v['key'], v['value'], tabs .. '\t')
@@ -104,7 +103,7 @@ return function(args, res)

local sorted = sort_values(res)

for i,v in ipairs(sorted) do
for _,v in ipairs(sorted) do
print_help(v['key'], v['value'], '')
print('')
end

+ 20
- 10
src/rspamadm/fuzzy_convert.lua Ver arquivo

@@ -41,10 +41,13 @@ end

local function send_digests(digests, redis_host, redis_password, redis_db)
local conn, err = connect_redis(redis_host, redis_password, redis_db)
if not conn then return false end
local _, v
if err then
print(err)
return false
end
local ret
for _, v in ipairs(digests) do
local ret, err = conn:add_cmd('HMSET', {
ret, err = conn:add_cmd('HMSET', {
'fuzzy' .. v[1],
'F', v[2],
'V', v[3],
@@ -72,10 +75,13 @@ end

local function send_shingles(shingles, redis_host, redis_password, redis_db)
local conn, err = connect_redis(redis_host, redis_password, redis_db)
if not conn then return false end
local _, v
if err then
print("Redis error: " .. err)
return false
end
local ret
for _, v in ipairs(shingles) do
local ret, err = conn:add_cmd('SET', {
ret, err = conn:add_cmd('SET', {
'fuzzy_' .. v[2] .. '_' .. v[1],
v[4],
})
@@ -102,8 +108,12 @@ end

local function update_counters(total, redis_host, redis_password, redis_db)
local conn, err = connect_redis(redis_host, redis_password, redis_db)
if not conn then return false end
local ret, err = conn:add_cmd('SET', {
if err then
print(err)
return false
end
local ret
ret, err = conn:add_cmd('SET', {
'fuzzylocal',
total,
})
@@ -111,7 +121,7 @@ local function update_counters(total, redis_host, redis_password, redis_db)
print('Cannot batch SET command: ' .. err)
return false
end
local ret, err = conn:add_cmd('SET', {
ret, err = conn:add_cmd('SET', {
'fuzzy_count',
total,
})
@@ -127,7 +137,7 @@ local function update_counters(total, redis_host, redis_password, redis_db)
return true
end

return function (args, res)
return function (_, res)
local db = sqlite3.open(res['source_db'])
local shingles = {}
local digests = {}

+ 15
- 15
src/rspamadm/fuzzy_stat.lua Ver arquivo

@@ -47,7 +47,7 @@ local function print_stat(st, tabs)
end

-- Sort by checked
local function sort_ips(tbl, opts)
local function sort_ips(tbl, _opts)
local res = {}
for k,v in pairs(tbl) do
table.insert(res, {ip = k, data = v})
@@ -55,23 +55,23 @@ local function sort_ips(tbl, opts)

local function sort_order(elt)
local key = 'checked'
local res = 0
local _res = 0

if opts['sort'] then
if opts['sort'] == 'matched' then
if _opts['sort'] then
if _opts['sort'] == 'matched' then
key = 'matched'
elseif opts['sort'] == 'errors' then
elseif _opts['sort'] == 'errors' then
key = 'errors'
elseif opts['sort'] == 'ip' then
elseif _opts['sort'] == 'ip' then
return elt['ip']
end
end

if elt['data'][key] then
res = elt['data'][key]
_res = elt['data'][key]
end

return res
return _res
end

table.sort(res, function(a, b)
@@ -150,7 +150,7 @@ return function(args, res)
opts = getopt(args, '')

if wrk then
for i,pr in pairs(wrk) do
for _,pr in pairs(wrk) do
-- processes cycle
if pr['data'] then
local id = pr['id']
@@ -227,16 +227,16 @@ return function(args, res)
local res_keys = st['keys']
if res_keys and not opts['no-keys'] and not opts['short'] then
print('Keys statistics:')
for k,st in pairs(res_keys) do
for k,_st in pairs(res_keys) do
print(string.format('Key id: %s', k))
print_stat(st, '\t')
print_stat(_st, '\t')

if st['ips'] and not opts['no-ips'] then
if _st['ips'] and not opts['no-ips'] then
print('')
print('\tIPs stat:')
local sorted_ips = sort_ips(st['ips'], opts)
local sorted_ips = sort_ips(_st['ips'], opts)

for i,v in ipairs(sorted_ips) do
for _,v in ipairs(sorted_ips) do
print(string.format('\t%s', v['ip']))
print_stat(v['data'], '\t\t')
print('')
@@ -264,7 +264,7 @@ return function(args, res)
print('IPs statistics:')

local sorted_ips = sort_ips(res_ips, opts)
for i, v in ipairs(sorted_ips) do
for _, v in ipairs(sorted_ips) do
print(string.format('%s', v['ip']))
print_stat(v['data'], '\t')
print('')

+ 5
- 5
src/rspamadm/stat_convert.lua Ver arquivo

@@ -41,6 +41,7 @@ local function convert_learned(cache, server, password, redis_db)
local converted = 0
local db = sqlite3.open(cache)
local ret = true
local err_str

if not db then
print('Cannot open cache database: ' .. cache)
@@ -84,7 +85,6 @@ local function convert_learned(cache, server, password, redis_db)
end
db:sql('COMMIT;')

local err_str
if ret then
ret,err_str = conn:exec()
end
@@ -99,7 +99,7 @@ local function convert_learned(cache, server, password, redis_db)
return ret
end

return function (args, res)
return function (_, res)
local db = sqlite3.open(res['source_db'])
local tokens = {}
local num = 0
@@ -110,8 +110,8 @@ return function (args, res)
local learns = {}
local redis_password = res['redis_password']
local redis_db = nil
local ret = false
local cmd = 'HINCRBY'
local ret, err_str

if res['redis_db'] then
redis_db = tostring(res['redis_db'])
@@ -166,7 +166,7 @@ return function (args, res)
num = num + 1
total = total + 1
if num > lim then
local ret,err_str = send_redis(res['redis_host'], res['symbol'],
ret,err_str = send_redis(res['redis_host'], res['symbol'],
tokens, redis_password, redis_db, cmd)
if not ret then
print('Cannot send tokens to the redis server: ' .. err_str)
@@ -178,7 +178,7 @@ return function (args, res)
end
end
if #tokens > 0 then
local ret, err_str = send_redis(res['redis_host'], res['symbol'], tokens,
ret, err_str = send_redis(res['redis_host'], res['symbol'], tokens,
redis_password, redis_db, cmd)

if not ret then

+ 1
- 3
test/functional/lua/deps.lua Ver arquivo

@@ -1,5 +1,3 @@
local logger = require "rspamd_logger"

local cb = function(task)
task:insert_result('TOP', 1.0)
end
@@ -29,4 +27,4 @@ rspamd_config:register_dependency('DEP1', 'TOP')
for i = 2,10 do
rspamd_config:register_symbol('DEP' .. tostring(i), 1.0, cb_gen(i - 1))
rspamd_config:register_dependency('DEP' .. tostring(i), 'DEP' .. tostring(i - 1))
end
end

+ 0
- 2
test/functional/lua/flags.lua Ver arquivo

@@ -24,8 +24,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]--

local logger = require "rspamd_logger"

rspamd_config:register_post_filter(function(task)
task:set_flag('no_stat')
task:set_flag('no_log', false)

+ 1
- 1
test/functional/lua/mapreload.lua Ver arquivo

@@ -6,7 +6,7 @@ local test_map = rspamd_config:add_map ({
rspamd_config:register_symbol({
name = 'MAP_SET_HIT_AND_MISS',
score = 1.0,
callback = function(task)
callback = function()
if (test_map:get_key('example.com') and not test_map:get_key('rspamd.com')) then
return true, 'example.com'
elseif (test_map:get_key('rspamd.com') and not test_map:get_key('example.com')) then

+ 1
- 1
test/functional/lua/simple.lua Ver arquivo

@@ -1,7 +1,7 @@
rspamd_config:register_symbol({
name = 'SIMPLE_TEST',
score = 1.0,
callback = function(task)
callback = function()
return true, 'Fires always'
end
})

+ 2
- 2
test/functional/lua/tlds.lua Ver arquivo

@@ -1,7 +1,7 @@
rspamd_config:register_symbol({
name = 'TEST_TLD',
score = 1.0,
callback = function(task)
callback = function()
local prefixes = {
'',
'example.'
@@ -38,7 +38,7 @@ rspamd_config:register_symbol({
return
end
local u = rspamd_url.create(pool, p .. d)
local test = u:get_tld()
test = u:get_tld()
if (test ~= d) then
table.insert(worry, 'url.get_tld:' .. p .. d .. ':' .. test)
return

Carregando…
Cancelar
Salvar