commit eeb429b: [Test] Start tests for magic detection

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Sep 10 10:42:04 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-10 11:35:51 +0100
URL: https://github.com/rspamd/rspamd/commit/eeb429bf4d7929522b318bbdd73ff57934156433 (HEAD -> master)

[Test] Start tests for magic detection

---
 test/functional/cases/350_magic.robot  | 18 ++++++++++++++++++
 test/functional/lua/magic.lua          | 14 ++++++++++++++
 test/functional/messages/gargantua.eml | 22 ++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/test/functional/cases/350_magic.robot b/test/functional/cases/350_magic.robot
new file mode 100644
index 000000000..85893b23b
--- /dev/null
+++ b/test/functional/cases/350_magic.robot
@@ -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
index 000000000..c0d5793d4
--- /dev/null
+++ b/test/functional/lua/magic.lua
@@ -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
index 000000000..b8ca8f3f0
--- /dev/null
+++ b/test/functional/messages/gargantua.eml
@@ -0,0 +1,22 @@
+From: <user at 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


More information about the Commits mailing list