]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Add & rework functional tests 693/head
authorAndrew Lewis <nerf@judo.za.org>
Sat, 2 Jul 2016 15:48:58 +0000 (17:48 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Sat, 2 Jul 2016 16:36:15 +0000 (18:36 +0200)
 - Machine formatted test data
 - More idiomatic use of test framework
 - Added tests for fuzzy & redis statistics

26 files changed:
test/functional/cases/__init__.robot
test/functional/cases/fuzzy/encrypted.robot [new file with mode: 0644]
test/functional/cases/fuzzy/lib.robot [new file with mode: 0644]
test/functional/cases/fuzzy/plain.robot [new file with mode: 0644]
test/functional/cases/general.robot
test/functional/cases/lua.robot
test/functional/cases/statistics.robot [deleted file]
test/functional/cases/statistics/compat-keyed.robot [new file with mode: 0644]
test/functional/cases/statistics/compat-plain.robot [new file with mode: 0644]
test/functional/cases/statistics/lib.robot [new file with mode: 0644]
test/functional/cases/statistics/redis-keyed-siphash.robot [new file with mode: 0644]
test/functional/cases/statistics/redis-keyed-xxhash.robot [new file with mode: 0644]
test/functional/cases/statistics/redis-plain-siphash.robot [new file with mode: 0644]
test/functional/cases/statistics/redis-plain-xxhash.robot [new file with mode: 0644]
test/functional/cases/statistics/sqlite-broken-stats-dir.robot [new file with mode: 0644]
test/functional/cases/statistics/sqlite-keyed-siphash.robot [new file with mode: 0644]
test/functional/cases/statistics/sqlite-keyed-xxhash.robot [new file with mode: 0644]
test/functional/cases/statistics/sqlite-plain-siphash.robot [new file with mode: 0644]
test/functional/cases/statistics/sqlite-plain-xxhash.robot [new file with mode: 0644]
test/functional/configs/fuzzy.conf [new file with mode: 0644]
test/functional/configs/redis-server.conf [new file with mode: 0644]
test/functional/configs/stats.conf
test/functional/configs/trivial.conf
test/functional/lib/rspamd.py
test/functional/lib/rspamd.robot
test/functional/lib/vars.py

index 46fdc8f2aa1886be43edefa1a49e0bed086169b8..4b95b921733fab54fca63a2cc1d76739f89b3b61 100644 (file)
@@ -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 (file)
index 0000000..45408d7
--- /dev/null
@@ -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 (file)
index 0000000..e5e9cbc
--- /dev/null
@@ -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 (file)
index 0000000..2fc2fd5
--- /dev/null
@@ -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
index aa146b4a9255141d6690009845aa5abd399b1f00..5fb80520dc24742fffb7395012edaa5b5a32b2f5 100644 (file)
@@ -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
index 46dd15ea0c3d70da23c45738d7a5cfee5ef8d4e2..f3a3567eccc47d59c7b8421cb47684a60d302d6c 100644 (file)
@@ -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 (file)
index 6d0218b..0000000
+++ /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 (file)
index 0000000..0549787
--- /dev/null
@@ -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 (file)
index 0000000..246d5a5
--- /dev/null
@@ -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 (file)
index 0000000..f710a87
--- /dev/null
@@ -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 (file)
index 0000000..f598915
--- /dev/null
@@ -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 (file)
index 0000000..ca87895
--- /dev/null
@@ -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 (file)
index 0000000..2946e89
--- /dev/null
@@ -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 (file)
index 0000000..de69465
--- /dev/null
@@ -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 (file)
index 0000000..57d75c2
--- /dev/null
@@ -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 (file)
index 0000000..8b9661a
--- /dev/null
@@ -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 (file)
index 0000000..7a51e93
--- /dev/null
@@ -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 (file)
index 0000000..2f88e0a
--- /dev/null
@@ -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 (file)
index 0000000..dd81982
--- /dev/null
@@ -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 (file)
index 0000000..9a4ed32
--- /dev/null
@@ -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 (file)
index 0000000..2973ae8
--- /dev/null
@@ -0,0 +1,4 @@
+bind ${LOCAL_ADDR}
+daemonize yes
+pidfile ${TMPDIR}/redis.pid
+port ${REDIS_PORT}
index 144b7a886ed5fdee11850cc5ae2f88094307161f..216d7d8f330b64734e129a4d60406713457c29af 100644 (file)
@@ -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}
        }
 }
 
index 03fb11e0f78372996af6977db363e07810807ad4..9bc07fa5cca843d9839e6991ca5967ec34771f3c 100644 (file)
@@ -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}";
        }
 }
index 93ec4c43006247ccd4abf1b787c6ff927a55e604..10caab3ca5bcb39c2cc17e4eb4e6de0edf707f47 100644 (file)
@@ -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
index b6180d40d4cd2abad99fae641480ad27cd5c775f..ded537e037c2e16ef3371f9bb0d991c76db5da04 100644 (file)
@@ -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
index 78151bd3798982af2bbc99f9b49fc25e145b73fd..31666991149d06a03b83f490344f4d19699912a9 100644 (file)
@@ -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'