commit e481f85: [Test] Add task:get_from(['mime']) test

Alexander Moisseev moiseev at mezonplus.ru
Thu Jan 17 14:00:03 UTC 2019


Author: Alexander Moisseev
Date: 2019-01-16 15:07:34 +0300
URL: https://github.com/rspamd/rspamd/commit/e481f8514ade0e8a3a5750c22c1fda9cffaea3fe (refs/pull/2715/head)

[Test] Add task:get_from(['mime']) test

---
 test/functional/cases/104_get_from.robot           | 53 ++++++++++++++++++++++
 test/functional/configs/lua_script.conf            | 25 ++++++++++
 test/functional/lua/get_from.lua                   |  8 ++++
 test/functional/messages/from/from.eml             |  2 +
 test/functional/messages/from/from_comment.eml     |  2 +
 test/functional/messages/from/from_dn.eml          |  2 +
 test/functional/messages/from/from_dn_base64.eml   |  2 +
 test/functional/messages/from/from_dn_comment.eml  |  2 +
 test/functional/messages/from/from_quoted_dn.eml   |  2 +
 .../messages/from/from_quoted_dn_comment.eml       |  2 +
 .../messages/from/from_quoted_dn_middle.eml        |  2 +
 .../messages/from/from_quoted_dn_middle_inner.eml  |  2 +
 12 files changed, 104 insertions(+)

