summaryrefslogtreecommitdiffstats
path: root/test/functional/lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2017-02-28 15:33:25 +0200
committerAndrew Lewis <nerf@judo.za.org>2017-02-28 15:33:25 +0200
commiteaa7e99d39d42e5a794cb133028e8a19dc7e23dc (patch)
treebb3410da5e7b7ac15585676d6e17a3e7d2a0e6cf /test/functional/lua
parent3b89fbaaef6fbf0157e69f713232d9aca3cb13b8 (diff)
downloadrspamd-eaa7e99d39d42e5a794cb133028e8a19dc7e23dc.tar.gz
rspamd-eaa7e99d39d42e5a794cb133028e8a19dc7e23dc.zip
[Test] Test URL tag persistence
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/url_tags.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/functional/lua/url_tags.lua b/test/functional/lua/url_tags.lua
new file mode 100644
index 000000000..6c2e07a7f
--- /dev/null
+++ b/test/functional/lua/url_tags.lua
@@ -0,0 +1,55 @@
+local rspamd_logger = require 'rspamd_logger'
+
+rspamd_config:register_symbol({
+ name = 'ADDED_TAGS',
+ score = 1.0,
+ callback = function(task)
+ if not task:get_request_header('addtags') then
+ return true, 'nope! not requested'
+ end
+ local urls = task:get_urls()
+ if not (urls and urls[1]) then
+ return true, 'nope! found no urls'
+ end
+ local mpool = task:get_mempool()
+ for _, u in ipairs(urls) do
+ u:add_tag('test1', 'meta1', mpool)
+ u:add_tag('test1', 'meta2', mpool)
+ u:add_tag('test2', 'http://www.example.com', mpool)
+ end
+ return true, 'no worry'
+ end
+})
+
+rspamd_config:register_symbol({
+ name = 'FOUND_TAGS',
+ score = 1.0,
+ callback = function(task)
+ local urls = task:get_urls()
+ if not (urls and urls[1]) then
+ return true, 'nope! found no urls'
+ end
+ for _, u in ipairs(urls) do
+ local tags = u:get_tags()
+ rspamd_logger.debugx(task, 'tags: %1', tags)
+ if not tags['test1'] then
+ return true, 'no key - test1'
+ end
+ local found1, found2 = false, false
+ for _, e in ipairs(tags['test1']) do
+ if e == 'meta1' then found1 = true end
+ if e == 'meta2' then found2 = true end
+ end
+ if not (found1 and found2) then
+ return true, 'missing metatags in test1'
+ end
+ if not tags['test2'] then
+ return true, 'no key - test2'
+ end
+ if not tags['test2'][1] == 'http://www.example.com' then
+ return true, 'wrong value in test2 metatag: ' .. tags['test2'][1]
+ end
+ end
+ return true, 'no worry'
+ end
+})