]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add test for TLD parts 832/head
authorAndrew Lewis <nerf@judo.za.org>
Sat, 13 Aug 2016 22:05:33 +0000 (00:05 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Sat, 13 Aug 2016 22:05:33 +0000 (00:05 +0200)
test/functional/cases/101_lua.robot
test/functional/cases/121_json/lib.robot
test/functional/cases/140_proxy.robot
test/functional/configs/lua_test.conf
test/functional/lua/tlds.lua [new file with mode: 0644]

index c465491f15eb656b136e8aaa1742043136f63251..27bb867f7d8033f4e421f6b4b28644d8ff7de513 100644 (file)
@@ -8,6 +8,7 @@ Variables       ${TESTDIR}/lib/vars.py
 ${CONFIG}       ${TESTDIR}/configs/lua_test.conf
 ${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
 ${RSPAMD_SCOPE}  Test
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
 
 *** Test Cases ***
 Flags
@@ -34,8 +35,18 @@ Recipient Parsing Sanity
   ...  -r  rcpt3@foobar  -r  rcpt4@foobar
   Check Rspamc  ${result}  TEST_RCPT (1.00)[rcpt1@foobar,rcpt2@foobar,rcpt3@foobar,rcpt4@foobar]
 
+TLD parts
+  [Setup]  TLD Setup  ${TESTDIR}/lua/tlds.lua
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  TEST_TLD (1.00)[no worry]
+
 *** Keywords ***
 Lua Setup
   [Arguments]  ${LUA_SCRIPT}
   Set Test Variable  ${LUA_SCRIPT}
   Generic Setup
+
+TLD Setup
+  [Arguments]  ${LUA_SCRIPT}
+  Set Test Variable  ${URL_TLD}  ${TESTDIR}/../../contrib/publicsuffix/effective_tld_names.dat
+  Lua Setup  ${LUA_SCRIPT}
index e558c710764402072c605819404aa9ae01fec6b1..7729bcc3aea3f7183c1927a82267c70e3afed4df 100644 (file)
@@ -1,3 +1,6 @@
+*** Variables ***
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
+
 *** Keywords ***
 Stat Test
   @{result} =  HTTP  GET  ${LOCAL_ADDR}  ${PORT_CONTROLLER}  /stat
index a82c687e4832ef85dd98666e1a90949fe1f61654..3907cfed6d4c1b8593ca3e8a8813727bd65c591e 100644 (file)
@@ -8,6 +8,7 @@ Variables       ${TESTDIR}/lib/vars.py
 *** Variables ***
 ${LUA_SCRIPT}   ${TESTDIR}/lua/simple.lua
 ${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
 
 *** Test Cases ***
 Scan Message
index bcb1c3323bf54f15b5514fe57e6ac126c0e6d50f..6e93f85ac4cac0c464d452897febf68560a40bea 100644 (file)
@@ -1,6 +1,6 @@
 options = {
        filters = ["spf", "dkim", "regexp"]
-       url_tld = "${TESTDIR}/../lua/unit/test_tld.dat"
+       url_tld = "${URL_TLD}"
        pidfile = "${TMPDIR}/rspamd.pid"
 }
 logging = {
diff --git a/test/functional/lua/tlds.lua b/test/functional/lua/tlds.lua
new file mode 100644 (file)
index 0000000..9f2d64f
--- /dev/null
@@ -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
+})