From c098f9df6beacf1b4623d359d2f5d409fff0bf8b Mon Sep 17 00:00:00 2001 From: "Stuart D. Gathman" Date: Tue, 16 Jun 2020 18:45:03 -0400 Subject: [PATCH] Test case for Milter.config (still failing) --- Milter/config.py | 5 ++++- Milter/test.py | 5 +++++ test.py | 2 ++ test/pysrs.cfg | 32 ++++++++++++++++++++++++++++++++ testcfg.py | 15 +++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 test/pysrs.cfg create mode 100644 testcfg.py diff --git a/Milter/config.py b/Milter/config.py index 944d26c..df64b3d 100644 --- a/Milter/config.py +++ b/Milter/config.py @@ -1,4 +1,7 @@ -from ConfigParser import ConfigParser +try: + from configparser import ConfigParser +except: + from ConfigParser import ConfigParser import os.path class MilterConfigParser(ConfigParser): diff --git a/Milter/test.py b/Milter/test.py index 846752e..e6906d6 100644 --- a/Milter/test.py +++ b/Milter/test.py @@ -46,6 +46,9 @@ class TestBase(object): ## The macros returned by protocol stage self._symlist = [ None, None, None, None, None, None, None ] + def _close(self): + close(self.logfp) + def log(self,*msg): for i in msg: print(i,file=self.logfp,end=None) print(file=self.logfp) @@ -204,6 +207,8 @@ class TestBase(object): self._body.write(header) self._body.write(b'\n\n') self._body.write(body) + self.close() + self._close() return rc ## Feed an email contained in a file to the %milter. diff --git a/test.py b/test.py index 895965e..96c608c 100644 --- a/test.py +++ b/test.py @@ -3,6 +3,7 @@ import testmime import testsample import testutils import testgrey +import testcfg import os def suite(): @@ -11,6 +12,7 @@ def suite(): s.addTest(testsample.suite()) s.addTest(testutils.suite()) s.addTest(testgrey.suite()) + s.addTest(testcfg.suite()) return s if __name__ == '__main__': diff --git a/test/pysrs.cfg b/test/pysrs.cfg new file mode 100644 index 0000000..622ccf6 --- /dev/null +++ b/test/pysrs.cfg @@ -0,0 +1,32 @@ +# sample SRS configuration +[srs] +;secret="shhhh!" +;maxage=21 +;hashlength=5 +# if defined, SRS uses a database for opaque rewriting +;database=/var/log/milter/srsdata +# sign these domains using SES to prevent forged bounces instead of SRS +;ses = localdomain1.com, localdomain2.org +# sign these domains using SRS in signing mode to prevent forged bounces +;sign = localdomain1.com, localdomain2.org +# rewrite all other domains to this domain using SRS +;fwdomain = mydomain.com +# additional domains to decode (reverse) srs +# NOTE: bms.py in milter package can also do this, as can pysrs.m4 HACK. +;srs = otherdomain.com +# do not rewrite mail to these domains +;nosrs = braindeadmail.com +# Treat these localparts as a DSN. Lot's of braindead systems +# send non-DSN mail to MAIL FROM. +;banned_users = mailer-daemon, clamav, postmaster + +[srsmilter] +;datadir=/var/lib/milter +socketname = /var/run/milter/srsmilter +miltername = pysrsfilter +# reject DSNs to unsigned recipients (bounce spam) +reject_spoofed = true +;trusted_relay = 1.2.3.4 +internal_connect = 192.168.*.*,127.0.0.1,::1 +# Enable outgoing SRS via CHGFROM (see code for limitations) +miltersrs = false diff --git a/testcfg.py b/testcfg.py new file mode 100644 index 0000000..0e19469 --- /dev/null +++ b/testcfg.py @@ -0,0 +1,15 @@ +import unittest +from Milter.config import MilterConfigParser + +class ConfigTestCase(unittest.TestCase): + def testConfig(self): + cp = MilterConfigParser() + cp.read(['test/pysrs.cfg']) + socketname = cp.getdefault('srsmilter','socketname', + '/var/run/milter/srsmilter') + self.assertEqual(socketname,'/var/run/milter/srsmilter') + +def suite(): return unittest.makeSuite(ConfigTestCase,'test') + +if __name__ == '__main__': + unittest.main()