commit 5367d1e: [Test] Fix tests

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Nov 27 15:00:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-11-27 14:57:35 +0000
URL: https://github.com/rspamd/rspamd/commit/5367d1ed1e71a0c5011e7f366de7c466b2b8e1e6 (HEAD -> master)

[Test] Fix tests

---
 test/lua/unit/lua_mime.message_to_ucl.lua | 197 +++++++++++++++---------------
 1 file changed, 100 insertions(+), 97 deletions(-)

diff --git a/test/lua/unit/lua_mime.message_to_ucl.lua b/test/lua/unit/lua_mime.message_to_ucl.lua
index c97f38724..27bf24d5a 100644
--- a/test/lua/unit/lua_mime.message_to_ucl.lua
+++ b/test/lua/unit/lua_mime.message_to_ucl.lua
@@ -33,6 +33,7 @@ context("Task piecewise split", function()
   local rspamd_test_helper = require "rspamd_test_helper"
   local lua_mime = require "lua_mime"
   local ucl = require "ucl"
+  local rspamd_parsers = require "rspamd_parsers"
 
   rspamd_test_helper.init_url_parser()
   local cfg = rspamd_util.config_from_ucl(rspamd_test_helper.default_config(),
@@ -45,6 +46,11 @@ context("Task piecewise split", function()
       assert_true(false, "failed to load message")
     end
 
+    task:set_from('smtp', rspamd_parsers.parse_mail_address("Test <test at example.com>")[1])
+    task:set_recipients('smtp', {
+      rspamd_parsers.parse_mail_address("Test1 <test1 at example.com>")[1],
+      rspamd_parsers.parse_mail_address("Test2 <test2 at example.com>")[1]
+    }, 'rewrite')
     task:process_message()
 
     local expected_json = [[
@@ -57,30 +63,26 @@ context("Task piecewise split", function()
             "boundary": "_000_6be055295eab48a5af7ad4022f33e2d0_",
             "detected_type": "text/plain",
             "headers": [
-                [
-                    {
-                        "order": 0,
-                        "raw": "Content-Type: text/plain; charset=\"utf-8\"\n",
-                        "empty_separator": false,
-                        "value": "text/plain; charset=\"utf-8\"",
-                        "separator": " ",
-                        "decoded": "text/plain; charset=\"utf-8\"",
-                        "name": "Content-Type",
-                        "tab_separated": false
-                    }
-                ],
-                [
-                    {
-                        "order": 1,
-                        "raw": "Content-Transfer-Encoding: 7bit\n",
-                        "empty_separator": false,
-                        "value": "7bit",
-                        "separator": " ",
-                        "decoded": "7bit",
-                        "name": "Content-Transfer-Encoding",
-                        "tab_separated": false
-                    }
-                ]
+                {
+                    "order": 0,
+                    "raw": "Content-Type: text/plain; charset=\"utf-8\"\n",
+                    "empty_separator": false,
+                    "value": "text/plain; charset=\"utf-8\"",
+                    "separator": " ",
+                    "decoded": "text/plain; charset=\"utf-8\"",
+                    "name": "Content-Type",
+                    "tab_separated": false
+                },
+                {
+                    "order": 1,
+                    "raw": "Content-Transfer-Encoding: 7bit\n",
+                    "empty_separator": false,
+                    "value": "7bit",
+                    "separator": " ",
+                    "decoded": "7bit",
+                    "name": "Content-Transfer-Encoding",
+                    "tab_separated": false
+                }
             ]
         },
         {
@@ -90,86 +92,85 @@ context("Task piecewise split", function()
             "boundary": "_000_6be055295eab48a5af7ad4022f33e2d0_",
             "detected_type": "text/html",
             "headers": [
-                [
-                    {
-                        "order": 0,
-                        "raw": "Content-Type: text/html; charset=\"utf-8\"\n",
-                        "empty_separator": false,
-                        "value": "text/html; charset=\"utf-8\"",
-                        "separator": " ",
-                        "decoded": "text/html; charset=\"utf-8\"",
-                        "name": "Content-Type",
-                        "tab_separated": false
-                    }
-                ]
+                {
+                    "order": 0,
+                    "raw": "Content-Type: text/html; charset=\"utf-8\"\n",
+                    "empty_separator": false,
+                    "value": "text/html; charset=\"utf-8\"",
+                    "separator": " ",
+                    "decoded": "text/html; charset=\"utf-8\"",
+                    "name": "Content-Type",
+                    "tab_separated": false
+                }
             ]
         }
     ],
     "newlines": "lf",
     "digest": "043cf1a314d0a1af95951d6aec932faf",
-    "envelope": [],
+    "envelope": {
+        "from_smtp": {
+            "addr": "test at example.com",
+            "raw": "<test at example.com>",
+            "flags": {
+                "valid": true
+            },
+            "user": "test",
+            "name": "Test",
+            "domain": "example.com"
+        }
+    },
     "size": 666,
     "headers": [
-        [
-            {
-                "order": 0,
-                "raw": "Received: from mail0.mindspring.com (unknown [1.1.1.1])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby mail.example.com (Postfix) with ESMTPS id 88A0C6B332\n\tfor <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)\n",
-                "empty_separator": false,
-                "value": "from mail0.mindspring.com (unknown [1.1.1.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPS id 88A0C6B332 for <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)",
-                "separator": " ",
-                "decoded": "from mail0.mindspring.com (unknown [1.1.1.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPS id 88A0C6B332 for <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)",
-                "name": "Received",
-                "tab_separated": false
-            }
-        ],
-        [
-            {
-                "order": 1,
-                "raw": "From: <>\n",
-                "empty_separator": false,
-                "value": "<>",
-                "separator": " ",
-                "decoded": "<>",
-                "name": "From",
-                "tab_separated": false
-            }
-        ],
-        [
-            {
-                "order": 2,
-                "raw": "To: <nobody at example.com>\n",
-                "empty_separator": false,
-                "value": "<nobody at example.com>",
-                "separator": " ",
-                "decoded": "<nobody at example.com>",
-                "name": "To",
-                "tab_separated": false
-            }
-        ],
-        [
-            {
-                "order": 3,
-                "raw": "Subject: test\n",
-                "empty_separator": false,
-                "value": "test",
-                "separator": " ",
-                "decoded": "test",
-                "name": "Subject",
-                "tab_separated": false
-            }
-        ],
-        [
-            {
-                "order": 4,
-                "raw": "Content-Type: multipart/alternative;\n    boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"\n",
-                "empty_separator": false,
-                "value": "multipart/alternative; boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"",
-                "separator": " ",
-                "decoded": "multipart/alternative; boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"",
-                "name": "Content-Type",
-                "tab_separated": false
-            }
-        ]
+        {
+            "order": 0,
+            "raw": "Received: from mail0.mindspring.com (unknown [1.1.1.1])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby mail.example.com (Postfix) with ESMTPS id 88A0C6B332\n\tfor <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)\n",
+            "empty_separator": false,
+            "value": "from mail0.mindspring.com (unknown [1.1.1.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPS id 88A0C6B332 for <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)",
+            "separator": " ",
+            "decoded": "from mail0.mindspring.com (unknown [1.1.1.1]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.com (Postfix) with ESMTPS id 88A0C6B332 for <example at example.com>; Wed, 24 Nov 2021 19:05:43 +0000 (GMT)",
+            "name": "Received",
+            "tab_separated": false
+        },
+        {
+            "order": 1,
+            "raw": "From: <>\n",
+            "empty_separator": false,
+            "value": "<>",
+            "separator": " ",
+            "decoded": "<>",
+            "name": "From",
+            "tab_separated": false
+        },
+        {
+            "order": 2,
+            "raw": "To: <nobody at example.com>\n",
+            "empty_separator": false,
+            "value": "<nobody at example.com>",
+            "separator": " ",
+            "decoded": "<nobody at example.com>",
+            "name": "To",
+            "tab_separated": false
+        },
+        {
+            "order": 3,
+            "raw": "Subject: test\n",
+            "empty_separator": false,
+            "value": "test",
+            "separator": " ",
+            "decoded": "test",
+            "name": "Subject",
+            "tab_separated": false
+        },
+        {
+            "order": 4,
+            "raw": "Content-Type: multipart/alternative;\n    boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"\n",
+            "empty_separator": false,
+            "value": "multipart/alternative; boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"",
+            "separator": " ",
+            "decoded": "multipart/alternative; boundary=\"_000_6be055295eab48a5af7ad4022f33e2d0_\"",
+            "name": "Content-Type",
+            "tab_separated": false
+        }
     ]
 }
 ]]
@@ -178,6 +179,8 @@ context("Task piecewise split", function()
     assert_true(res)
     local expected = parser:get_object()
     local ucl_object = lua_mime.message_to_ucl(task, true)
+    local schema = lua_mime.message_to_ucl_schema()
+    assert_true(schema(ucl_object))
     assert_rspamd_table_eq({
       actual = ucl_object,
       expect = expected


More information about the Commits mailing list