commit 161184e: add tests for dkim signatures with milter

John McKay adenosine3p at gmail.com
Mon Feb 4 14:35:22 UTC 2019


Author: John McKay
Date: 2019-02-02 11:26:14 +0000
URL: https://github.com/rspamd/rspamd/commit/161184eb72bd570e7002d15a689f2dac56392d21 (refs/pull/2739/head)

add tests for dkim signatures with milter

---
 .../006_milter.robot}                              | 23 +++++------------
 .../configs/{ => dkim_signing}/milter.conf         | 30 +++++++++++++++++-----
 test/functional/lua/miltertest/data_dkim.lua       | 23 +++++++++++++++++
 test/functional/lua/miltertest/dkim_many.lua       | 11 ++++++++
 test/functional/lua/miltertest/dkim_one.lua        | 11 ++++++++
 test/functional/lua/miltertest/lib.lua             |  9 +++++++
 6 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/test/functional/cases/180_milter.robot b/test/functional/cases/131_dkim_signing/006_milter.robot
similarity index 72%
copy from test/functional/cases/180_milter.robot
copy to test/functional/cases/131_dkim_signing/006_milter.robot
index 23a366814..fa6f532b4 100644
--- a/test/functional/cases/180_milter.robot
+++ b/test/functional/cases/131_dkim_signing/006_milter.robot
@@ -1,5 +1,5 @@
 *** Settings ***
-Suite Setup     Milter Setup
+Suite Setup     DKIM Milter Setup
 Suite Teardown  Generic Teardown
 Library         Process
 Library         ${TESTDIR}/lib/rspamd.py
@@ -11,24 +11,15 @@ ${RSPAMD_SCOPE}  Suite
 ${URL_TLD}      ${TESTDIR}/../lua/unit/test_tld.dat
 
 *** Test Cases ***
-ACCEPT
-  Milter Test  mt1.lua
+SINGLE SIGNATURE
+  Milter Test  dkim_one.lua
 
-REJECT
-  Milter Test  mt2.lua
-
-REWRITE SUBJECT
-  Milter Test  mt3.lua
-
-DEFER
-  Milter Test  mt4.lua
-
-COMBINED TEST
-  Milter Test  combined.lua
+MULTIPLE SIGNATURES
+  Milter Test  dkim_many.lua
 
 *** Keywords ***
-Milter Setup
-  Generic Setup  CONFIG=${TESTDIR}/configs/milter.conf
+DKIM Milter Setup
+  Generic Setup  CONFIG=${TESTDIR}/configs/dkim_signing/milter.conf
 
 Milter Test
   [Arguments]  ${mtlua}
