aboutsummaryrefslogtreecommitdiffstats
path: root/test/functional
diff options
context:
space:
mode:
authorAlexander Moisseev <moiseev@mezonplus.ru>2018-10-30 09:51:32 +0300
committerAlexander Moisseev <moiseev@mezonplus.ru>2018-10-30 18:58:19 +0300
commit046e1b263ac2200a00839a59ebd392169c345bb9 (patch)
treee5898d11190e92ddffceb67049b6fbd69cd82c57 /test/functional
parenta8b22f9aacad391cdaa865039f38a13f622fdbc3 (diff)
downloadrspamd-046e1b263ac2200a00839a59ebd392169c345bb9.tar.gz
rspamd-046e1b263ac2200a00839a59ebd392169c345bb9.zip
[Test] Add composites test
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/cases/109_composites.robot57
-rw-r--r--test/functional/configs/composites.conf64
-rw-r--r--test/functional/lua/composites.lua93
3 files changed, 214 insertions, 0 deletions
diff --git a/test/functional/cases/109_composites.robot b/test/functional/cases/109_composites.robot
new file mode 100644
index 000000000..94c9f58ee
--- /dev/null
+++ b/test/functional/cases/109_composites.robot
@@ -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
index 000000000..3b281fc57
--- /dev/null
+++ b/test/functional/configs/composites.conf
@@ -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
index 000000000..de4642c3b
--- /dev/null
+++ b/test/functional/lua/composites.lua
@@ -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
+})