]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Start tests for magic detection
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Sep 2019 10:35:51 +0000 (11:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Sep 2019 10:35:51 +0000 (11:35 +0100)
test/functional/cases/350_magic.robot [new file with mode: 0644]
test/functional/lua/magic.lua [new file with mode: 0644]
test/functional/messages/gargantua.eml [new file with mode: 0644]

diff --git a/test/functional/cases/350_magic.robot b/test/functional/cases/350_magic.robot
new file mode 100644 (file)
index 0000000..85893b2
--- /dev/null
@@ -0,0 +1,18 @@
+*** Settings ***
+Suite Setup     Generic Setup
+Suite Teardown  Simple Teardown
+Library         ${TESTDIR}/lib/rspamd.py
+Resource        ${TESTDIR}/lib/rspamd.robot
+Variables       ${TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}       ${TESTDIR}/configs/lua_script.conf
+${LUA_SCRIPT}   ${TESTDIR}/lua/magic.lua
+${RSPAMD_SCOPE}  Suite
+${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
+
+*** Test Cases ***
+Magic detections bundle 1
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/gargantua.eml
+  Should Contain  ${result.stdout}  MAGIC_SYM_ZIP_2
+  Should Contain  ${result.stdout}  MAGIC_SYM_RAR_3
\ No newline at end of file
diff --git a/test/functional/lua/magic.lua b/test/functional/lua/magic.lua
new file mode 100644 (file)
index 0000000..c0d5793
--- /dev/null
@@ -0,0 +1,14 @@
+rspamd_config.MAGIC_SYM = {
+  callback = function(task)
+    local parts = task:get_parts()
+
+    for i,p in ipairs(parts) do
+      local ext = p:get_detected_ext()
+
+      if ext then
+        task:insert_result('MAGIC_SYM_' .. ext:upper() .. '_' .. tostring(i), 1.0)
+      end
+    end
+  end,
+  type = 'callback'
+}
\ No newline at end of file
diff --git a/test/functional/messages/gargantua.eml b/test/functional/messages/gargantua.eml
new file mode 100644 (file)
index 0000000..b8ca8f3
--- /dev/null
@@ -0,0 +1,22 @@
+From: <user@example.com>
+To: undisclosed-recipients:;
+Content-Type: multipart/mixed; boundary=XXX
+
+--XXX
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: base64
+
+UEsDBBQDAAAAADxGUzwAAAAAAAAAAAAAAAACAAAAdC9QSwMECgMAAAAAHUZTPIiw
+JDICAAAAAgAAAAcAAAB0L3QudHh0NDJQSwECPwMUAwAAAAA8RlM8AAAAAAAAAAAA
+AAAAAgAAAAAAAAAAABCA6EEAAAAAdC9QSwECPwMKAwAAAAAdRlM8iLAkMgIAAAAC
+AAAABwAAAAAAAAAAACCAoIEgAAAAdC90LnR4dFBLBQYAAAAAAgACAGUAAABHAAAA
+AAA=
+
+--XXX
+Content-Type: application/octet-stream
+Content-Transfer-Encoding: base64
+
+UmFyIRoHAM+QcwAADQAAAAAAAABs53QggCcACwAAAAIAAAADiLAkMh0+UzwdMwcA
+oIEAAHRcdC50eHQRC/TEnu9/Np/2WmMfdOCAIQAAAAAAAAAAAAMAAAAAPD5TPBQw
+AQDoQQAAdMQ9ewBABwA=
+--XXX--
\ No newline at end of file