diff --git a/test/functional/configs/milter.conf b/test/functional/configs/dkim_signing/milter.conf
similarity index 66%
copy from test/functional/configs/milter.conf
copy to test/functional/configs/dkim_signing/milter.conf
index 789040e68..263ed0b4e 100644
--- a/test/functional/configs/milter.conf
+++ b/test/functional/configs/dkim_signing/milter.conf
@@ -1,5 +1,5 @@
 options = {
-	filters = ["spf", "dkim", "regexp"]
+	filters = ["dkim"]
 	url_tld = "${URL_TLD}"
 	pidfile = "${TMPDIR}/rspamd.pid"
 	lua_path = "${INSTALLROOT}/share/rspamd/lib/?.lua"
@@ -47,14 +47,30 @@ worker {
 	bind_socket = "${LOCAL_ADDR}:${PORT_PROXY}";
 	milter = true;
 }
+dkim_signing {
+  domain {
+    cacophony.za.org {
+      selectors = {
+        path: "${TESTDIR}/configs/dkim.key";
+        selector: "dkim";
+      }
+      selectors = {
+        path: "${TESTDIR}/configs/dkim-eddsa.key";
+        selector: "eddsa";
+     }
+   }
+    invalid.za.org {
+      selectors = [ 
+        { path: "${TESTDIR}/configs/dkim-eddsa.key";
+          selector: "eddsa"; }
+      ]
+   }
+  }
+  allow_pubkey_mismatch: true;
+}
 modules {
-    path = "${TESTDIR}/../../src/plugins/lua/"
+    path = "${TESTDIR}/../../src/plugins/lua/dkim_signing.lua"
 }
 lua = "${TESTDIR}/lua/test_coverage.lua";
 lua = "${INSTALLROOT}/share/rspamd/rules/rspamd.lua"
 lua = "${TESTDIR}/lua/params.lua"
-milter_headers {
-	extended_spam_headers = true;
-	skip_local = false;
-	skip_authenticated = false;
-}
diff --git a/test/functional/lua/miltertest/data_dkim.lua b/test/functional/lua/miltertest/data_dkim.lua
new file mode 100644
index 000000000..15adf15ec
--- /dev/null
+++ b/test/functional/lua/miltertest/data_dkim.lua
@@ -0,0 +1,23 @@
+multi_hdrs = {
+  ['Message-ID'] = '<a44q4StVFY04V4_4gOMYXjTgMDvmlSFzZxnoyJPHFwM at cacophony.za.org>',
+  ['From'] = 'Rspamd <foo at cacophony.za.org>',
+  ['To'] = 'nerf at example.org',
+  ['Subject'] = 'dkim test message',
+  ['User-Agent'] = 'Vi IMproved 8.1',
+  ['Content-Type'] = 'text/plain; charset=utf-8;',
+  ['MIME-Version'] = '1.0',
+  ['Date'] = 'Sat, 02 Feb 2019 10:34:54 +0000',
+}
+
+single_hdr = {
+  ['Message-ID'] = '<a44q4StVFY04V4_4gOMYXjTgMDvmlSFzZxnoyJPHFwM at cacophony.za.org>',
+  ['From'] = 'Rspamd <foo at invalid.za.org>',
+  ['To'] = 'nerf at example.org',
+  ['Subject'] = 'dkim test message',
+  ['User-Agent'] = 'Vi IMproved 8.1',
+  ['Content-Type'] = 'text/plain; charset=utf-8;',
+  ['MIME-Version'] = '1.0',
+  ['Date'] = 'Sat, 02 Feb 2019 10:34:54 +0000',
+}
+
+innocuous_msg = 'hello'
diff --git a/test/functional/lua/miltertest/dkim_many.lua b/test/functional/lua/miltertest/dkim_many.lua
new file mode 100644
index 000000000..70a3a1be6
--- /dev/null
+++ b/test/functional/lua/miltertest/dkim_many.lua
@@ -0,0 +1,11 @@
+print('Check we get multiple dkim signatures')
+
+dofile './lib.lua'
+dofile './data_dkim.lua'
+
+setup()
+
+send_message(innocuous_msg, multi_hdrs, 'test-id', 'foo at cacophony.za.org', {'nerf at example.org'})
+check_headers(2)
+
+teardown()
diff --git a/test/functional/lua/miltertest/dkim_one.lua b/test/functional/lua/miltertest/dkim_one.lua
new file mode 100644
index 000000000..0c7def8b9
--- /dev/null
+++ b/test/functional/lua/miltertest/dkim_one.lua
@@ -0,0 +1,11 @@
+print('Check we get single dkim signature')
+
+dofile './lib.lua'
+dofile './data_dkim.lua'
+
+setup()
+
+send_message(innocuous_msg, single_hdr, 'test-id', 'foo at invalid.za.org', {'nerf at example.org'})
+check_headers(1)
+
+teardown()
diff --git a/test/functional/lua/miltertest/lib.lua b/test/functional/lua/miltertest/lib.lua
index e94efd559..44dc76ea5 100644
--- a/test/functional/lua/miltertest/lib.lua
+++ b/test/functional/lua/miltertest/lib.lua
@@ -108,3 +108,12 @@ function check_subject_rw(subj, tmpl)
     error "subject not rewritten"
   end
 end
+
+function check_headers(count)
+  for i=0, count-1 do
+    local hdr = mt.getheader(conn, "DKIM-Signature", i)
+    if not hdr then
+      error (string.format("Signature %s not added", i))
+    end
+  end
+end


More information about the Commits mailing list