]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add functional tests for neural plugin
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Jul 2019 15:41:46 +0000 (16:41 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Jul 2019 15:41:46 +0000 (16:41 +0100)
test/functional/cases/330_neural.robot [new file with mode: 0644]
test/functional/configs/neural.conf [new file with mode: 0644]
test/functional/configs/plugins.conf
test/functional/lua/neural.lua [new file with mode: 0644]

diff --git a/test/functional/cases/330_neural.robot b/test/functional/cases/330_neural.robot
new file mode 100644 (file)
index 0000000..1ee003c
--- /dev/null
@@ -0,0 +1,72 @@
+*** Settings ***
+Suite Setup      Neural Setup
+Suite Teardown   Neural Teardown
+Library         Process
+Library         ${TESTDIR}/lib/rspamd.py
+Resource        ${TESTDIR}/lib/rspamd.robot
+Variables       ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
+${CONFIG}       ${TESTDIR}/configs/plugins.conf
+${MESSAGE}      ${TESTDIR}/messages/spam_message.eml
+${LUA_SCRIPT}   ${TESTDIR}/lua/neural.lua
+${REDIS_SCOPE}  Suite
+${RSPAMD_SCOPE}  Suite
+
+*** Test Cases ***
+Train Spam
+  : FOR    ${INDEX}    IN RANGE    0    10
+  \  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["SPAM_SYMBOL"]}
+  \  Check Rspamc  ${result}  SPAM_SYMBOL (1.00)
+
+Train Ham
+  : FOR    ${INDEX}    IN RANGE    0    10
+  \  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["HAM_SYMBOL"]}
+  \  Check Rspamc  ${result}  HAM_SYMBOL (-1.00)
+
+Check Neural HAM
+  Sleep  2s  Wait for neural to be loaded
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["HAM_SYMBOL"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
+  Check Rspamc  ${result}  NEURAL_HAM_SHORT
+  Check Rspamc  ${result}  NEURAL_SPAM_SHORT  inverse=1
+
+Check Neural SPAM
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["SPAM_SYMBOL"];groups_enabled=["neural"];symbols_disabled = ["NEURAL_LEARN"]}
+  Check Rspamc  ${result}  NEURAL_SPAM_SHORT
+  Check Rspamc  ${result}  NEURAL_HAM_SHORT  inverse=1
+
+
+Train Spam INVERSE
+  : FOR    ${INDEX}    IN RANGE    0    10
+  \  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["SPAM_SYMBOL"]; SPAM_SYMBOL = -1}
+  \  Check Rspamc  ${result}  SPAM_SYMBOL (-1.00)
+
+Train Ham INVERSE
+  : FOR    ${INDEX}    IN RANGE    0    10
+  \  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["HAM_SYMBOL"]; HAM_SYMBOL = 1;}
+  \  Check Rspamc  ${result}  HAM_SYMBOL (1.00)
+
+
+Check Neural HAM INVERSE
+  Sleep  2s  Wait for neural to be loaded
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["HAM_SYMBOL"];groups_enabled=["neural"]}
+  Check Rspamc  ${result}  NEURAL_SPAM_SHORT
+  Check Rspamc  ${result}  NEURAL_HAM_SHORT  inverse=1
+
+Check Neural SPAM INVERSE
+  ${result} =  Scan Message With Rspamc  ${MESSAGE}  --header  Settings={symbols_enabled = ["SPAM_SYMBOL"];groups_enabled=["neural"]}
+  Check Rspamc  ${result}  NEURAL_HAM_SHORT
+  Check Rspamc  ${result}  NEURAL_SPAM_SHORT  inverse=1
+
+*** Keywords ***
+Neural Setup
+  ${PLUGIN_CONFIG} =  Get File  ${TESTDIR}/configs/neural.conf
+  Set Suite Variable  ${PLUGIN_CONFIG}
+  Set Global Variable  ${LUA_SCRIPT}
+  Generic Setup  PLUGIN_CONFIG
+  Run Redis
+
+Neural Teardown
+  Normal Teardown
+  Shutdown Process With Children  ${REDIS_PID}
diff --git a/test/functional/configs/neural.conf b/test/functional/configs/neural.conf
new file mode 100644 (file)
index 0000000..a8b30b1
--- /dev/null
@@ -0,0 +1,26 @@
+neural {
+  rules {
+      SHORT {
+          train {
+              learning_rate = 0.001;
+              max_usages = 2;
+              spam_score = 1;
+              ham_score = -1;
+              max_trains = 10;
+              max_iterations = 250;
+          }
+          symbol_spam = "NEURAL_SPAM_SHORT";
+          symbol_ham = "NEURAL_HAM_SHORT";
+          ann_expire = 86400;
+          watch_interval = 0.1;
+      }
+
+  }
+  allow_local = true;
+
+}
+redis {
+  servers = "${REDIS_ADDR}:${REDIS_PORT}";
+  expand_keys = true;
+}
+lua = ${LUA_SCRIPT};
\ No newline at end of file
index 507f00b76748f71df9434eabadea62e8bc073bf2..71c1e7c33ebf320c559d3d2af0c730910c7deb2a 100644 (file)
@@ -3,6 +3,7 @@ options = {
   url_tld = "${URL_TLD}"
   pidfile = "${TMPDIR}/rspamd.pid"
   lua_path = "${INSTALLROOT}/share/rspamd/lib/?.lua"
+  explicit_modules = ["settings", "bayes_expiry"];
   dns {
     nameserver = ["8.8.8.8", "8.8.4.4"];
     retransmits = 10;
@@ -539,6 +540,7 @@ logging = {
   type = "file",
   level = "debug"
   filename = "${TMPDIR}/rspamd.log"
+  log_usec = true;
 }
 metric = {
   name = "default",
diff --git a/test/functional/lua/neural.lua b/test/functional/lua/neural.lua
new file mode 100644 (file)
index 0000000..68d7ca2
--- /dev/null
@@ -0,0 +1,15 @@
+rspamd_config:register_symbol({
+  name = 'SPAM_SYMBOL',
+  score = 1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
+
+rspamd_config:register_symbol({
+  name = 'HAM_SYMBOL',
+  score = -1.0,
+  callback = function()
+    return true, 'Fires always'
+  end
+})
\ No newline at end of file