diff --git a/run_tests.sh b/run_tests.sh index 3480d3d..dafc2e8 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,21 +1,9 @@ #!/bin/bash ./smf-spf -h -RET=0 for testfile in tests/* ; do echo "#########################################" echo "Running $testfile ..." - miltertest -s $testfile - status=$? - echo -n "returned " - if [ $status -eq 0 ] ; then - echo -e "\e[32msuccessful\e[39m" - else - echo -e "\e[31mfailed\e[39m" - RET=1 - FAILED+="\n\t$testfile" - fi + echo "#########################################" + miltertest -s $testfile done - -[[ -z "$FAILED" ]] || echo -e "#########################################\nFailed tests $FAILED" -exit $RET diff --git a/smf-spf-tests-fixedip-fail.conf b/smf-spf-tests-fixedip-fail.conf index 305c0e6..df63359 100644 --- a/smf-spf-tests-fixedip-fail.conf +++ b/smf-spf-tests-fixedip-fail.conf @@ -1,6 +1,5 @@ WhitelistIP 192.168.0.0/16 relaxedlocalpart on -TTL 1h tagsubject off RejectReason "Rejeitado" User nobody diff --git a/smf-spf-tests-fixedip.conf b/smf-spf-tests-fixedip.conf index c54410e..cb6ff11 100644 --- a/smf-spf-tests-fixedip.conf +++ b/smf-spf-tests-fixedip.conf @@ -1,14 +1,13 @@ +LogTo /dev/stdout WhitelistIP 192.168.0.0/16 RefuseFail off # (on|off) -TTL 1D relaxedlocalpart on tagsubject off -FixedClientIP 54.154.126.152 +FixedClientIP 54.154.126.152 RefuseFail on User nobody Socket inet:2424@127.0.0.1 -Syslog none -LogTo /dev/stdout +Syslog mail # (daemon|mail|local0...local7) Daemonize off # (on|off) AuthservID mail.example.com diff --git a/smf-spf-tests-q.conf b/smf-spf-tests-q.conf index 7ee33e0..91da65f 100644 --- a/smf-spf-tests-q.conf +++ b/smf-spf-tests-q.conf @@ -9,6 +9,6 @@ Quarantine on # (on|off) QuarantineBox postmaster TTL 60m User nobody -Socket unix:/tmp/milter.sock +Socket unix:./milter.sock Syslog mail # (daemon|mail|local0...local7) Daemonize off # (on|off) diff --git a/smf-spf-tests-refuse.conf b/smf-spf-tests-refuse.conf index dcdbd6d..fb09f62 100644 --- a/smf-spf-tests-refuse.conf +++ b/smf-spf-tests-refuse.conf @@ -1,3 +1,4 @@ +LogTo /dev/stdout WhitelistIP 127.0.0.0/8 RefuseFail on # (on|off) RefuseSPFnone on # (on|off) diff --git a/smf-spf-tests.conf b/smf-spf-tests.conf index 8861dd7..b65302c 100644 --- a/smf-spf-tests.conf +++ b/smf-spf-tests.conf @@ -98,7 +98,8 @@ QuarantineBox postmaster # # Default: 1h # -TTL 1 +TTL 1D +TTL 1h # Run as a selected user (smf-spf must be started by root) # diff --git a/tests/01-loadconfig-q.lua b/tests/01-loadconfig-q.lua index dc77e99..53070aa 100644 --- a/tests/01-loadconfig-q.lua +++ b/tests/01-loadconfig-q.lua @@ -1,6 +1,6 @@ mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-q.conf") -- try to connect to it -conn = mt.connect("unix:/tmp/milter.sock", 4, 0.25) +conn = mt.connect("unix:./milter.sock", 40, 0.25) if conn == nil then error("mt.connect() failed") end diff --git a/tests/02-host-whitelisted.lua b/tests/02-host-whitelisted.lua index fdf1157..1ed2b3a 100644 --- a/tests/02-host-whitelisted.lua +++ b/tests/02-host-whitelisted.lua @@ -11,7 +11,7 @@ end -- send connection information -mt.macro(conn, SMFIC_CONNECT, "j", "") +mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") if mt.conninfo(conn, "server.example.org", "2001:0101:DEAD:BEEF::1") ~= nil then error("mt.conninfo() failed") end diff --git a/tests/04-fixed-client-fail.lua b/tests/04-fixed-client-fail.lua index 7be9931..d932d31 100644 --- a/tests/04-fixed-client-fail.lua +++ b/tests/04-fixed-client-fail.lua @@ -1,5 +1,5 @@ -- Copyright (c) 2009-2013, The Trusted Domain Project. All rights reserved. -mt.echo("SPF Fixed-client fail. Using ./smf-spf-tests-fixedip-fail.conf") +mt.echo("SPF pass test") -- try to start the filter mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-fixedip-fail.conf") diff --git a/tests/04-fixed-client-pass.lua b/tests/04-fixed-client-pass.lua index e7530b8..b2f248e 100644 --- a/tests/04-fixed-client-pass.lua +++ b/tests/04-fixed-client-pass.lua @@ -1,5 +1,5 @@ -- Copyright (c) 2009-2013, The Trusted Domain Project. All rights reserved. -mt.echo("SPF Fixed-client pass. Using ./smf-spf-tests-fixedip.conf") +mt.echo("SPF pass test") -- try to start the filter mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-fixedip.conf") @@ -13,7 +13,7 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "10.10.10.10") ~= nil then +if mt.conninfo(conn, "localhost", "192.0.0.194") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -68,8 +68,8 @@ end 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) then - error("incorrect Authentication-Results field : " .. ar) + if string.find(ar, "spf=pass", 1, true) == nil then + error("incorrect Authentication-Results field") else mt.echo("SPF pass ") end diff --git a/tests/04-fulltest-fail-tag.lua b/tests/04-fulltest-fail-tag.lua index ea24019..223d1f4 100644 --- a/tests/04-fulltest-fail-tag.lua +++ b/tests/04-fulltest-fail-tag.lua @@ -5,7 +5,7 @@ mt.echo("SPF fail test") mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-q.conf") -- try to connect to it -conn = mt.connect("unix:/tmp/milter.sock", 40, 0.25) +conn = mt.connect("unix:./milter.sock", 40, 0.25) if conn == nil then error("mt.connect() failed") end diff --git a/tests/04-fulltest-neutral.lua b/tests/04-fulltest-neutral.lua index 821887a..a90423e 100644 --- a/tests/04-fulltest-neutral.lua +++ b/tests/04-fulltest-neutral.lua @@ -60,11 +60,11 @@ end 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) then + if string.find(ar, "spf=neutral", 1, true) == nil then mt.echo ("Got header Authentication-Results: " .. ar) error("incorrect Authentication-Results field") else - mt.echo("SPF neutral") + mt.echo("SPF neutral ") end else mt.echo ("Got header Authentication-Results: " .. ar) diff --git a/tests/04-fulltest-pass.lua b/tests/04-fulltest-pass.lua index 0bef09f..f352ba2 100644 --- a/tests/04-fulltest-pass.lua +++ b/tests/04-fulltest-pass.lua @@ -13,7 +13,7 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "54.154.126.152") ~= nil then +if mt.conninfo(conn, "localhost", "54.194.147.141") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -77,12 +77,11 @@ end 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) then - mt.echo("SPF pass ") - else - mt.echo(" Got AR: "..ar); - error("incorrect Authentication-Results field") - end + if string.find(ar, "spf=pass", 1, true) == nil then + error("incorrect Authentication-Results field") + else + mt.echo("SPF pass ") + end else mt.echo ("Got header Authentication-Results: " .. ar) error("missing Authentication-Results field") diff --git a/tests/04-fulltest-refusefail.lua b/tests/04-fulltest-refusefail.lua index d793ee7..a3e14c8 100644 --- a/tests/04-fulltest-refusefail.lua +++ b/tests/04-fulltest-refusefail.lua @@ -1,5 +1,5 @@ -- Copyright (c) 2009-2013, The Trusted Domain Project. All rights reserved. -mt.echo("SPF refusefail test. Using ./smf-spf-tests-refuse.conf") +mt.echo("SPF pass test") -- try to start the filter mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests-refuse.conf") @@ -13,7 +13,7 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "10.10.10.10") ~= nil then +if mt.conninfo(conn, "localhost", "195.22.26.194") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -27,11 +27,10 @@ if mt.mailfrom(conn, "") ~= nil then error("mt.mailfrom() failed") end -if mt.getreply(conn) == SMFIR_REPLYCODE then - mt.echo ("received SMFIR_REPLYCODE ") -else - error("mt.mailfrom() unexpected reply") +if mt.getreply(conn) ~= SMFIR_REPLYCODE then + error("mt.mailfrom() unexpected reply") end +print ("received SMFIR_REPLYCODE ") mt.disconnect(conn) diff --git a/tests/04-fulltest-soft.lua b/tests/04-fulltest-soft.lua index 7faac32..eebe1b2 100644 --- a/tests/04-fulltest-soft.lua +++ b/tests/04-fulltest-soft.lua @@ -60,12 +60,12 @@ end 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=softfail", 1) then - mt.echo("SPF softfail") - else - mt.echo(" Got AR: "..ar); - error("incorrect Authentication-Results field") - end + if string.find(ar, "spf=softfail", 1, true) == nil then + mt.echo ("Got header Authentication-Results: " .. ar) + error("incorrect Authentication-Results field") + else + mt.echo("SPF softfail ") + end else mt.echo ("Got header Authentication-Results: " .. ar) error("missing Authentication-Results field") diff --git a/tests/04-helo-pass.lua b/tests/04-helo-pass.lua index fc4837c..9cbf92c 100644 --- a/tests/04-helo-pass.lua +++ b/tests/04-helo-pass.lua @@ -13,7 +13,7 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "hostname.underspell.com","10.11.12.13") ~= nil then +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 @@ -67,14 +67,13 @@ end 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) - mt.echo("Got AR "..ar) - if string.find(ar, "spf=pass", 1) then - mt.echo("SPF pass ") - else + if string.find(ar, "spf=pass", 1, true) == nil then error("incorrect Authentication-Results field") + else + mt.echo("SPF pass ") end else + mt.echo ("Got header Authentication-Results: " .. ar) error("missing Authentication-Results field") end - mt.disconnect(conn) diff --git a/tests/05-cache-test.lua b/tests/05-cache-test.lua index c4c2519..df33115 100644 --- a/tests/05-cache-test.lua +++ b/tests/05-cache-test.lua @@ -1,5 +1,5 @@ -- Copyright (c) 2009-2013, The Trusted Domain Project. All rights reserved. -mt.echo("Milter cache test. Using ./smf-spf-tests.conf") +mt.echo("Milter cache test") -- try to start the filter mt.startfilter("./smf-spf", "-f", "-c","./smf-spf-tests.conf") @@ -13,7 +13,8 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "54.154.126.152") ~= nil then +mt.echo("Connect from 54.194.157.134") +if mt.conninfo(conn, "localhost", "54.194.157.134") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -23,7 +24,7 @@ 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 +if mt.mailfrom(conn, "") ~= nil then error("mt.mailfrom() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -60,11 +61,10 @@ end 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) then - mt.echo("SPF none") - else - mt.echo(" Got AR: "..ar); + 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") @@ -80,7 +80,8 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "54.154.126.152") ~= nil then +mt.echo("Connect from 54.194.147.141") +if mt.conninfo(conn, "localhost", "54.194.147.141") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -127,16 +128,16 @@ end 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) then - mt.echo("SPF pass ") - else - mt.echo(" Got AR: "..ar); + if string.find(ar, "spf=pass", 1, true) == nil then error("incorrect Authentication-Results field") + else + mt.echo("SPF pass ") 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) @@ -147,7 +148,8 @@ end -- send connection information -- mt.negotiate() is called implicitly mt.macro(conn, SMFIC_CONNECT, "j", "mta.name.local") -if mt.conninfo(conn, "localhost", "54.154.126.152") ~= nil then +mt.echo("Connect from 54.194.147.141") +if mt.conninfo(conn, "localhost", "54.194.147.141") ~= nil then error("mt.conninfo() failed") end if mt.getreply(conn) ~= SMFIR_CONTINUE then @@ -194,15 +196,14 @@ end 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) then - mt.echo("SPF pass ") - else - mt.echo(" Got AR: "..ar); + if string.find(ar, "spf=pass", 1, true) == nil then error("incorrect Authentication-Results field") + else + mt.echo("SPF pass ") end else mt.echo ("Got header Authentication-Results: " .. ar) error("missing Authentication-Results field") end -mt.disconnect(conn) +mt.disconnect(conn) \ No newline at end of file