diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-08-13 14:47:25 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-08-13 14:47:25 +0100 |
commit | 6dcd2bd6760bdf33c953d89e5c6752a3154bd4ab (patch) | |
tree | 3f4d672d80725614863b0550110ca79c5c03241d /test/lua/unit | |
parent | c3ca41d039721004af10cf77083ccebb4b3a0bb8 (diff) | |
download | rspamd-6dcd2bd6760bdf33c953d89e5c6752a3154bd4ab.tar.gz rspamd-6dcd2bd6760bdf33c953d89e5c6752a3154bd4ab.zip |
[Fix] Fix more issues with nested messages + tests
Diffstat (limited to 'test/lua/unit')
-rw-r--r-- | test/lua/unit/task.lua | 130 |
1 files changed, 100 insertions, 30 deletions
diff --git a/test/lua/unit/task.lua b/test/lua/unit/task.lua index 2825a076f..3ec583043 100644 --- a/test/lua/unit/task.lua +++ b/test/lua/unit/task.lua @@ -1,35 +1,11 @@ context("Task processing", function() - local ffi = require("ffi") - local rspamd_util = require("rspamd_util") - local logger = require("rspamd_logger") - local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1") - - local tld_file = string.format('%s/%s', test_dir, "test_tld.dat") - local config = { - options = { - filters = {'spf', 'dkim', 'regexp'}, - url_tld = tld_file, - dns = { - nameserver = {'8.8.8.8'} - }, - }, - logging = { - type = 'console', - level = 'debug' - }, - metric = { - name = 'default', - actions = { - reject = 100500, - }, - unknown_weight = 1 - } - } - + local fun = require("fun") + local rspamd_task = require("rspamd_task") + test("Process a simple task", function() --local cfg = rspamd_util.config_from_ucl(config) --assert_not_nil(cfg) - + local msg = [[ From: <> To: <nobody@example.com> @@ -38,7 +14,101 @@ Content-Type: text/plain Test. ]] - --local obj = rspamd_util.process_message(cfg, msg) - --print(logger.slog("result: %1", obj)) + local res,task = rspamd_task.load_from_string(msg) + assert_true(res, "failed to load message") + task:process_message() + task:destroy() + end) + + local hdrs = [[ +From: <> +To: <nobody@example.com> +Subject: test +]] + local mpart = [[ +Content-Type: multipart/mixed; boundary=XXX +]] + local body = [[ +Content-Type: text/html +Content-Transfer-Encoding: quoted-printable + +<html> +<body> +=0DAttached is your new documents. +<br> +<a href=3D"http://evil.com/Information/">http:= +//example.com/privacy/XXX/YYY_April_25_2019.doc</a> +<br> +<br> +<br> +Thank you, +<br> +<b>Haloclaims.co</b> +</body></html> +]] + test("Process mime nesting: simple", function() + local msg = hdrs .. body + local res,task = rspamd_task.load_from_string(msg) + assert_true(res, "failed to load message") + task:process_message() + assert_rspamd_table_eq({actual = fun.totable(fun.map(function(u) + return u:get_host() + end, task:get_urls())), expect = { + 'evil.com', 'example.com' + }}) + task:destroy() + end) + test("Process mime nesting: multipart", function() + local msg = table.concat{ + hdrs, mpart, '\n', '--XXX\n', body, '\n--XXX--\n' + } + local res,task = rspamd_task.load_from_string(msg) + assert_true(res, "failed to load message") + task:process_message() + assert_rspamd_table_eq({ + actual = fun.totable(fun.map(function(u) + return u:get_host() + end, task:get_urls())), + + expect = { + 'evil.com', 'example.com' + }}) + task:destroy() + end) + test("Process mime nesting: multipart, broken", function() + local msg = table.concat{ + hdrs, mpart, '\n', '--XXX\n', 'garbadge\n', '\n--XXX--\n', '--XXX\n', body + } + local res,task = rspamd_task.load_from_string(msg) + assert_true(res, "failed to load message") + task:process_message() + assert_rspamd_table_eq({ + actual = fun.totable(fun.map(function(u) + return u:get_host() + end, task:get_urls())), + + expect = { + 'evil.com', 'example.com' + }}) + + task:destroy() + end) + test("Process mime nesting: message", function() + local msg = table.concat{ + hdrs, 'Content-Type: message/rfc822\n', '\n', hdrs, body + } + local res,task = rspamd_task.load_from_string(msg) + assert_true(res, "failed to load message") + task:process_message() + assert_rspamd_table_eq({ + actual = fun.totable(fun.map(function(u) + return u:get_host() + end, task:get_urls())), + + expect = { + 'evil.com', 'example.com' + }}) + + task:destroy() end) end)
\ No newline at end of file |