]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Test] Add functional tests for legacy protocol milter headers 5948/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 21 Mar 2026 12:12:10 +0000 (12:12 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 21 Mar 2026 12:12:10 +0000 (12:12 +0000)
Tests RSPAMC and SPAMC protocol output for:
- X-Milter-Add: lines (add headers)
- X-Milter-Del: lines (remove headers)
- X-Symbol: lines (extended symbol info with options)
- Backward compatibility of existing Symbol: lines

Also fix rspamc()/spamc() test helpers to read full response
instead of truncating at 2048 bytes.

test/functional/cases/551_legacy_milter_headers.robot [new file with mode: 0644]
test/functional/lib/rspamd.py

diff --git a/test/functional/cases/551_legacy_milter_headers.robot b/test/functional/cases/551_legacy_milter_headers.robot
new file mode 100644 (file)
index 0000000..16224d9
--- /dev/null
@@ -0,0 +1,59 @@
+*** Settings ***
+Suite Setup     Rspamd Setup
+Suite Teardown  Rspamd Teardown
+Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables       ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}             ${RSPAMD_TESTDIR}/configs/milter_headers.conf
+${MESSAGE}            ${RSPAMD_TESTDIR}/messages/zip.eml
+${RSPAMD_SCOPE}       Suite
+${RSPAMD_URL_TLD}     ${RSPAMD_TESTDIR}/../lua/unit/test_tld.dat
+
+*** Test Cases ***
+RSPAMC PROTOCOL STATUS LINE
+  [Documentation]  Verify RSPAMC response has correct status line and basic structure
+  ${result} =  Rspamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Contain  ${result}  RSPAMD/1.3 0 EX_OK
+  Should Contain  ${result}  Metric: default;
+
+RSPAMC BACKWARD COMPATIBLE SYMBOLS
+  [Documentation]  Existing Symbol: lines must be preserved
+  ${result} =  Rspamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  Symbol: SIMPLE_TEST\\(\\d+\\.\\d+\\)
+
+RSPAMC EXTENDED SYMBOLS
+  [Documentation]  X-Symbol: lines with options from symbol callbacks
+  ${result} =  Rspamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  X-Symbol: SIMPLE_TEST\\(\\d+\\.\\d+\\).*\\[Fires always\\]
+
+RSPAMC MILTER ADD HEADERS
+  [Documentation]  X-Milter-Add: lines for milter add_headers
+  ${result} =  Rspamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  X-Milter-Add: X-Virus:
+  Should Match Regexp  ${result}  X-Milter-Add: My-Spamd-Bar:
+  Should Match Regexp  ${result}  X-Milter-Add: X-Spam-Level:
+
+RSPAMC MILTER DEL HEADERS
+  [Documentation]  X-Milter-Del: lines for milter remove_headers
+  ${result} =  Rspamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  X-Milter-Del: X-Spam-Level
+  Should Match Regexp  ${result}  X-Milter-Del: X-Virus
+
+SPAMC PROTOCOL STATUS LINE
+  [Documentation]  Verify SPAMC response has correct status line
+  ${result} =  Spamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Contain  ${result}  SPAMD/1.1 0 EX_OK
+
+SPAMC MILTER ADD HEADERS
+  [Documentation]  X-Milter-Add: lines in SPAMC protocol output
+  ${result} =  Spamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  X-Milter-Add: X-Virus:
+  Should Match Regexp  ${result}  X-Milter-Add: My-Spamd-Bar:
+
+SPAMC MILTER DEL HEADERS
+  [Documentation]  X-Milter-Del: lines in SPAMC protocol output
+  ${result} =  Spamc  ${RSPAMD_LOCAL_ADDR}  ${RSPAMD_PORT_NORMAL}  ${MESSAGE}
+  Should Match Regexp  ${result}  X-Milter-Del: X-Spam-Level
+  Should Match Regexp  ${result}  X-Milter-Del: X-Virus
index f692089313494def9d30c17aea31e05315ecd204..a974bbb34d72fdda27200eee0aed949edb29879d 100644 (file)
@@ -256,8 +256,14 @@ def rspamc(addr, port, filename):
     s.send(b"\r\n\r\n")
     s.send(mboxgoo)
     s.send(goo)
-    r = s.recv(2048)
-    return r.decode('utf-8')
+    data = b""
+    while True:
+        chunk = s.recv(32768)
+        if not chunk:
+            break
+        data += chunk
+    s.close()
+    return data.decode('utf-8')
 
 
 def Scan_File(filename, **headers):
@@ -511,8 +517,14 @@ def spamc(addr, port, filename):
     s.send(b"\r\n\r\n")
     s.send(goo)
     s.shutdown(socket.SHUT_WR)
-    r = s.recv(2048)
-    return r.decode('utf-8')
+    data = b""
+    while True:
+        chunk = s.recv(32768)
+        if not chunk:
+            break
+        data += chunk
+    s.close()
+    return data.decode('utf-8')
 
 
 def TCP_Connect(addr, port):