]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add composites test 2617/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 30 Oct 2018 06:51:32 +0000 (09:51 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Tue, 30 Oct 2018 15:58:19 +0000 (18:58 +0300)
test/functional/cases/109_composites.robot [new file with mode: 0644]
test/functional/configs/composites.conf [new file with mode: 0644]
test/functional/lua/composites.lua [new file with mode: 0644]

diff --git a/test/functional/cases/109_composites.robot b/test/functional/cases/109_composites.robot
new file mode 100644 (file)
index 0000000..94c9f58
--- /dev/null
@@ -0,0 +1,57 @@
+*** Settings ***
+Suite Setup     Generic Setup
+Suite Teardown  Simple Teardown
+Library         ${TESTDIR}/lib/rspamd.py
+Resource        ${TESTDIR}/lib/rspamd.robot
+Variables       ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}       ${TESTDIR}/configs/composites.conf
+${LUA_SCRIPT}   ${TESTDIR}/lua/composites.lua
+${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
+${RSPAMD_SCOPE}  Suite
+
+*** Test Cases ***
+Composites - Score
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  ${SPACE}46.00 / 0.00
+
+Composites - Expressions
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  EXPRESSIONS (5.00)
+  Should Contain  ${result.stdout}  EXPRESSIONS_B (0.00)
+
+Composites - Policy: remove_weight
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  ${SPACE}POLICY_REMOVE_WEIGHT (5.00)
+  Should Not Contain  ${result.stdout}  ${SPACE}POLICY_REMOVE_WEIGHT_A (1.00)
+  Should Contain  ${result.stdout}  ${SPACE}POLICY_REMOVE_WEIGHT_B (0.00)
+
+Composites - Policy: force removing
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  ${SPACE}POLICY_FORCE_REMOVE (5.00)
+  Should Contain  ${result.stdout}  ${SPACE}POLICY_FORCE_REMOVE_A (1.00)
+  Should Not Contain  ${result.stdout}  ${SPACE}POLICY_FORCE_REMOVE_B
+
+Composites - Policy: leave
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  ${SPACE}POLICY_LEAVE (5.00)
+  Should Not Contain  ${result.stdout}  ${SPACE}POLICY_LEAVE_A
+  Should Contain  ${result.stdout}  ${SPACE}POLICY_LEAVE_B (1.00)
+
+Composites - Default policy: remove_weight
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  DEFAULT_POLICY_REMOVE_WEIGHT (5.00)
+  Should Contain  ${result.stdout}  DEFAULT_POLICY_REMOVE_WEIGHT_A (0.00)
+  Should Contain  ${result.stdout}  DEFAULT_POLICY_REMOVE_WEIGHT_B (0.00)
+
+Composites - Default policy: remove_symbol
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  DEFAULT_POLICY_REMOVE_SYMBOL (5.00)
+  Should Not Contain  ${result.stdout}  DEFAULT_POLICY_REMOVE_SYMBOL_
+
+Composites - Default policy: leave
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}
+  Check Rspamc  ${result}  DEFAULT_POLICY_LEAVE (5.00)
+  Should Contain  ${result.stdout}  DEFAULT_POLICY_LEAVE_A (1.00)
+  Should Contain  ${result.stdout}  DEFAULT_POLICY_LEAVE_B (1.00)
diff --git a/test/functional/configs/composites.conf b/test/functional/configs/composites.conf
new file mode 100644 (file)
index 0000000..3b281fc
--- /dev/null
@@ -0,0 +1,64 @@
+options = {
+    pidfile = "${TMPDIR}/rspamd.pid"
+}
+logging = {
+    type = "file",
+    level = "debug"
+    filename = "${TMPDIR}/rspamd.log"
+}
+
+worker {
+    type = normal
+    bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL}
+    count = 1
+    task_timeout = 60s;
+}
+worker {
+    type = controller
+    bind_socket = ${LOCAL_ADDR}:${PORT_CONTROLLER}
+    count = 1
+    secure_ip = ["127.0.0.1", "::1"];
+    stats_path = "${TMPDIR}/stats.ucl"
+}
+lua = "${TESTDIR}/lua/test_coverage.lua";
+lua = ${LUA_SCRIPT};
+
+composites {
+    EXPRESSIONS {
+        expression = "(EXPRESSIONS_A | ~EXPRESSIONS_B) & !EXPRESSIONS_C";
+        score = 5.0;
+    }
+
+    POLICY_REMOVE_WEIGHT {
+        expression = "POLICY_REMOVE_WEIGHT_A and ~POLICY_REMOVE_WEIGHT_B";
+        score = 5.0;
+    }
+    POLICY_FORCE_REMOVE {
+        expression = "POLICY_FORCE_REMOVE_A & ^POLICY_FORCE_REMOVE_B";
+        score = 5.0;
+    }
+    POLICY_FORCE_REMOVE_LEAVE {
+        expression = "-POLICY_FORCE_REMOVE_A and -POLICY_FORCE_REMOVE_B";
+        score = 5.0;
+    }
+    POLICY_LEAVE {
+        expression = "POLICY_LEAVE_A & -POLICY_LEAVE_B";
+        score = 5.0;
+    }
+
+    DEFAULT_POLICY_REMOVE_WEIGHT {
+        expression = "DEFAULT_POLICY_REMOVE_WEIGHT_A and DEFAULT_POLICY_REMOVE_WEIGHT_B";
+        score = 5.0;
+        policy = "remove_weight";
+    }
+    DEFAULT_POLICY_REMOVE_SYMBOL {
+        expression = "DEFAULT_POLICY_REMOVE_SYMBOL_A & DEFAULT_POLICY_REMOVE_SYMBOL_B";
+        score = 5.0;
+        policy = "remove_symbol";
+    }
+    DEFAULT_POLICY_LEAVE {
+        expression = "DEFAULT_POLICY_LEAVE_A & DEFAULT_POLICY_LEAVE_B";
+        score = 5.0;
+        policy = "leave";
+    }
+}
diff --git a/test/functional/lua/composites.lua b/test/functional/lua/composites.lua
new file mode 100644 (file)
index 0000000..de4642c
--- /dev/null
@@ -0,0 +1,93 @@
+rspamd_config:register_symbol({
+  name = 'EXPRESSIONS_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+
+rspamd_config:register_symbol({
+  name = 'POLICY_REMOVE_WEIGHT_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'POLICY_REMOVE_WEIGHT_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'POLICY_FORCE_REMOVE_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'POLICY_FORCE_REMOVE_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'POLICY_LEAVE_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'POLICY_LEAVE_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_REMOVE_WEIGHT_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_REMOVE_WEIGHT_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_REMOVE_SYMBOL_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_REMOVE_SYMBOL_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_LEAVE_A',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+rspamd_config:register_symbol({
+  name = 'DEFAULT_POLICY_LEAVE_B',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})