aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-15 16:41:46 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-07-15 16:41:46 +0100
commitd61bd5017d8899defac876df4da2cfaacd0f3272 (patch)
tree2b93b36a86bad8275408a01adb96642e768f2d36 /test
parent834573afd5cb9495d12d5945bea07f64a6cae540 (diff)
downloadrspamd-d61bd5017d8899defac876df4da2cfaacd0f3272.tar.gz
rspamd-d61bd5017d8899defac876df4da2cfaacd0f3272.zip
[Test] Add functional tests for neural plugin
Diffstat (limited to 'test')
-rw-r--r--test/functional/cases/330_neural.robot72
-rw-r--r--test/functional/configs/neural.conf26
-rw-r--r--test/functional/configs/plugins.conf2
-rw-r--r--test/functional/lua/neural.lua15
4 files changed, 115 insertions, 0 deletions
diff --git a/test/functional/cases/330_neural.robot b/test/functional/cases/330_neural.robot
new file mode 100644
index 000000000..1ee003ccb
--- /dev/null
+++ b/test/functional/cases/330_neural.robot
@@ -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
index 000000000..a8b30b197
--- /dev/null
+++ b/test/functional/configs/neural.conf
@@ -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
diff --git a/test/functional/configs/plugins.conf b/test/functional/configs/plugins.conf
index 507f00b76..71c1e7c33 100644
--- a/test/functional/configs/plugins.conf
+++ b/test/functional/configs/plugins.conf
@@ -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
index 000000000..68d7ca2ae
--- /dev/null
+++ b/test/functional/lua/neural.lua
@@ -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