From: Vsevolod Stakhov Date: Thu, 15 Aug 2019 14:49:58 +0000 (+0100) Subject: [Test] Add options in composites tests X-Git-Tag: 2.0~415 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5dfabf334545326059c7b652cae9e0789c965e9f;p=rspamd.git [Test] Add options in composites tests --- diff --git a/test/functional/cases/109_composites.robot b/test/functional/cases/109_composites.robot index d24c505e9..1216e4c88 100644 --- a/test/functional/cases/109_composites.robot +++ b/test/functional/cases/109_composites.robot @@ -63,3 +63,23 @@ Composites - Symbol groups Should Contain ${result.stdout} ANY_A (-1.00) Should Contain ${result.stdout} NEGATIVE_B (1.00) Should Not Contain ${result.stdout} NEGATIVE_A + +Composites - Opts Plain + ${result} = Scan Message With Rspamc ${MESSAGE} --header=opts:sym1 + Check Rspamc ${result} SYMOPTS1 (5.00) + Should Not Contain ${result.stdout} SYMOPTS2 + +Composites - Opts RE Miss one + ${result} = Scan Message With Rspamc ${MESSAGE} --header=opts:sym1,foo1 + Check Rspamc ${result} SYMOPTS1 (5.00) + Should Not Contain ${result.stdout} SYMOPTS2 + +Composites - Opts RE Miss both + ${result} = Scan Message With Rspamc ${MESSAGE} --header=opts:sym2 + Should Not Contain ${result.stdout} SYMOPTS1 + Should Not Contain ${result.stdout} SYMOPTS2 + +Composites - Opts RE Hit + ${result} = Scan Message With Rspamc ${MESSAGE} --header=opts:sym2,foo1 + Check Rspamc ${result} SYMOPTS2 (6.00) + Should Not Contain ${result.stdout} SYMOPTS1 \ No newline at end of file diff --git a/test/functional/configs/composites.conf b/test/functional/configs/composites.conf index 8b79d5ae7..932b25fc1 100644 --- a/test/functional/configs/composites.conf +++ b/test/functional/configs/composites.conf @@ -66,4 +66,14 @@ composites { expression = "!g+:positive & g-:negative & -g:any"; score = 5.0; } + + SYMOPTS1 { + expression = "OPTS[sym1]"; + score = 5.0; + } + + SYMOPTS2 { + expression = "OPTS[/foo.*/,sym2]"; + score = 6.0; + } } diff --git a/test/functional/lua/composites.lua b/test/functional/lua/composites.lua index 66d595cd8..648eda0ff 100644 --- a/test/functional/lua/composites.lua +++ b/test/functional/lua/composites.lua @@ -124,3 +124,17 @@ rspamd_config:register_symbol({ return true, 'Fires always' end }) + +rspamd_config:register_symbol({ + name = 'OPTS', + score = -1.0, + group = "any", + callback = function(task) + local lua_util = require "lua_util" + local woot = lua_util.str_split(tostring(task:get_request_header('opts') or ''), ',') + + if woot and #woot > 0 and #woot[1] > 0 then + return true, 1.0, woot + end + end +})