Skip to content

Commit

Permalink
Merge pull request #26 from jcbf/enable_tests
Browse files Browse the repository at this point in the history
Enable tests
  • Loading branch information
jcbf committed Nov 29, 2016
2 parents a6ca5df + 0ea6e61 commit 9f65e5e
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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)

2 changes: 1 addition & 1 deletion tests/02-host-whitelisted.lua
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tests/04-fulltest-neutral.lua
Expand Up @@ -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 ")
Expand Down
2 changes: 1 addition & 1 deletion tests/04-fulltest-refusefail.lua
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/04-fulltest-soft.lua
Expand Up @@ -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 ")
Expand Down
79 changes: 79 additions & 0 deletions 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)
142 changes: 142 additions & 0 deletions 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, "<user@underspell.com>") ~= 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, "<user@underspell.com>") ~= 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)

0 comments on commit 9f65e5e

Please sign in to comment.