aboutsummaryrefslogtreecommitdiffstats
path: root/test/functional/lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-08-14 00:05:33 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-08-14 00:05:33 +0200
commit38042e8a569250c148b709c577ed7784acd9a167 (patch)
treeacdfc96f93cecb713bd4c9f01b42cc5c62b1b2b3 /test/functional/lua
parent38b9b3527b2beb223de5373b549819a8e1552c9f (diff)
downloadrspamd-38042e8a569250c148b709c577ed7784acd9a167.tar.gz
rspamd-38042e8a569250c148b709c577ed7784acd9a167.zip
[Test] Add test for TLD parts
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/tlds.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/functional/lua/tlds.lua b/test/functional/lua/tlds.lua
new file mode 100644
index 000000000..9f2d64feb
--- /dev/null
+++ b/test/functional/lua/tlds.lua
@@ -0,0 +1,56 @@
+rspamd_config:register_symbol({
+ name = 'TEST_TLD',
+ score = 1.0,
+ callback = function(task)
+ local prefixes = {
+ '',
+ 'example.'
+ }
+ local test_domains = {
+ 'example.ac',
+ 'example.b.br',
+ 'example.co',
+ 'example.city.kawasaki.jp',
+ 'example.com',
+ 'example.co.za',
+ 'example.in.net',
+ 'example.kawasaki.jp',
+ 'example.net',
+ 'example.net.in',
+ 'example.nom.br',
+ 'example.org',
+ 'example.org.ac',
+ 'example.ru.com',
+ 'example.za.net',
+ 'example.za.org',
+ 'org.org.za',
+ }
+ local worry = {}
+ local rspamd_mempool = require 'rspamd_mempool'
+ local rspamd_url = require 'rspamd_url'
+ local rspamd_util = require 'rspamd_util'
+ local pool = rspamd_mempool.create()
+ for _, d in ipairs(test_domains) do
+ (function()
+ for _, p in ipairs(prefixes) do
+ local test = rspamd_util.get_tld(p .. d)
+ if (test ~= d) then
+ table.insert(worry, 'util.get_tld:' .. p .. d .. ':' .. test)
+ return
+ end
+ local u = rspamd_url.create(pool, p .. d)
+ local test = u:get_tld()
+ if (test ~= d) then
+ table.insert(worry, 'url.get_tld:' .. p .. d .. ':' .. test)
+ return
+ end
+ end
+ end)()
+ end
+ if (#worry == 0) then
+ return true, "no worry"
+ else
+ return true, table.concat(worry, ",")
+ end
+ end
+})