commit 5dfabf3: [Test] Add options in composites tests

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Aug 15 14:56:08 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-08-15 15:49:58 +0100
URL: https://github.com/rspamd/rspamd/commit/5dfabf334545326059c7b652cae9e0789c965e9f

[Test] Add options in composites tests

---
 test/functional/cases/109_composites.robot | 20 ++++++++++++++++++++
 test/functional/configs/composites.conf    | 10 ++++++++++
 test/functional/lua/composites.lua         | 14 ++++++++++++++
 3 files changed, 44 insertions(+)

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
+})


More information about the Commits mailing list