summaryrefslogtreecommitdiffstats
path: root/test/functional/lua/tlds.lua
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 21:30:40 +0000
commit133a45c109da5310add55824db21af5239951f93 (patch)
treeba6ac4c0a950a0dda56451944315d66409923918 /test/functional/lua/tlds.lua
parentInitial commit. (diff)
downloadrspamd-133a45c109da5310add55824db21af5239951f93.tar.xz
rspamd-133a45c109da5310add55824db21af5239951f93.zip
Adding upstream version 3.8.1.upstream/3.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/functional/lua/tlds.lua')
-rw-r--r--test/functional/lua/tlds.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/functional/lua/tlds.lua b/test/functional/lua/tlds.lua
new file mode 100644
index 0000000..24836b3
--- /dev/null
+++ b/test/functional/lua/tlds.lua
@@ -0,0 +1,58 @@
+rspamd_config:register_symbol({
+ name = 'TEST_TLD',
+ score = 1.0,
+ callback = function()
+ local prefixes = {
+ '',
+ 'example.'
+ }
+ local test_domains = {
+ 'example.ac',
+ 'example.b.br',
+ 'example.co',
+ 'example.com',
+ 'example.co.za',
+ 'example.in.net',
+ 'example.star.kawasaki.jp',
+ 'example.net',
+ 'example.net.in',
+ 'example.star.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
+ local opt = string.format('util.get_tld:p=%s;d=%s;got=%s', p, d, test)
+ table.insert(worry, opt)
+ return
+ end
+ local u = rspamd_url.create(pool, p .. d)
+ assert(u, "cannot parse string: " .. p .. d)
+ test = u:get_tld()
+ if (test ~= d) then
+ local opt = string.format('url.create:p=%s;d=%s;got=%s', p, d, test)
+ table.insert(worry, opt)
+ return
+ end
+ end
+ end)()
+ end
+ if (#worry == 0) then
+ return true, 1.0, "no worry"
+ else
+ return true, 1.0, worry
+ end
+ end
+})