| 1 |
rspamd_config:register_symbol({ |
| 2 |
name = 'TEST_TLD', |
| 3 |
score = 1.0, |
| 4 |
callback = function() |
| 5 |
local prefixes = { |
| 6 |
'', |
| 7 |
'example.' |
| 8 |
} |
| 9 |
local test_domains = { |
| 10 |
'example.ac', |
| 11 |
'example.b.br', |
| 12 |
'example.co', |
| 13 |
'example.com', |
| 14 |
'example.co.za', |
| 15 |
'example.in.net', |
| 16 |
'example.star.kawasaki.jp', |
| 17 |
'example.net', |
| 18 |
'example.net.in', |
| 19 |
'example.star.nom.br', |
| 20 |
'example.org', |
| 21 |
'example.org.ac', |
| 22 |
'example.ru.com', |
| 23 |
'example.za.net', |
| 24 |
'example.za.org', |
| 25 |
'org.org.za', |
| 26 |
} |
| 27 |
local worry = {} |
| 28 |
local rspamd_mempool = require 'rspamd_mempool' |
| 29 |
local rspamd_url = require 'rspamd_url' |
| 30 |
local rspamd_util = require 'rspamd_util' |
| 31 |
local pool = rspamd_mempool.create() |
| 32 |
for _, d in ipairs(test_domains) do |
| 33 |
(function() |
| 34 |
for _, p in ipairs(prefixes) do |
| 35 |
local test = rspamd_util.get_tld(p .. d) |
| 36 |
if (test ~= d) then |
| 37 |
local opt = string.format('util.get_tld:p=%s;d=%s;got=%s', p, d, test) |
| 38 |
table.insert(worry, opt) |
| 39 |
return |
| 40 |
end |
| 41 |
local u = rspamd_url.create(pool, p .. d) |
| 42 |
assert(u, "cannot parse string: " .. p .. d) |
| 43 |
test = u:get_tld() |
| 44 |
if (test ~= d) then |
| 45 |
local opt = string.format('url.create:p=%s;d=%s;got=%s', p, d, test) |
| 46 |
table.insert(worry, opt) |
| 47 |
return |
| 48 |
end |
| 49 |
end |
| 50 |
end)() |
| 51 |
end |
| 52 |
if (#worry == 0) then |
| 53 |
return true, 1.0, "no worry" |
| 54 |
else |
| 55 |
return true, 1.0, worry |
| 56 |
end |
| 57 |
end |
| 58 |
}) |