diff --git a/README.md b/README.md index 63fa207..ff5d396 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ smf-spf [![Build Status](https://travis-ci.org/jcbf/smf-spf.svg?branch=master)](https://travis-ci.org/jcbf/smf-spf) [![Stories in Ready](https://badge.waffle.io/jcbf/smf-spf.svg?label=ready&title=Ready)](http://waffle.io/jcbf/smf-spf) +[![Coverage Status](https://coveralls.io/repos/github/jcbf/smf-spf/badge.svg?branch=master)](https://coveralls.io/github/jcbf/smf-spf?branch=master) It's a lightweight, fast and reliable Sendmail milter that implements the Sender Policy Framework This was abandoned code and has several bugfixes and enhancements. - [Full Changelog since initial import](https://github.com/jcbf/smf-spf/compare/0bc5e609bd5cfe9a459c265e561a9e81888d237c...HEAD) diff --git a/tests/02-host-whitelisted.lua b/tests/02-host-whitelisted.lua index 739a417..1ed2b3a 100644 --- a/tests/02-host-whitelisted.lua +++ b/tests/02-host-whitelisted.lua @@ -12,7 +12,7 @@ end -- send connection information mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "server.example.org", "10.0.0.1") ~= nil then +if mt.conninfo(conn, "server.example.org", "2001:0101:DEAD:BEEF::1") ~= nil then error("mt.conninfo() failed") end diff --git a/tests/04-fulltest-neutral.lua b/tests/04-fulltest-neutral.lua index 2c50bd5..ad27368 100644 --- a/tests/04-fulltest-neutral.lua +++ b/tests/04-fulltest-neutral.lua @@ -61,6 +61,7 @@ if mt.eom_check(conn, MT_HDRINSERT, "Authentication-Results") or mt.eom_check(conn, MT_HDRADD, "Authentication-Results") then ar = mt.getheader(conn, "Authentication-Results", 0) if string.find(ar, "spf=none", 1, true) == nil then + mt.echo ("Got header Authentication-Results: " .. ar) error("incorrect Authentication-Results field") else mt.echo("SPF neutral ") diff --git a/tests/04-fulltest-refusefail.lua b/tests/04-fulltest-refusefail.lua index 12ea233..a3e14c8 100644 --- a/tests/04-fulltest-refusefail.lua +++ b/tests/04-fulltest-refusefail.lua @@ -2,7 +2,7 @@ mt.echo("SPF pass test") -- try to start the filter -mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests.conf") +mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-refuse.conf") -- try to connect to it conn = mt.connect("inet:2424@127.0.0.1", 40, 0.25) diff --git a/tests/04-fulltest-soft.lua b/tests/04-fulltest-soft.lua index 668b739..a0b18a8 100644 --- a/tests/04-fulltest-soft.lua +++ b/tests/04-fulltest-soft.lua @@ -61,6 +61,7 @@ if mt.eom_check(conn, MT_HDRINSERT, "Authentication-Results") or mt.eom_check(conn, MT_HDRADD, "Authentication-Results") then ar = mt.getheader(conn, "Authentication-Results", 0) if string.find(ar, "spf=none", 1, true) == nil then + mt.echo ("Got header Authentication-Results: " .. ar) error("incorrect Authentication-Results field") else mt.echo("SPF softfail ") diff --git a/tests/04-helo-pass.lua b/tests/04-helo-pass.lua new file mode 100644 index 0000000..9e7c9a3 --- /dev/null +++ b/tests/04-helo-pass.lua @@ -0,0 +1,79 @@ +-- Copyright (c) 2009-2013, The Trusted Domain Project. All rights reserved. +mt.echo("SPF helo pass test") + +-- try to start the filter +mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests.conf") + +-- try to connect to it +conn = mt.connect("inet:2424@127.0.0.1", 40, 0.25) +if conn == nil then + error("mt.connect() failed") +end + +-- send connection information +-- mt.negotiate() is called implicitly +mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") +if mt.conninfo(conn, "helo.underspell.com","10.11.12.13") ~= nil then + error("mt.conninfo() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.conninfo() unexpected reply") +end + +if mt.helo(conn, "helo.underspell.com") ~= nil then + error("mt.helo() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.helo() unexpected reply") +end + +-- send envelope macros and sender data +-- mt.helo() is called implicitly +mt.macro(conn, SMFIC_MAIL, "i", "t-empty-sender") +if mt.mailfrom(conn, "<>") ~= nil then + error("mt.mailfrom() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.mailfrom() unexpected reply") +end + +-- send headers +-- mt.rcptto() is called implicitly +if mt.header(conn, "From", "user") ~= nil then + error("mt.header(From) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(From) unexpected reply") +end +if mt.header(conn, "Date", "Tue, 22 Dec 2009 13:04:12 -0800") ~= nil then + error("mt.header(Date) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Date) unexpected reply") +end +if mt.header(conn, "Subject", "Signing test") ~= nil then + error("mt.header(Subject) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Subject) unexpected reply") +end + +-- end of message; let the filter react +if mt.eom(conn) ~= nil then + error("mt.eom() failed") +end + +-- verify that the right Authentication-Results header field got added +if mt.eom_check(conn, MT_HDRINSERT, "Authentication-Results") or + mt.eom_check(conn, MT_HDRADD, "Authentication-Results") then + ar = mt.getheader(conn, "Authentication-Results", 0) + if string.find(ar, "spf=pass", 1, true) == nil then + error("incorrect Authentication-Results field") + else + mt.echo("SPF pass ") + end +else + error("missing Authentication-Results field") +end + +mt.disconnect(conn) diff --git a/tests/05-cache-test-fail.lua b/tests/05-cache-test-fail.lua new file mode 100644 index 0000000..aaa7be5 --- /dev/null +++ b/tests/05-cache-test-fail.lua @@ -0,0 +1,142 @@ + +mt.echo("Cached SPF fail test") + +-- try to start the filter +mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests.conf") + +-- try to connect to it +conn = mt.connect("inet:2424@127.0.0.1", 40, 0.25) +if conn == nil then + error("mt.connect() failed") +end + +-- send connection information +-- mt.negotiate() is called implicitly +mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") +if mt.conninfo(conn, "localhost", "10.11.12.13") ~= nil then + error("mt.conninfo() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.conninfo() unexpected reply") +end + +-- send envelope macros and sender data +-- mt.helo() is called implicitly +mt.macro(conn, SMFIC_MAIL, "i", "t-verify-malformed") +if mt.mailfrom(conn, "") ~= nil then + error("mt.mailfrom() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.mailfrom() unexpected reply") +end + +-- send headers +-- mt.rcptto() is called implicitly +if mt.header(conn, "From", "user") ~= nil then + error("mt.header(From) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(From) unexpected reply") +end +if mt.header(conn, "Date", "Tue, 22 Dec 2009 13:04:12 -0800") ~= nil then + error("mt.header(Date) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Date) unexpected reply") +end +if mt.header(conn, "Subject", "Signing test") ~= nil then + error("mt.header(Subject) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Subject) unexpected reply") +end + +-- end of message; let the filter react +if mt.eom(conn) ~= nil then + error("mt.eom() failed") +end + +-- verify that the right Authentication-Results header field got added +if mt.eom_check(conn, MT_HDRINSERT, "Authentication-Results") or + mt.eom_check(conn, MT_HDRADD, "Authentication-Results") then + ar = mt.getheader(conn, "Authentication-Results", 0) + if string.find(ar, "spf=fail", 1, true) == nil then + error("incorrect Authentication-Results field") + else + mt.echo("SPF failed as expected") + end +else + mt.echo ("Got header Authentication-Results: " .. ar) + error("missing Authentication-Results field") +end + +mt.disconnect(conn) + +-- try to connect to it +conn = mt.connect("inet:2424@127.0.0.1", 40, 0.25) +if conn == nil then + error("mt.connect() failed") +end + +-- send connection information +-- mt.negotiate() is called implicitly +mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") +if mt.conninfo(conn, "localhost", "10.11.12.13") ~= nil then + error("mt.conninfo() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.conninfo() unexpected reply") +end + +-- send envelope macros and sender data +-- mt.helo() is called implicitly +mt.macro(conn, SMFIC_MAIL, "i", "t-verify-malformed") +if mt.mailfrom(conn, "") ~= nil then + error("mt.mailfrom() failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.mailfrom() unexpected reply") +end + +-- send headers +-- mt.rcptto() is called implicitly +if mt.header(conn, "From", "user") ~= nil then + error("mt.header(From) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(From) unexpected reply") +end +if mt.header(conn, "Date", "Tue, 22 Dec 2009 13:04:12 -0800") ~= nil then + error("mt.header(Date) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Date) unexpected reply") +end +if mt.header(conn, "Subject", "Signing test") ~= nil then + error("mt.header(Subject) failed") +end +if mt.getreply(conn) ~= SMFIR_CONTINUE then + error("mt.header(Subject) unexpected reply") +end + +-- end of message; let the filter react +if mt.eom(conn) ~= nil then + error("mt.eom() failed") +end + +-- verify that the right Authentication-Results header field got added +if mt.eom_check(conn, MT_HDRINSERT, "Authentication-Results") or + mt.eom_check(conn, MT_HDRADD, "Authentication-Results") then + ar = mt.getheader(conn, "Authentication-Results", 0) + if string.find(ar, "spf=fail", 1, true) == nil then + mt.echo ("Got header Authentication-Results: " .. ar) + error("incorrect Authentication-Results field") + else + mt.echo("SPF failed as expected") + end +else + mt.echo ("Got header Authentication-Results: " .. ar) + error("missing Authentication-Results field") +end + +mt.disconnect(conn)