aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/unit/url.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-24 20:14:38 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-24 20:14:38 +0000
commit8fcd9548181172bf53992ee1039c8ba550727dd1 (patch)
tree3178d1d930aa7ccb4cb738d5a78e06b6f92287b2 /test/lua/unit/url.lua
parent1629eb5614c82e4ec3b1d480ee74d01eac0b66fe (diff)
downloadrspamd-8fcd9548181172bf53992ee1039c8ba550727dd1.tar.gz
rspamd-8fcd9548181172bf53992ee1039c8ba550727dd1.zip
[Project] Fix urls composition rules, add unit tests
Diffstat (limited to 'test/lua/unit/url.lua')
-rw-r--r--test/lua/unit/url.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
index 583502c48..24c354960 100644
--- a/test/lua/unit/url.lua
+++ b/test/lua/unit/url.lua
@@ -2,7 +2,9 @@
context("URL check functions", function()
local mpool = require("rspamd_mempool")
+ local lua_urls_compose = require "lua_urls_compose"
local url = require("rspamd_url")
+ local lua_util = require("lua_util")
local logger = require("rspamd_logger")
local test_helper = require("rspamd_test_helper")
local ffi = require("ffi")
@@ -177,4 +179,32 @@ context("URL check functions", function()
assert_equal(v[2], res, 'expected ' .. v[2] .. ' but got ' .. res .. ' in path ' .. v[1])
end)
end
+
+ cases = {
+ {'example.com', 'example.com'},
+ {'baz.example.com', 'baz.example.com'},
+ {'3.baz.example.com', 'baz.example.com'},
+ {'bar.example.com', 'example.com'},
+ {'foo.example.com', 'foo.example.com'},
+ {'3.foo.example.com', '3.foo.example.com'},
+ {'foo.com', 'foo.com'},
+ {'bar.foo.com', 'foo.com'},
+ }
+
+ local excl_rules1 = {
+ 'example.com',
+ '*.foo.example.com',
+ '!bar.example.com'
+ }
+
+ local comp_rules = lua_urls_compose.inject_composition_rules(rspamd_config, excl_rules1)
+
+ for _,v in ipairs(cases) do
+ test("URL composition " .. v[1], function()
+ local u = url.create(pool, v[1])
+ assert_not_nil(u, "we are able to parse url: " .. v[1])
+ local res = comp_rules:process_url(nil, u:get_tld(), u:get_host())
+ assert_equal(v[2], res, 'expected ' .. v[2] .. ' but got ' .. res .. ' in url ' .. v[1])
+ end)
+ end
end)