aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2016-07-02 17:48:58 +0200
committerAndrew Lewis <nerf@judo.za.org>2016-07-02 18:36:15 +0200
commitad797afed513439cb2cd81de185b75880ea9f8aa (patch)
treed3826459a27b101b0051abde7681ad752760f03c /test
parente3a301a85d355a7f559173b88613fb4da5fbd016 (diff)
downloadrspamd-ad797afed513439cb2cd81de185b75880ea9f8aa.tar.gz
rspamd-ad797afed513439cb2cd81de185b75880ea9f8aa.zip
[Test] Add & rework functional tests
- Machine formatted test data - More idiomatic use of test framework - Added tests for fuzzy & redis statistics
Diffstat (limited to 'test')
-rw-r--r--test/functional/cases/__init__.robot22
-rw-r--r--test/functional/cases/fuzzy/encrypted.robot20
-rw-r--r--test/functional/cases/fuzzy/lib.robot48
-rw-r--r--test/functional/cases/fuzzy/plain.robot18
-rw-r--r--test/functional/cases/general.robot15
-rw-r--r--test/functional/cases/lua.robot21
-rw-r--r--test/functional/cases/statistics.robot83
-rw-r--r--test/functional/cases/statistics/compat-keyed.robot19
-rw-r--r--test/functional/cases/statistics/compat-plain.robot18
-rw-r--r--test/functional/cases/statistics/lib.robot59
-rw-r--r--test/functional/cases/statistics/redis-keyed-siphash.robot20
-rw-r--r--test/functional/cases/statistics/redis-keyed-xxhash.robot20
-rw-r--r--test/functional/cases/statistics/redis-plain-siphash.robot19
-rw-r--r--test/functional/cases/statistics/redis-plain-xxhash.robot19
-rw-r--r--test/functional/cases/statistics/sqlite-broken-stats-dir.robot15
-rw-r--r--test/functional/cases/statistics/sqlite-keyed-siphash.robot19
-rw-r--r--test/functional/cases/statistics/sqlite-keyed-xxhash.robot19
-rw-r--r--test/functional/cases/statistics/sqlite-plain-siphash.robot18
-rw-r--r--test/functional/cases/statistics/sqlite-plain-xxhash.robot18
-rw-r--r--test/functional/configs/fuzzy.conf74
-rw-r--r--test/functional/configs/redis-server.conf4
-rw-r--r--test/functional/configs/stats.conf24
-rw-r--r--test/functional/configs/trivial.conf4
-rw-r--r--test/functional/lib/rspamd.py8
-rw-r--r--test/functional/lib/rspamd.robot80
-rw-r--r--test/functional/lib/vars.py2
26 files changed, 521 insertions, 165 deletions
diff --git a/test/functional/cases/__init__.robot b/test/functional/cases/__init__.robot
index 46fdc8f2a..4b95b9217 100644
--- a/test/functional/cases/__init__.robot
+++ b/test/functional/cases/__init__.robot
@@ -1,18 +1,12 @@
*** Settings ***
-Suite Setup Export Global Variables
-Library ../lib/rspamd.py
-Variables ../lib/vars.py
+Suite Setup Export Global Variables
+Library ../lib/rspamd.py
+Variables ../lib/vars.py
*** Keywords ***
Export Global Variables
- ${TESTDIR} = Get Test Directory
- Set Global Variable ${KEY_PUB1}
- Set Global Variable ${KEY_PVT1}
- Set Global Variable ${LOCAL_ADDR}
- Set Global Variable ${PORT_CONTROLLER}
- Set Global Variable ${PORT_NORMAL}
- Set Global Variable ${RSPAMC} ${TESTDIR}/../../src/client/rspamc
- Set Global Variable ${RSPAMD} ${TESTDIR}/../../src/rspamd
- Set Global Variable ${RSPAMD_GROUP}
- Set Global Variable ${RSPAMD_USER}
- Set Global Variable ${TESTDIR}
+ ${TESTDIR} = Get Test Directory
+ Set Global Variable ${RSPAMADM} ${TESTDIR}/../../src/rspamadm/rspamadm
+ Set Global Variable ${RSPAMC} ${TESTDIR}/../../src/client/rspamc
+ Set Global Variable ${RSPAMD} ${TESTDIR}/../../src/rspamd
+ Set Global Variable ${TESTDIR}
diff --git a/test/functional/cases/fuzzy/encrypted.robot b/test/functional/cases/fuzzy/encrypted.robot
new file mode 100644
index 000000000..45408d7f8
--- /dev/null
+++ b/test/functional/cases/fuzzy/encrypted.robot
@@ -0,0 +1,20 @@
+*** Settings ***
+Suite Setup Encrypted Fuzzy Setup
+Suite Teardown Generic Teardown
+Resource lib.robot
+
+*** Test Cases ***
+Fuzzy Add
+ Fuzzy Add Test
+
+Fuzzy Delete
+ Fuzzy Delete Test
+
+Fuzzy Overwrite
+ Fuzzy Overwrite Test
+
+*** Keywords ***
+Encrypted Fuzzy Setup
+ Set Suite Variable ${SETTINGS_FUZZY_WORKER} "keypair": {"pubkey": "${KEY_PUB1}", "privkey": "${KEY_PVT1}"}; "encrypted_only": true;
+ Set Suite Variable ${SETTINGS_FUZZY_CHECK} encryption_key = "${KEY_PUB1}";
+ Generic Setup
diff --git a/test/functional/cases/fuzzy/lib.robot b/test/functional/cases/fuzzy/lib.robot
new file mode 100644
index 000000000..e5e9cbcb7
--- /dev/null
+++ b/test/functional/cases/fuzzy/lib.robot
@@ -0,0 +1,48 @@
+*** Settings ***
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG} ${TESTDIR}/configs/fuzzy.conf
+${FLAG1_NUMBER} 50
+${FLAG1_SYMBOL} R_TEST_FUZZY_DENIED
+${FLAG2_NUMBER} 51
+${FLAG2_SYMBOL} R_TEST_FUZZY_WHITE
+${MESSAGE} ${TESTDIR}/messages/bad_message.eml
+${RSPAMD_SCOPE} Suite
+
+*** Keywords ***
+Fuzzy Add Test
+ Set Suite Variable ${RSPAMD_FUZZY_ADD} 0
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} -w 10 -f
+ ... ${FLAG1_NUMBER} fuzzy_add ${MESSAGE}
+ Check Rspamc ${result}
+ Sync Fuzzy Storage
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} ${FLAG1_SYMBOL}
+ Set Suite Variable ${RSPAMD_FUZZY_ADD} 1
+
+Fuzzy Delete Test
+ Run Keyword If ${RSPAMD_FUZZY_ADD} == 0 Fail "Fuzzy Add was not run"
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} -f ${FLAG1_NUMBER} fuzzy_del
+ ... ${MESSAGE}
+ Check Rspamc ${result}
+ Sync Fuzzy Storage
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Follow Rspamd Log
+ Should Not Contain ${result.stdout} ${FLAG1_SYMBOL}
+ Should Be Equal As Integers ${result.rc} 0
+
+Fuzzy Overwrite Test
+ ${flag_numbers} = Create List ${FLAG1_NUMBER} ${FLAG2_NUMBER}
+ : FOR ${i} IN @{flag_numbers}
+ \ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} -w 10
+ \ ... -f ${i} fuzzy_add ${MESSAGE}
+ \ Check Rspamc ${result}
+ Sync Fuzzy Storage
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Follow Rspamd Log
+ Should Not Contain ${result.stdout} ${FLAG1_SYMBOL}
+ Should Contain ${result.stdout} ${FLAG2_SYMBOL}
+ Should Be Equal As Integers ${result.rc} 0
diff --git a/test/functional/cases/fuzzy/plain.robot b/test/functional/cases/fuzzy/plain.robot
new file mode 100644
index 000000000..2fc2fd5ef
--- /dev/null
+++ b/test/functional/cases/fuzzy/plain.robot
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup Generic Setup
+Suite Teardown Generic Teardown
+Resource lib.robot
+
+*** Variables ***
+${SETTINGS_FUZZY_WORKER} ${EMPTY}
+${SETTINGS_FUZZY_CHECK} ${EMPTY}
+
+*** Test Cases ***
+Fuzzy Add
+ Fuzzy Add Test
+
+Fuzzy Delete
+ Fuzzy Delete Test
+
+Fuzzy Overwrite
+ Fuzzy Overwrite Test
diff --git a/test/functional/cases/general.robot b/test/functional/cases/general.robot
index aa146b4a9..5fb80520d 100644
--- a/test/functional/cases/general.robot
+++ b/test/functional/cases/general.robot
@@ -1,14 +1,14 @@
*** Settings ***
-Library ${TESTDIR}/lib/rspamd.py
-Resource ${TESTDIR}/lib/rspamd.robot
Suite Setup Generic Setup
Suite Teardown Generic Teardown
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
*** Variables ***
-${CONFIG} ${TESTDIR}/configs/trivial.conf
-${GTUBE} ${TESTDIR}/messages/gtube.eml
-&{RSPAMD_KEYWORDS} KEY_PUBLIC=${KEY_PUB1} KEY_PRIVATE=${KEY_PVT1} LOCAL_ADDR=${LOCAL_ADDR} PORT_NORMAL=${PORT_NORMAL} TESTDIR=${TESTDIR}
-${RSPAMD_SCOPE} Suite
+${CONFIG} ${TESTDIR}/configs/trivial.conf
+${GTUBE} ${TESTDIR}/messages/gtube.eml
+${RSPAMD_SCOPE} Suite
*** Test Cases ***
GTUBE
@@ -16,7 +16,8 @@ GTUBE
Check Rspamc ${result} GTUBE (
GTUBE - Encrypted
- ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} --key ${KEY_PUB1} ${GTUBE}
+ ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} --key ${KEY_PUB1}
+ ... ${GTUBE}
Check Rspamc ${result} GTUBE (
GTUBE - Scan File feature
diff --git a/test/functional/cases/lua.robot b/test/functional/cases/lua.robot
index 46dd15ea0..f3a3567ec 100644
--- a/test/functional/cases/lua.robot
+++ b/test/functional/cases/lua.robot
@@ -1,19 +1,14 @@
*** Settings ***
+Test Teardown Generic Teardown
Library ${TESTDIR}/lib/rspamd.py
Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
*** Variables ***
-${CONFIG} ${TESTDIR}/configs/lua_test.conf
-${MESSAGE} ${TESTDIR}/messages/spam_message.eml
+${CONFIG} ${TESTDIR}/configs/lua_test.conf
+${MESSAGE} ${TESTDIR}/messages/spam_message.eml
${RSPAMD_SCOPE} Test
-*** Keywords ***
-Lua Setup
- [Arguments] ${lua_script}
- &{RSPAMD_KEYWORDS} = Create Dictionary LOCAL_ADDR=${LOCAL_ADDR} LUA_SCRIPT=${lua_script} PORT_CONTROLLER=${PORT_CONTROLLER} PORT_NORMAL=${PORT_NORMAL} TESTDIR=${TESTDIR}
- Set Test Variable &{RSPAMD_KEYWORDS}
- Generic Setup
-
*** Test Cases ***
Flags
[Setup] Lua Setup ${TESTDIR}/lua/flags.lua
@@ -21,10 +16,14 @@ Flags
Follow Rspamd Log
${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} stat
Should Contain ${result.stdout} Messages scanned: 0
- [Teardown] Generic Teardown
Dependencies
[Setup] Lua Setup ${TESTDIR}/lua/deps.lua
${result} = Scan Message With Rspamc ${MESSAGE}
Check Rspamc ${result} DEP10
- [Teardown] Generic Teardown
+
+*** Keywords ***
+Lua Setup
+ [Arguments] ${LUA_SCRIPT}
+ Set Test Variable ${LUA_SCRIPT}
+ Generic Setup
diff --git a/test/functional/cases/statistics.robot b/test/functional/cases/statistics.robot
deleted file mode 100644
index 6d0218b56..000000000
--- a/test/functional/cases/statistics.robot
+++ /dev/null
@@ -1,83 +0,0 @@
-*** Settings ***
-Library ${TESTDIR}/lib/rspamd.py
-Resource ${TESTDIR}/lib/rspamd.robot
-
-*** Variables ***
-@{ALIASES} STATSDIR
-${CONFIG} ${TESTDIR}/configs/stats.conf
-${MESSAGE} ${TESTDIR}/messages/spam_message.eml
-${RSPAMD_SCOPE} Test
-
-*** Keywords ***
-Statistics Setup
- [Arguments] @{aliases} &{kw}
- &{RSPAMD_KEYWORDS} = Create Dictionary KEY_PRIVATE=${KEY_PVT1} KEY_PUBLIC=${KEY_PUB1} LOCAL_ADDR=${LOCAL_ADDR} PORT_CONTROLLER=${PORT_CONTROLLER} PORT_NORMAL=${PORT_NORMAL} TESTDIR=${TESTDIR}
- Update Dictionary ${RSPAMD_KEYWORDS} ${kw}
- Set Test Variable &{RSPAMD_KEYWORDS}
- ${TMPDIR} ${RSPAMD_PID} ${RSPAMD_LOGPOS} = Run Rspamd @{aliases} &{RSPAMD_KEYWORDS}
- Export Rspamd Vars To Test ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID}
-
-*** Test Cases ***
-Sqlite Learn - Keyed, siphash
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=siphash STATS_KEY=${KEY_PVT1}
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- [Teardown] Generic Teardown
-
-Sqlite Learn - Keyed, xxhash
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1}
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- [Teardown] Generic Teardown
-
-Sqlite Learn - Broken Stats Directory
- [Setup] Statistics Setup @{EMPTY} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1} STATSDIR=/does/not/exist
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Follow Rspamd Log
- Should Not Contain ${result.stdout} success = true
- [Teardown] Generic Teardown
-
-Sqlite Learn - Empty part
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1}
- Set Test Variable ${MESSAGE} ${TESTDIR}/messages/empty_part.eml
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- [Teardown] Generic Teardown
-
-Sqlite Relearn
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=sqlite3 STATS_HASH=xxh STATS_KEY=${KEY_PVT1}
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_ham ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_HAM
- [Teardown] Generic Teardown
-
-Mmap Learn
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=mmap STATS_HASH=compat STATS_KEY=${KEY_PVT1}
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- [Teardown] Generic Teardown
-
-Mmap Relearn
- [Setup] Statistics Setup @{ALIASES} STATS_BACKEND=mmap STATS_HASH=compat STATS_KEY=${KEY_PVT1}
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_SPAM
- ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_ham ${MESSAGE}
- Check Rspamc ${result}
- ${result} = Scan Message With Rspamc ${MESSAGE}
- Check Rspamc ${result} BAYES_HAM
- [Teardown] Generic Teardown
diff --git a/test/functional/cases/statistics/compat-keyed.robot b/test/functional/cases/statistics/compat-keyed.robot
new file mode 100644
index 000000000..054978745
--- /dev/null
+++ b/test/functional/cases/statistics/compat-keyed.robot
@@ -0,0 +1,19 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} mmap
+${STATS_HASH} hash = "compat";
+${STATS_KEY} key = "${KEY_PVT1}";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/compat-plain.robot b/test/functional/cases/statistics/compat-plain.robot
new file mode 100644
index 000000000..246d5a5d5
--- /dev/null
+++ b/test/functional/cases/statistics/compat-plain.robot
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} mmap
+${STATS_HASH} hash = "compat";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/lib.robot b/test/functional/cases/statistics/lib.robot
new file mode 100644
index 000000000..f710a87d5
--- /dev/null
+++ b/test/functional/cases/statistics/lib.robot
@@ -0,0 +1,59 @@
+*** Settings ***
+Library ${TESTDIR}/lib/rspamd.py
+Resource ${TESTDIR}/lib/rspamd.robot
+Variables ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG} ${TESTDIR}/configs/stats.conf
+${MESSAGE} ${TESTDIR}/messages/spam_message.eml
+${REDIS_SCOPE} Suite
+${REDIS_SERVER} ${EMPTY}
+${RSPAMD_SCOPE} Suite
+${STATS_HASH} ${EMPTY}
+${STATS_KEY} ${EMPTY}
+${STATS_PATH_CACHE} path = "\${TMPDIR}/bayes-cache.sqlite";
+${STATS_PATH_HAM} path = "\${TMPDIR}/bayes-ham.sqlite";
+${STATS_PATH_SPAM} path = "\${TMPDIR}/bayes-spam.sqlite";
+
+*** Keywords ***
+Broken Learn Test
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
+ Follow Rspamd Log
+ Should Not Contain ${result.stdout} success = true
+ Should Not Equal As Integers ${result.rc} 0
+
+Empty Part Test
+ Set Test Variable ${MESSAGE} ${TESTDIR}/messages/empty_part.eml
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
+ Check Rspamc ${result}
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} BAYES_SPAM
+
+Learn Test
+ Set Suite Variable ${RSPAMD_STATS_LEARNTEST} 0
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_spam ${MESSAGE}
+ Check Rspamc ${result}
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} BAYES_SPAM
+ Set Suite Variable ${RSPAMD_STATS_LEARNTEST} 1
+
+Relearn Test
+ Run Keyword If ${RSPAMD_STATS_LEARNTEST} == 0 Fail "Learn test was not run"
+ ${result} = Run Rspamc -h ${LOCAL_ADDR}:${PORT_CONTROLLER} learn_ham ${MESSAGE}
+ Check Rspamc ${result}
+ ${result} = Scan Message With Rspamc ${MESSAGE}
+ Check Rspamc ${result} BAYES_HAM
+
+Redis Statistics Setup
+ Generic Setup
+ Run Redis
+
+Redis Statistics Teardown
+ Generic Teardown
+ Shutdown Process ${REDIS_PID}
+
+Statistics Setup
+ Generic Setup STATS_PATH_CACHE STATS_PATH_HAM STATS_PATH_SPAM
+
+Statistics Teardown
+ Generic Teardown
diff --git a/test/functional/cases/statistics/redis-keyed-siphash.robot b/test/functional/cases/statistics/redis-keyed-siphash.robot
new file mode 100644
index 000000000..f598915cd
--- /dev/null
+++ b/test/functional/cases/statistics/redis-keyed-siphash.robot
@@ -0,0 +1,20 @@
+*** Settings ***
+Suite Setup Redis Statistics Setup
+Suite Teardown Redis Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${REDIS_SERVER} servers = "${LOCAL_ADDR}:${REDIS_PORT}"
+${STATS_BACKEND} redis
+${STATS_HASH} hash = "siphash";
+${STATS_KEY} key = "${KEY_PVT1}";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/redis-keyed-xxhash.robot b/test/functional/cases/statistics/redis-keyed-xxhash.robot
new file mode 100644
index 000000000..ca87895c5
--- /dev/null
+++ b/test/functional/cases/statistics/redis-keyed-xxhash.robot
@@ -0,0 +1,20 @@
+*** Settings ***
+Suite Setup Redis Statistics Setup
+Suite Teardown Redis Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${REDIS_SERVER} servers = "${LOCAL_ADDR}:${REDIS_PORT}"
+${STATS_BACKEND} redis
+${STATS_HASH} hash = "xxhash";
+${STATS_KEY} key = "${KEY_PVT1}";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/redis-plain-siphash.robot b/test/functional/cases/statistics/redis-plain-siphash.robot
new file mode 100644
index 000000000..2946e8903
--- /dev/null
+++ b/test/functional/cases/statistics/redis-plain-siphash.robot
@@ -0,0 +1,19 @@
+*** Settings ***
+Suite Setup Redis Statistics Setup
+Suite Teardown Redis Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${REDIS_SERVER} servers = "${LOCAL_ADDR}:${REDIS_PORT}"
+${STATS_BACKEND} redis
+${STATS_HASH} hash = "siphash";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/redis-plain-xxhash.robot b/test/functional/cases/statistics/redis-plain-xxhash.robot
new file mode 100644
index 000000000..de69465f0
--- /dev/null
+++ b/test/functional/cases/statistics/redis-plain-xxhash.robot
@@ -0,0 +1,19 @@
+*** Settings ***
+Suite Setup Redis Statistics Setup
+Suite Teardown Redis Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${REDIS_SERVER} servers = "${LOCAL_ADDR}:${REDIS_PORT}"
+${STATS_BACKEND} redis
+${STATS_HASH} hash = "xxhash";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/sqlite-broken-stats-dir.robot b/test/functional/cases/statistics/sqlite-broken-stats-dir.robot
new file mode 100644
index 000000000..57d75c294
--- /dev/null
+++ b/test/functional/cases/statistics/sqlite-broken-stats-dir.robot
@@ -0,0 +1,15 @@
+*** Settings ***
+Suite Setup Generic Setup
+Suite Teardown Generic Teardown
+Resource ${TESTDIR}/lib/rspamd.robot
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} sqlite3
+${STATS_PATH_CACHE} path = "/does/not/exist/bayes-cache.sqlite";
+${STATS_PATH_HAM} path = "/does/not/exist/bayes-ham.sqlite";
+${STATS_PATH_SPAM} path = "/does/not/exist/bayes-spam.sqlite";
+
+*** Test Cases ***
+Broken Stats Directory
+ Broken Learn Test
diff --git a/test/functional/cases/statistics/sqlite-keyed-siphash.robot b/test/functional/cases/statistics/sqlite-keyed-siphash.robot
new file mode 100644
index 000000000..8b9661a9a
--- /dev/null
+++ b/test/functional/cases/statistics/sqlite-keyed-siphash.robot
@@ -0,0 +1,19 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} sqlite3
+${STATS_HASH} hash = "siphash";
+${STATS_KEY} key = "${KEY_PVT1}";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/sqlite-keyed-xxhash.robot b/test/functional/cases/statistics/sqlite-keyed-xxhash.robot
new file mode 100644
index 000000000..7a51e93ae
--- /dev/null
+++ b/test/functional/cases/statistics/sqlite-keyed-xxhash.robot
@@ -0,0 +1,19 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} sqlite3
+${STATS_HASH} hash = "xxhash";
+${STATS_KEY} key = "${KEY_PVT1}";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/sqlite-plain-siphash.robot b/test/functional/cases/statistics/sqlite-plain-siphash.robot
new file mode 100644
index 000000000..2f88e0a95
--- /dev/null
+++ b/test/functional/cases/statistics/sqlite-plain-siphash.robot
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} sqlite3
+${STATS_HASH} hash = "siphash";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/cases/statistics/sqlite-plain-xxhash.robot b/test/functional/cases/statistics/sqlite-plain-xxhash.robot
new file mode 100644
index 000000000..dd8198222
--- /dev/null
+++ b/test/functional/cases/statistics/sqlite-plain-xxhash.robot
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup Statistics Setup
+Suite Teardown Statistics Teardown
+Resource lib.robot
+
+*** Variables ***
+${STATS_BACKEND} sqlite3
+${STATS_HASH} hash = "xxhash";
+
+*** Test Cases ***
+Learn
+ Learn Test
+
+Relearn
+ Relearn Test
+
+Empty Part
+ Empty Part Test
diff --git a/test/functional/configs/fuzzy.conf b/test/functional/configs/fuzzy.conf
new file mode 100644
index 000000000..9a4ed32d3
--- /dev/null
+++ b/test/functional/configs/fuzzy.conf
@@ -0,0 +1,74 @@
+options = {
+ filters = "fuzzy_check";
+ pidfile = "${TMPDIR}/rspamd.pid"
+ control_socket = "${TMPDIR}/rspamd.sock mode=0600";
+}
+logging = {
+ type = "file",
+ level = "debug"
+ filename = "${TMPDIR}/rspamd.log"
+}
+metric = {
+ name = "default",
+ actions = {
+ reject = 100500,
+ }
+ unknown_weight = 1
+ symbol {
+ weight = 0.0;
+ name = "R_TEST_FUZZY_UNKNOWN";
+ }
+ symbol {
+ weight = 10.0;
+ name = "${FLAG1_SYMBOL}";
+ }
+ symbol {
+ weight = -1.0;
+ name = "${FLAG2_SYMBOL}";
+ }
+}
+
+worker {
+ type = normal
+ bind_socket = "${LOCAL_ADDR}:${PORT_NORMAL}";
+ count = 1
+}
+
+worker {
+ type = controller
+ bind_socket = "${LOCAL_ADDR}:${PORT_CONTROLLER}";
+ count = 1
+ secure_ip = ["${LOCAL_ADDR}"];
+}
+
+worker {
+ bind_socket = "${LOCAL_ADDR}:${PORT_FUZZY}";
+ type = "fuzzy";
+ hashfile = "${TMPDIR}/fuzzy.db";
+ allow_update = ["${LOCAL_ADDR}"];
+ ${SETTINGS_FUZZY_WORKER}
+}
+
+fuzzy_check {
+ min_bytes = 100;
+
+ rule {
+ servers = "${LOCAL_ADDR}:${PORT_FUZZY}";
+ symbol = "R_TEST_FUZZY";
+ max_score = 10.0;
+ mime_types = ["application/*"];
+ read_only = false;
+ skip_unknown = true;
+ ${SETTINGS_FUZZY_CHECK}
+ fuzzy_map = {
+ ${FLAG1_SYMBOL} {
+ max_score = 10.0;
+ flag = ${FLAG1_NUMBER};
+ }
+ ${FLAG2_SYMBOL} {
+ max_score = 1.0;
+ flag = ${FLAG2_NUMBER};
+ }
+ }
+ }
+}
diff --git a/test/functional/configs/redis-server.conf b/test/functional/configs/redis-server.conf
new file mode 100644
index 000000000..2973ae8d9
--- /dev/null
+++ b/test/functional/configs/redis-server.conf
@@ -0,0 +1,4 @@
+bind ${LOCAL_ADDR}
+daemonize yes
+pidfile ${TMPDIR}/redis.pid
+port ${REDIS_PORT}
diff --git a/test/functional/configs/stats.conf b/test/functional/configs/stats.conf
index 144b7a886..216d7d8f3 100644
--- a/test/functional/configs/stats.conf
+++ b/test/functional/configs/stats.conf
@@ -21,8 +21,8 @@ worker {
bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL}
count = 1
keypair {
- pubkey = "${KEY_PUBLIC}";
- privkey = "${KEY_PRIVATE}";
+ pubkey = "${KEY_PUB1}";
+ privkey = "${KEY_PVT1}";
}
}
worker {
@@ -30,8 +30,8 @@ worker {
bind_socket = ${LOCAL_ADDR}:${PORT_CONTROLLER}
count = 1
keypair {
- pubkey = "${KEY_PUBLIC}";
- privkey = "${KEY_PRIVATE}";
+ pubkey = "${KEY_PUB1}";
+ privkey = "${KEY_PVT1}";
}
secure_ip = ["127.0.0.1", "::1"];
}
@@ -40,26 +40,26 @@ classifier {
languages_enabled = true;
tokenizer {
name = "osb";
- hash = ${STATS_HASH}
- key = ${STATS_KEY}
+ ${STATS_HASH}
+ ${STATS_KEY}
}
backend = ${STATS_BACKEND}
statfile {
symbol = BAYES_SPAM;
- path = ${STATSDIR}/rspamd-bats-bayes.spam;
+ ${STATS_PATH_SPAM}
size = 1M;
- write_servers = ${REDIS_SERVER}
+ ${REDIS_SERVER}
}
statfile {
symbol = BAYES_HAM;
- path = ${STATSDIR}/rspamd-bats-bayes.ham;
+ ${STATS_PATH_HAM}
size = 1M;
- write_servers = ${REDIS_SERVER}
+ ${REDIS_SERVER}
}
cache {
- path = ${STATSDIR}/rspamd-bats-cache.sqlite;
- write_servers = ${REDIS_SERVER}
+ ${STATS_PATH_CACHE}
+ ${REDIS_SERVER}
}
}
diff --git a/test/functional/configs/trivial.conf b/test/functional/configs/trivial.conf
index 03fb11e0f..9bc07fa5c 100644
--- a/test/functional/configs/trivial.conf
+++ b/test/functional/configs/trivial.conf
@@ -21,7 +21,7 @@ worker {
bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL}
count = 1
keypair {
- pubkey = "${KEY_PUBLIC}";
- privkey = "${KEY_PRIVATE}";
+ pubkey = "${KEY_PUB1}";
+ privkey = "${KEY_PVT1}";
}
}
diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py
index 93ec4c430..10caab3ca 100644
--- a/test/functional/lib/rspamd.py
+++ b/test/functional/lib/rspamd.py
@@ -29,12 +29,6 @@ def get_test_directory():
def make_temporary_directory():
return tempfile.mkdtemp()
-def populate_rspamd_config(template_file, temporary_dir, **config):
- t = string.Template(open(template_file).read())
- f = open("%s/rspamd.conf" % temporary_dir, "w")
- f.write(t.safe_substitute(config))
- f.close()
-
def process_should_exist(pid):
pid = int(pid)
os.kill(pid, 0)
@@ -75,7 +69,7 @@ def update_dictionary(a, b):
a.update(b)
return a
-def shutdown_rspamd(pid):
+def shutdown_process(pid):
pid = int(pid)
process_should_exist(pid)
i = 0
diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot
index b6180d40d..ded537e03 100644
--- a/test/functional/lib/rspamd.robot
+++ b/test/functional/lib/rspamd.robot
@@ -1,7 +1,7 @@
*** Settings ***
-Library Collections
-Library OperatingSystem
-Library Process
+Library Collections
+Library OperatingSystem
+Library Process
*** Keywords ***
Check Rspamc
@@ -32,42 +32,64 @@ Follow Rspamd Log
... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
Generic Setup
- ${TMPDIR} ${RSPAMD_PID} ${RSPAMD_LOGPOS} = Run Rspamd
+ [Arguments] @{vargs}
+ ${TMPDIR} ${RSPAMD_PID} ${RSPAMD_LOGPOS} = Run Rspamd @{vargs}
Run Keyword If '${RSPAMD_SCOPE}' == 'Test' Export Rspamd Vars To Test ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID}
... ELSE IF '${RSPAMD_SCOPE}' == 'Suite' Export Rspamd Vars To Suite ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID}
... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
Generic Teardown
- Shutdown Rspamd ${RSPAMD_PID}
- Cleanup Temporary Directory ${TMPDIR}
+ Shutdown Process ${RSPAMD_PID}
+ Cleanup Temporary Directory ${TMPDIR}
Log Logs
- [Arguments] ${logfile} ${position}
- ${the_log} ${position} = Read Log From Position ${logfile} ${position}
- Log ${the_log}
- [Return] ${position}
+ [Arguments] ${logfile} ${position}
+ ${the_log} ${position} = Read Log From Position ${logfile} ${position}
+ Log ${the_log}
+ [Return] ${position}
+
+Run Redis
+ ${template} = Get File ${TESTDIR}/configs/redis-server.conf
+ ${config} = Replace Variables ${template}
+ Create File ${TMPDIR}/redis-server.conf ${config}
+ ${result} = Run Process redis-server ${TMPDIR}/redis-server.conf
+ Should Be Equal As Integers ${result.rc} 0
+ ${REDIS_PID} = Get File ${TMPDIR}/redis.pid
+ Run Keyword If '${REDIS_SCOPE}' == 'Test' Set Test Variable ${REDIS_PID}
+ ... ELSE IF '${REDIS_SCOPE}' == 'Suite' Set Suite Variable ${REDIS_PID}
Run Rspamc
- [Arguments] @{args}
- ${result} = Run Process ${RSPAMC} @{args}
- [Return] ${result}
+ [Arguments] @{args}
+ ${result} = Run Process ${RSPAMC} @{args}
+ [Return] ${result}
Run Rspamd
- [Arguments] @{args} &{kw}
- ${tmpdir} = Make Temporary Directory
- Set Directory Ownership ${tmpdir} ${RSPAMD_USER} ${RSPAMD_GROUP}
- Set To Dictionary ${RSPAMD_KEYWORDS} TMPDIR=${tmpdir}
- Update Dictionary ${RSPAMD_KEYWORDS} ${kw}
- :FOR ${i} IN @{args}
- \ Set To Dictionary ${RSPAMD_KEYWORDS} ${i} ${tmpdir}
- Populate Rspamd Config ${CONFIG} ${tmpdir} &{RSPAMD_KEYWORDS}
- ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP} -c ${tmpdir}/rspamd.conf
- ${rspamd_logpos} = Log Logs ${tmpdir}/rspamd.log 0
- Should Be Equal As Integers ${result.rc} 0
- ${rspamd_pid} = Get File ${tmpdir}/rspamd.pid
- [Return] ${tmpdir} ${rspamd_pid} ${rspamd_logpos}
+ [Arguments] @{vargs}
+ ${TMPDIR} = Make Temporary Directory
+ Set Directory Ownership ${TMPDIR} ${RSPAMD_USER} ${RSPAMD_GROUP}
+ ${template} = Get File ${CONFIG}
+ : FOR ${i} IN @{vargs}
+ \ ${newvalue} = Replace Variables ${${i}}
+ \ Set Suite Variable ${${i}} ${newvalue}
+ \ Run Keyword If '${RSPAMD_SCOPE}' == 'Test' Set Test Variable ${${i}} ${newvalue}
+ \ ... ELSE IF '${RSPAMD_SCOPE}' == 'Suite' Set Suite Variable ${${i}} ${newvalue}
+ \ ... ELSE Fail 'RSPAMD_SCOPE must be Test or Suite'
+ ${config} = Replace Variables ${template}
+ Log ${config}
+ Create File ${TMPDIR}/rspamd.conf ${config}
+ ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP}
+ ... -c ${TMPDIR}/rspamd.conf
+ ${rspamd_logpos} = Log Logs ${TMPDIR}/rspamd.log 0
+ Should Be Equal As Integers ${result.rc} 0
+ ${rspamd_pid} = Get File ${TMPDIR}/rspamd.pid
+ [Return] ${TMPDIR} ${rspamd_pid} ${rspamd_logpos}
Scan Message With Rspamc
- [Arguments] ${msg_file}
- ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} ${msg_file}
- [Return] ${result}
+ [Arguments] ${msg_file}
+ ${result} = Run Rspamc -p -h ${LOCAL_ADDR}:${PORT_NORMAL} ${msg_file}
+ [Return] ${result}
+
+Sync Fuzzy Storage
+ ${result} = Run Process ${RSPAMADM} control -s ${TMPDIR}/rspamd.sock fuzzy_sync
+ Log ${result.stdout}
+ Follow Rspamd Log
diff --git a/test/functional/lib/vars.py b/test/functional/lib/vars.py
index 78151bd37..316669911 100644
--- a/test/functional/lib/vars.py
+++ b/test/functional/lib/vars.py
@@ -2,6 +2,8 @@ KEY_PVT1 = 'ekd3x36tfa5gd76t6pa8hqif3ott7n1siuux68exbkk7ukscte9y'
KEY_PUB1 = 'm8kneubpcjsb8sbsoj7jy7azj9fdd3xmj63txni86a8ye9ncomny'
LOCAL_ADDR = 'localhost'
PORT_CONTROLLER = 56790
+PORT_FUZZY = 56791
PORT_NORMAL = 56789
+REDIS_PORT = 56379
RSPAMD_GROUP = 'nogroup'
RSPAMD_USER = 'nobody'