2 changed files with 0 additions and 277 deletions
@ -1,61 +0,0 @@ |
|||
TMPDIR=${BATS_TMPDIR} |
|||
|
|||
function run_rspamd() { |
|||
TMPDIR=${BATS_TMPDIR} |
|||
RSPAMD_USER=${RSPAMD_USER:-"nobody"} |
|||
RSPAMD_GROUP=${RSPAMD_GROUP:-"nogroup"} |
|||
RSPAMD=${RSPAMD:-"$BATS_TEST_DIRNAME/../../src/rspamd"} |
|||
STATS_BACKEND=${STATS_BACKEND:-"mmap"} |
|||
STATS_HASH=${STATS_HASH:-"compat"} |
|||
STATS_KEY=${STATS_KEY:-"osipg87ms5gzsis33fdrhaqn5wocp6qfofzxjbw8k1wh9yb6adty"} |
|||
|
|||
if [ -f ${TMPDIR}/rspamd-bats-${BATS_TEST_NAME}.log ] ; then |
|||
rm -f ${TMPDIR}/rspamd-bats-${BATS_TEST_NAME}.log |
|||
fi |
|||
${RSPAMD} -c ${RSPAMD_CONFIG} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP} \ |
|||
TMPDIR=${TMPDIR} \ |
|||
STATSDIR=${STATSDIR} \ |
|||
LUADIR=${LUADIR} \ |
|||
TEST_NUM=${BATS_TEST_NAME} \ |
|||
STATS_BACKEND=${STATS_BACKEND} \ |
|||
STATS_HASH=${STATS_HASH} \ |
|||
STATS_KEY=${STATS_KEY} |
|||
} |
|||
|
|||
|
|||
function teardown() { |
|||
( |
|||
pgrep rspamd > /dev/null 2>&1 |
|||
while [ $? -eq 0 ] ; do |
|||
pkill -TERM rspamd || true |
|||
pgrep rspamd > /dev/null 2>&1 |
|||
if [ $? -eq 0 ] ; then |
|||
sleep 0.1 |
|||
fi |
|||
pgrep rspamd > /dev/null 2>&1 |
|||
done |
|||
) || true |
|||
} |
|||
|
|||
function clear_stats() { |
|||
rm -f ${STATSDIR}/rspamd-bats-cache.sqlite \ |
|||
${STATSDIR}/rspamd-bats-bayes.spam \ |
|||
${STATSDIR}/rspamd-bats-bayes.ham || true |
|||
} |
|||
|
|||
function check_output() { |
|||
_output="$1" |
|||
_pattern="$2" |
|||
|
|||
( |
|||
echo $_output | egrep $_pattern |
|||
|
|||
_saved_exit=$? |
|||
if [ $_saved_exit -ne 0 ] ; then |
|||
printf "Expected pattern %s, while get output:\n%s\nEND\n" $_pattern $_output >&2 |
|||
return $_saved_exit |
|||
fi |
|||
|
|||
return 0 |
|||
) |
|||
} |
|||
@ -1,216 +0,0 @@ |
|||
load test_helper |
|||
|
|||
RSPAMC="$BATS_TEST_DIRNAME/../../src/client/rspamc" |
|||
|
|||
@test "Test rspamd using gtube" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf" |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
"$BATS_TEST_DIRNAME/messages/gtube.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'Action: reject' |
|||
} |
|||
|
|||
@test "Test rspamd encrypted using gtube" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf" |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
"$BATS_TEST_DIRNAME/messages/gtube.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'Action: reject' |
|||
} |
|||
|
|||
@test "Test rspamd spamc gtube" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/trivial.conf" |
|||
run_rspamd |
|||
run perl $BATS_TEST_DIRNAME/cases/spamc.pl "$BATS_TEST_DIRNAME/messages/gtube.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'GTUBE' |
|||
} |
|||
|
|||
@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" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'Action: reject' |
|||
} |
|||
|
|||
@test "Test rspamd learn" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'BAYES_SPAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test rspamd re-learn" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_ham \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'BAYES_HAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test learn message with an empty part" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/empty_part.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/empty_part.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'BAYES_SPAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test rspamd re-learn sqlite3 backend" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} \ |
|||
STATS_BACKEND="sqlite3" |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_ham \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
check_output $output 'BAYES_HAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test rspamd xxhash tokenizer" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} \ |
|||
STATS_HASH="xxh" |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'BAYES_SPAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test rspamd siphash tokenizer" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=${BATS_TMPDIR} \ |
|||
STATS_HASH="siphash" |
|||
clear_stats |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'success.*true' |
|||
|
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'BAYES_SPAM' |
|||
clear_stats |
|||
} |
|||
|
|||
@test "Test learn message with bad statfiles" { |
|||
export RSPAMD_CONFIG="$BATS_TEST_DIRNAME/configs/stats.conf" \ |
|||
STATSDIR=/non/existent |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56790 \ |
|||
--key y3ms1knmetxf8gdeixkf74b6tbpxqugmxzqksnjodiqei7tksyty \ |
|||
learn_spam \ |
|||
"$BATS_TEST_DIRNAME/messages/empty_part.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'cannot open backend' |
|||
} |
|||
|
|||
@test "Test rspamd dependencies" { |
|||
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" \ |
|||
STATSDIR=${BATS_TMPDIR} |
|||
run_rspamd |
|||
run ${RSPAMC} -h localhost:56789 \ |
|||
symbols \ |
|||
"$BATS_TEST_DIRNAME/messages/spam_message.eml" |
|||
[ "$status" -eq 0 ] |
|||
|
|||
check_output $output 'DEP10' |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue