diff options
author | Mikhail Galanin <mgalanin@mimecast.com> | 2018-10-08 17:53:50 +0100 |
---|---|---|
committer | Mikhail Galanin <mgalanin@mimecast.com> | 2018-10-08 17:53:50 +0100 |
commit | 4d4119d3c39664ec707578f976cefb195b3df792 (patch) | |
tree | af3d2d61acbee2fec688caf0bd04fdb6e87e479a /test | |
parent | 41deb94d44828c326c69ca0fb5468058818fedfd (diff) | |
download | rspamd-4d4119d3c39664ec707578f976cefb195b3df792.tar.gz rspamd-4d4119d3c39664ec707578f976cefb195b3df792.zip |
[Test] one more test case
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/lua_util.extract_specific_urls.lua | 90 |
1 files changed, 55 insertions, 35 deletions
diff --git a/test/lua/unit/lua_util.extract_specific_urls.lua b/test/lua/unit/lua_util.extract_specific_urls.lua index 210e0370c..3a28217a6 100644 --- a/test/lua/unit/lua_util.extract_specific_urls.lua +++ b/test/lua/unit/lua_util.extract_specific_urls.lua @@ -1,3 +1,7 @@ + +local msg +local msg2 + context("Lua util - extract_specific_urls", function() local util = require 'lua_util' local mpool = require "rspamd_mempool" @@ -43,6 +47,7 @@ context("Lua util - extract_specific_urls", function() {expect = url_list, filter = nil, limit = 9999, need_emails = true, prefix = 'p'}, {expect = {}, filter = (function() return false end), limit = 9999, need_emails = true, prefix = 'p'}, {expect = {"domain4.co.net", "test.com"}, filter = nil, limit = 2, need_emails = true, prefix = 'p'}, + {expect = {"domain4.co.net", "test.com", "domain3.org"}, filter = nil, limit = 3, need_emails = true, prefix = 'p'}, { expect = {"gov.co.net", "tesco.co.net", "domain1.co.net", "domain2.co.net", "domain3.co.net", "domain4.co.net"}, filter = (function(s) return s:get_host():sub(-4) == ".net" end), @@ -79,17 +84,16 @@ context("Lua util - extract_specific_urls", function() local pool = mpool.create() - for i,c in ipairs(cases) do - - local function prepare_url_list(c) - return fun.totable(fun.map( + local function prepare_url_list(list) + return fun.totable(fun.map( function (u) return url.create(pool, u) end, - c.input or url_list + list or url_list )) end + for i,c in ipairs(cases) do test("extract_specific_urls, backward compatibility case #" .. i, function() - task_object.urls = prepare_url_list(c) + task_object.urls = prepare_url_list(c.input) if (c.esld_limit) then -- not awailable in deprecated version return @@ -106,7 +110,7 @@ context("Lua util - extract_specific_urls", function() end) test("extract_specific_urls " .. i, function() - task_object.urls = prepare_url_list(c) + task_object.urls = prepare_url_list(c.input) local actual = util.extract_specific_urls({ task = task_object, @@ -127,6 +131,20 @@ context("Lua util - extract_specific_urls", function() end) end + test("extract_specific_urls, another case", function() + task_object.urls = prepare_url_list {"abc.net", "abc.com", "abc.net", "abc.za.org"} + local actual = util.extract_specific_urls(task_object, 3, true) + + local actual_result = prepare_actual_result(actual) + table.sort(actual_result) + --[[ + local s = logger.slog("%1 =?= %2", c.expect, actual_result) + print(s) --]] + + assert_rspamd_table_eq({actual = actual_result, expect = {"abc.com", "abc.net", "abc.za.org"}}) + end) + + --[[ ******************* kinda functional *************************************** ]] local test_dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1") local tld_file = string.format('%s/%s', test_dir, "test_tld.dat") @@ -156,7 +174,36 @@ context("Lua util - extract_specific_urls", function() local cfg = rspamd_util.config_from_ucl(config, "INIT_URL,INIT_LIBS,INIT_SYMCACHE,INIT_VALIDATE,INIT_PRELOAD_MAPS") assert_not_nil(cfg) - local msg = [[ + local expect = {"example.net", "domain.com"} + local res,task = rspamd_task.load_from_string(msg, rspamd_config) + + if not res then + assert_true(false, "failed to load message") + end + + if not task:process_message() then + assert_true(false, "failed to process message") + end + + local actual = util.extract_specific_urls({ + task = task, + limit = 2, + esld_limit = 2, + }) + + local actual_result = prepare_actual_result(actual) + + --[[ + local s = logger.slog("case[%1] %2 =?= %3", i, expect, actual_result) + print(s) --]] + + assert_equal("domain.com", actual_result[1], "checking that first url is the one with highest suspiciousness level") + + end) +end) + +--[=========[ ******************* message ******************* ]=========] +local msg = [[ From: <> To: <nobody@example.com> Subject: test @@ -187,30 +234,3 @@ Content-Type: text/html; charset="utf-8" <a href="http://domain.com">http://example.net/</a> </html> ]] - local expect = {"example.net", "domain.com"} - local res,task = rspamd_task.load_from_string(msg, rspamd_config) - - if not res then - assert_true(false, "failed to load message") - end - - if not task:process_message() then - assert_true(false, "failed to process message") - end - - local actual = util.extract_specific_urls({ - task = task, - limit = 2, - esld_limit = 2, - }) - - local actual_result = prepare_actual_result(actual) - - --[[ - local s = logger.slog("case[%1] %2 =?= %3", i, expect, actual_result) - print(s) --]] - - assert_equal("domain.com", actual_result[1], "checking that first url is the one with highest suspiciousness level") - - end) -end)
\ No newline at end of file |