]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Some basic functional tests for mime_types module & archives 715/head
authorAndrew Lewis <nerf@judo.za.org>
Sun, 10 Jul 2016 11:39:33 +0000 (13:39 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Sun, 10 Jul 2016 11:39:33 +0000 (13:39 +0200)
 - Also some new features for Check Rspamc function
 - Run rspamd/rspamc with LD_LIBRARY_PATH

test/functional/cases/archives.robot [new file with mode: 0644]
test/functional/cases/statistics/lib.robot
test/functional/configs/plugins.conf [new file with mode: 0644]
test/functional/lib/rspamd.robot
test/functional/messages/rar4.eml [new file with mode: 0644]
test/functional/messages/zip-doublebad.eml [new file with mode: 0644]
test/functional/messages/zip.eml [new file with mode: 0644]

diff --git a/test/functional/cases/archives.robot b/test/functional/cases/archives.robot
new file mode 100644 (file)
index 0000000..c94de4e
--- /dev/null
@@ -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
index f710a87d5f16396d6b10dd63b167aa0dbe0e3591..387fa5ca874857723aec886f9d9f926b94b03216 100644 (file)
@@ -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 (file)
index 0000000..6eded73
--- /dev/null
@@ -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/"
+}
index ded537e037c2e16ef3371f9bb0d991c76db5da04..eb70d4c435c5295551a5607d22d614aac8c0e641 100644 (file)
@@ -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 (file)
index 0000000..61f6836
--- /dev/null
@@ -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 (file)
index 0000000..b8fbb41
--- /dev/null
@@ -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 (file)
index 0000000..dd6bc0b
--- /dev/null
@@ -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--