From f0349d47ad137f8d965377e2e037bff25e009f8b Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Sun, 10 Jul 2016 13:39:33 +0200 Subject: [PATCH] [Test] Some basic functional tests for mime_types module & archives - Also some new features for Check Rspamc function - Run rspamd/rspamc with LD_LIBRARY_PATH --- test/functional/cases/archives.robot | 23 +++++++++++++ test/functional/cases/statistics/lib.robot | 4 +-- test/functional/configs/plugins.conf | 38 ++++++++++++++++++++ test/functional/lib/rspamd.robot | 40 +++++++++++++++++----- test/functional/messages/rar4.eml | 10 ++++++ test/functional/messages/zip-doublebad.eml | 12 +++++++ test/functional/messages/zip.eml | 11 ++++++ 7 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 test/functional/cases/archives.robot create mode 100644 test/functional/configs/plugins.conf create mode 100644 test/functional/messages/rar4.eml create mode 100644 test/functional/messages/zip-doublebad.eml create mode 100644 test/functional/messages/zip.eml diff --git a/test/functional/cases/archives.robot b/test/functional/cases/archives.robot new file mode 100644 index 000000000..c94de4e5e --- /dev/null +++ b/test/functional/cases/archives.robot @@ -0,0 +1,23 @@ +*** Settings *** +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/plugins.conf +${RSPAMD_SCOPE} Suite + +*** Test Cases *** +Zip + ${result} = Scan Message With Rspamc ${TESTDIR}/messages/zip.eml + Check Rspamc ${result} MIME_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[exe\\]\\n re=1 + +Zip Double Bad Extension + ${result} = Scan Message With Rspamc ${TESTDIR}/messages/zip-doublebad.eml + Check Rspamc ${result} MIME_DOUBLE_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[pdf, exe\\]\\n re=1 + +Rar4 + ${result} = Scan Message With Rspamc ${TESTDIR}/messages/rar4.eml + Check Rspamc ${result} MIME_BAD_EXTENSION \\(\\d+\\.\\d+\\)\\[exe\\]\\n re=1 diff --git a/test/functional/cases/statistics/lib.robot b/test/functional/cases/statistics/lib.robot index f710a87d5..387fa5ca8 100644 --- a/test/functional/cases/statistics/lib.robot +++ b/test/functional/cases/statistics/lib.robot @@ -18,9 +18,7 @@ ${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 + Check Rspamc ${result} inverse=1 Empty Part Test Set Test Variable ${MESSAGE} ${TESTDIR}/messages/empty_part.eml diff --git a/test/functional/configs/plugins.conf b/test/functional/configs/plugins.conf new file mode 100644 index 000000000..6eded737a --- /dev/null +++ b/test/functional/configs/plugins.conf @@ -0,0 +1,38 @@ +options = { + pidfile = "${TMPDIR}/rspamd.pid" +} +logging = { + type = "file", + level = "debug" + filename = "${TMPDIR}/rspamd.log" +} +metric = { + name = "default", + actions = { + reject = 100500, + } + unknown_weight = 1 +} +worker { + type = normal + bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL} + count = 1 +} +mime_types { + file = "${TESTDIR}/../../../conf/mime_types.inc"; + extension_map { + html = "text/html"; + txt [ + "message/disposition-notification", + "text/plain", + "text/rfc822-headers", + ] + pdf [ + "application/octet-stream", + "application/pdf", + ] + } +} +modules { + path = "${TESTDIR}/../../src/plugins/lua/" +} diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot index ded537e03..eb70d4c43 100644 --- a/test/functional/lib/rspamd.robot +++ b/test/functional/lib/rspamd.robot @@ -5,13 +5,36 @@ Library Process *** Keywords *** Check Rspamc - [Arguments] ${result} @{args} - ${arglen} = Get Length ${args} - ${expected_output} = Set Variable If ${arglen} < 1 success = true @{args}[0] - ${expected_rc} = Set Variable If ${arglen} < 2 0 @{args}[1] + [Arguments] ${result} @{args} &{kwargs} Follow Rspamd Log - Should Contain ${result.stdout} ${expected_output} - Should Be Equal As Integers ${result.rc} ${expected_rc} + Run Keyword If ${result.rc} != 0 Log ${result.stderr} + ${has_rc} = Evaluate 'rc' in $kwargs + ${inverse} = Evaluate 'inverse' in $kwargs + ${re} = Evaluate 're' in $kwargs + ${rc} = Set Variable If ${has_rc} == True &{kwargs}[rc] 0 + : FOR ${i} IN @{args} + \ Run Keyword If ${re} == True Check Rspamc Match Regexp ${result.stdout} ${i} ${inverse} + \ ... ELSE Check Rspamc Match String ${result.stdout} ${i} ${inverse} + Run Keyword If @{args} == @{EMPTY} Check Rspamc Match Default ${result.stdout} ${inverse} + ${rc_nocheck} = Evaluate 'rc_nocheck' in $kwargs + Run Keyword If ${rc_nocheck} == True Return From Keyword + Run Keyword If ${inverse} == False Should Be Equal As Integers ${result.rc} ${rc} + ... ELSE Should Not Be Equal As Integers ${result.rc} ${rc} + +Check Rspamc Match Default + [Arguments] ${subject} ${inverse} + Run Keyword If ${inverse} == False Should Contain ${subject} success = true + ... ELSE Should Not Contain ${subject} success = true + +Check Rspamc Match Regexp + [Arguments] ${subject} ${re} ${inverse} + Run Keyword If ${inverse} == False Should Match Regexp ${subject} ${re} + ... ELSE Should Not Match Regexp ${subject} ${re} + +Check Rspamc Match String + [Arguments] ${subject} ${str} ${inverse} + Run Keyword If ${inverse} == False Should Contain ${subject} ${str} + ... ELSE Should Not Contain ${subject} ${str} Export Rspamd Vars To Suite [Arguments] ${TMPDIR} ${RSPAMD_LOGPOS} ${RSPAMD_PID} @@ -60,7 +83,7 @@ Run Redis Run Rspamc [Arguments] @{args} - ${result} = Run Process ${RSPAMC} @{args} + ${result} = Run Process ${RSPAMC} @{args} env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick [Return] ${result} Run Rspamd @@ -78,7 +101,8 @@ Run Rspamd Log ${config} Create File ${TMPDIR}/rspamd.conf ${config} ${result} = Run Process ${RSPAMD} -u ${RSPAMD_USER} -g ${RSPAMD_GROUP} - ... -c ${TMPDIR}/rspamd.conf + ... -c ${TMPDIR}/rspamd.conf env:LD_LIBRARY_PATH=${TESTDIR}/../../contrib/aho-corasick + Run Keyword If ${result.rc} != 0 Log ${result.stderr} ${rspamd_logpos} = Log Logs ${TMPDIR}/rspamd.log 0 Should Be Equal As Integers ${result.rc} 0 ${rspamd_pid} = Get File ${TMPDIR}/rspamd.pid diff --git a/test/functional/messages/rar4.eml b/test/functional/messages/rar4.eml new file mode 100644 index 000000000..61f6836ea --- /dev/null +++ b/test/functional/messages/rar4.eml @@ -0,0 +1,10 @@ +Content-Type: multipart/mixed; boundary="=_hqO3MQBWZkrB1Zd_nWFL3XM" + +--=_hqO3MQBWZkrB1Zd_nWFL3XM +Content-Type: application/x-rar-compressed; name=f.rar +Content-Disposition: attachment; size=68; filename=f.rar +Content-Transfer-Encoding: base64 + +UmFyIRoHAM+QcwAADQAAAAAAAADSkHQggCgAAQAAAAEAAAADkwbXMiqO6UgdMAgAtIEAAGZha2Uu +ZXhlCsQ9ewBABwA= +--=_hqO3MQBWZkrB1Zd_nWFL3XM-- diff --git a/test/functional/messages/zip-doublebad.eml b/test/functional/messages/zip-doublebad.eml new file mode 100644 index 000000000..b8fbb41b8 --- /dev/null +++ b/test/functional/messages/zip-doublebad.eml @@ -0,0 +1,12 @@ +Content-Type: multipart/mixed; boundary="=__i0GhaBNmijobzbiTaqMvfI" + +--=__i0GhaBNmijobzbiTaqMvfI +Content-Type: application/zip; name=f.zip +Content-Disposition: attachment; size=174; filename=f.zip +Content-Transfer-Encoding: base64 + +UEsDBAoAAAAAAJNg6kgAAAAAAAAAAAAAAAAMABwAZmFrZS5wZGYuZXhlVVQJAAO1HYJXtR2CV3V4 +CwABBOgDAAAE6AMAAFBLAQIeAwoAAAAAAJNg6kgAAAAAAAAAAAAAAAAMABgAAAAAAAAAAAC0gQAA +AABmYWtlLnBkZi5leGVVVAUAA7Udgld1eAsAAQToAwAABOgDAABQSwUGAAAAAAEAAQBSAAAARgAA +AAAA +--=__i0GhaBNmijobzbiTaqMvfI-- diff --git a/test/functional/messages/zip.eml b/test/functional/messages/zip.eml new file mode 100644 index 000000000..dd6bc0b69 --- /dev/null +++ b/test/functional/messages/zip.eml @@ -0,0 +1,11 @@ +Content-Type: multipart/mixed; boundary="=_MlaYox31rMNP821ZlG2h4Xe" + +--=_MlaYox31rMNP821ZlG2h4Xe +Content-Type: application/zip; name=f.zip +Content-Disposition: attachment; size=166; filename=f.zip +Content-Transfer-Encoding: base64 + +UEsDBAoAAAAAAINe6kgAAAAAAAAAAAAAAAAIABwAZmFrZS5leGVVVAkAA8YaglfGGoJXdXgLAAEE +6AMAAAToAwAAUEsBAh4DCgAAAAAAg17qSAAAAAAAAAAAAAAAAAgAGAAAAAAAAAAAALSBAAAAAGZh +a2UuZXhlVVQFAAPGGoJXdXgLAAEE6AMAAAToAwAAUEsFBgAAAAABAAEATgAAAEIAAAAAAA== +--=_MlaYox31rMNP821ZlG2h4Xe-- -- 2.39.5