diff --git a/test/functional/cases/104_get_from.robot b/test/functional/cases/104_get_from.robot
new file mode 100644
index 000000000..a81dec559
--- /dev/null
+++ b/test/functional/cases/104_get_from.robot
@@ -0,0 +1,53 @@
+*** 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/get_from.lua
+${RSPAMD_SCOPE}  Suite
+
+${SYMBOL}   GET_FROM (0.00)
+${SYMBOL1}  ${SYMBOL}[,user at example.org,user,example.org]
+${SYMBOL2}  ${SYMBOL}[First Last,user at example.org,user,example.org]
+${SYMBOL3}  ${SYMBOL}[First M. Last,user at example.org,user,example.org]
+
+*** Test Cases ***
+task:get_from('mime') - address only
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from.eml
+  Check Rspamc  ${result}  ${SYMBOL1}
+
+task:get_from('mime') - comment
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_comment.eml
+  Check Rspamc  ${result}  ${SYMBOL1}
+
+task:get_from('mime') - display name
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_dn.eml
+  Check Rspamc  ${result}  ${SYMBOL2}
+
+task:get_from('mime') - display name Base64
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_dn_base64.eml
+  Check Rspamc  ${result}  ${SYMBOL}[Кириллица,user at example.org,user,example.org]
+
+task:get_from('mime') - display name and comment
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_dn_comment.eml
+  Check Rspamc  ${result}  ${SYMBOL2}
+
+task:get_from('mime') - quoted display name
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_quoted_dn.eml
+  Check Rspamc  ${result}  ${SYMBOL3}
+
+task:get_from('mime') - quoted display name and comment
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_quoted_dn_comment.eml
+  Check Rspamc  ${result}  ${SYMBOL3}
+
+task:get_from('mime') - quoted in the middle of DN (outer spaces)
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_quoted_dn_middle.eml
+  Check Rspamc  ${result}  ${SYMBOL3}
+
+task:get_from('mime') - quoted in the middle of DN (inner spaces)
+  ${result} =  Scan Message With Rspamc  ${TESTDIR}/messages/from/from_quoted_dn_middle_inner.eml
+  Check Rspamc  ${result}  ${SYMBOL3}
diff --git a/test/functional/configs/lua_script.conf b/test/functional/configs/lua_script.conf
new file mode 100644
index 000000000..2bde672fe
--- /dev/null
+++ b/test/functional/configs/lua_script.conf
@@ -0,0 +1,25 @@
+options = {
+    pidfile = "${TMPDIR}/rspamd.pid"
+}
+logging = {
+    type = "file",
+    level = "debug"
+    filename = "${TMPDIR}/rspamd.log"
+}
+
+worker {
+    type = normal
+    bind_socket = ${LOCAL_ADDR}:${PORT_NORMAL}
+    count = 1
+    task_timeout = 60s;
+}
+worker {
+    type = controller
+    bind_socket = ${LOCAL_ADDR}:${PORT_CONTROLLER}
+    count = 1
+    secure_ip = ["127.0.0.1", "::1"];
+    stats_path = "${TMPDIR}/stats.ucl"
+}
+
+lua = "${TESTDIR}/lua/test_coverage.lua";
+lua = ${LUA_SCRIPT};
diff --git a/test/functional/lua/get_from.lua b/test/functional/lua/get_from.lua
new file mode 100644
index 000000000..4e3267b41
--- /dev/null
+++ b/test/functional/lua/get_from.lua
@@ -0,0 +1,8 @@
+rspamd_config:register_symbol({
+  name = 'SIMPLE_TEST',
+  score = 1.0,
+  callback = function(task)
+    local a = task:get_from('mime')[1]
+    task:insert_result('GET_FROM', 0.0, a.name .. ',' .. a.addr .. ',' .. a.user .. ',' .. a.domain)
+  end
+})
diff --git a/test/functional/messages/from/from.eml b/test/functional/messages/from/from.eml
new file mode 100644
index 000000000..20c2b1bd8
--- /dev/null
+++ b/test/functional/messages/from/from.eml
@@ -0,0 +1,2 @@
+From: user at example.org
+
diff --git a/test/functional/messages/from/from_comment.eml b/test/functional/messages/from/from_comment.eml
new file mode 100644
index 000000000..235ccf1e9
--- /dev/null
+++ b/test/functional/messages/from/from_comment.eml
@@ -0,0 +1,2 @@
+From: user at example.org (Comment text)
+
diff --git a/test/functional/messages/from/from_dn.eml b/test/functional/messages/from/from_dn.eml
new file mode 100644
index 000000000..fd714c2b3
--- /dev/null
+++ b/test/functional/messages/from/from_dn.eml
@@ -0,0 +1,2 @@
+From: First Last <user at example.org>
+
diff --git a/test/functional/messages/from/from_dn_base64.eml b/test/functional/messages/from/from_dn_base64.eml
new file mode 100644
index 000000000..e4fdbf2cf
--- /dev/null
+++ b/test/functional/messages/from/from_dn_base64.eml
@@ -0,0 +1,2 @@
+From: =?UTF-8?B?0JrQuNGA0LjQu9C70LjRhtCw?= <user at example.org>
+
diff --git a/test/functional/messages/from/from_dn_comment.eml b/test/functional/messages/from/from_dn_comment.eml
new file mode 100644
index 000000000..5f8b339d4
--- /dev/null
+++ b/test/functional/messages/from/from_dn_comment.eml
@@ -0,0 +1,2 @@
+From: First Last <user at example.org> (Comment text)
+
diff --git a/test/functional/messages/from/from_quoted_dn.eml b/test/functional/messages/from/from_quoted_dn.eml
new file mode 100644
index 000000000..8e0d01ef2
--- /dev/null
+++ b/test/functional/messages/from/from_quoted_dn.eml
@@ -0,0 +1,2 @@
+From: "First M. Last" <user at example.org>
+
diff --git a/test/functional/messages/from/from_quoted_dn_comment.eml b/test/functional/messages/from/from_quoted_dn_comment.eml
new file mode 100644
index 000000000..eddba68f4
--- /dev/null
+++ b/test/functional/messages/from/from_quoted_dn_comment.eml
@@ -0,0 +1,2 @@
+From: "First M. Last" <user at example.org> (Comment text)
+
diff --git a/test/functional/messages/from/from_quoted_dn_middle.eml b/test/functional/messages/from/from_quoted_dn_middle.eml
new file mode 100644
index 000000000..98ddac4ce
--- /dev/null
+++ b/test/functional/messages/from/from_quoted_dn_middle.eml
@@ -0,0 +1,2 @@
+From: First "M." Last <user at example.org>
+
diff --git a/test/functional/messages/from/from_quoted_dn_middle_inner.eml b/test/functional/messages/from/from_quoted_dn_middle_inner.eml
new file mode 100644
index 000000000..4e7f3630f
--- /dev/null
+++ b/test/functional/messages/from/from_quoted_dn_middle_inner.eml
@@ -0,0 +1,2 @@
+From: First" M. "Last <user at example.org>
+


More information about the Commits mailing list