aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-07 09:47:50 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-07 09:47:50 +0100
commit4355ecf626c1e463818b36094cff39976848ca9f (patch)
treeb57893d84ae504787ef259f38eb574b088de2c7a /test
parent61d68ce55e03ed4667a5b647c0f286005ce01c85 (diff)
downloadrspamd-4355ecf626c1e463818b36094cff39976848ca9f.tar.gz
rspamd-4355ecf626c1e463818b36094cff39976848ca9f.zip
Add dependencies test.
Diffstat (limited to 'test')
-rw-r--r--test/functional/cases/deps.lua32
-rw-r--r--test/functional/configs/lua_test.conf32
-rw-r--r--test/functional/test_helper.bash2
-rw-r--r--test/functional/tests.bats17
4 files changed, 82 insertions, 1 deletions
diff --git a/test/functional/cases/deps.lua b/test/functional/cases/deps.lua
new file mode 100644
index 000000000..581825400
--- /dev/null
+++ b/test/functional/cases/deps.lua
@@ -0,0 +1,32 @@
+local logger = require "rspamd_logger"
+
+local cb = function(task)
+ task:insert_result('TOP', 1.0)
+end
+
+local cb_dep1 = function(task)
+ if task:get_symbol('TOP') then
+ task:insert_result('DEP1', 1.0)
+ end
+end
+
+local cb_gen = function(num)
+ local cb_dep = function(task)
+ if task:get_symbol('DEP' .. tostring(num)) then
+ task:insert_result('DEP' .. tostring(num + 1), 1.0)
+ end
+ end
+
+ return cb_dep
+end
+
+local id = rspamd_config:register_callback_symbol(1.0, cb)
+rspamd_config:register_virtual_symbol('TOP', 1.0, id)
+
+rspamd_config:register_symbol('DEP1', 1.0, cb_dep1)
+rspamd_config:register_dependency('DEP1', 'TOP')
+
+for i = 2,10 do
+ rspamd_config:register_symbol('DEP' .. tostring(i), 1.0, cb_gen(i - 1))
+ rspamd_config:register_dependency('DEP' .. tostring(i), 'DEP' .. tostring(i - 1))
+end \ No newline at end of file
diff --git a/test/functional/configs/lua_test.conf b/test/functional/configs/lua_test.conf
new file mode 100644
index 000000000..0cab3c59c
--- /dev/null
+++ b/test/functional/configs/lua_test.conf
@@ -0,0 +1,32 @@
+options = {
+ filters = ["spf", "dkim", "regexp"]
+ url_tld = "${CURDIR}/lua/unit/test_tld.dat"
+ dns = {
+ nameserver = "8.8.8.8"
+ }
+ pidfile = "${TMPDIR}/rspamd-bats.pid"
+}
+logging = {
+ type = "file",
+ level = "debug"
+ filename = "/tmp/rspamd-bats.log"
+}
+metric = {
+ name = "default",
+ actions = {
+ reject = 100500,
+ }
+ unknown_weight = 1
+}
+
+worker {
+ type = normal
+ bind_socket = localhost:56789
+ count = 1
+ keypair {
+ pubkey = "y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty";
+ privkey = "oswsyqndpj3swqa4yqm4yzoyih83otqkeoxpo9km95o46ixh6quy";
+ }
+}
+
+lua = @@LUA_SCRIPT@@;
diff --git a/test/functional/test_helper.bash b/test/functional/test_helper.bash
index 4323109b9..a25035e77 100644
--- a/test/functional/test_helper.bash
+++ b/test/functional/test_helper.bash
@@ -12,7 +12,7 @@ function run_rspamd() {
function teardown() {
- pkill -TERM rspamd
+ pkill -TERM rspamd || true
}
function clear_stats() {
diff --git a/test/functional/tests.bats b/test/functional/tests.bats
index aaa57ebb3..387c7c260 100644
--- a/test/functional/tests.bats
+++ b/test/functional/tests.bats
@@ -33,6 +33,7 @@ RSPAMC="$BATS_TEST_DIRNAME/../../src/client/rspamc"
}
@test "Test rspamd streamlined gtube" {
+ skip
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf"
run_rspamd
run perl $BATS_TEST_DIRNAME/cases/http_streamline.pl "$BATS_TEST_DIRNAME/messages/gtube.eml"
@@ -91,4 +92,20 @@ RSPAMC="$BATS_TEST_DIRNAME/../../src/client/rspamc"
echo $output | grep 'BAYES_HAM'
clear_stats
+}
+
+@test "Test rspamd dependencies" {
+ clear_stats
+ sed -e 's|@@LUA_SCRIPT@@|${CURDIR}/functional/cases/deps.lua|' < \
+ "$BATS_TEST_DIRNAME/configs/lua_test.conf" > \
+ "$BATS_TMPDIR/rspamd.conf"
+ export RSPAMD_CONFIG="$BATS_TMPDIR/rspamd.conf"
+ run_rspamd
+ run ${RSPAMC} -h localhost:56789 \
+ symbols \
+ "$BATS_TEST_DIRNAME/messages/spam_message.eml"
+ [ "$status" -eq 0 ]
+
+ echo $output | grep 'DEP10'
+ clear_stats
} \ No newline at end of file