Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymilter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Url: http://bmsi.com/pymilter
Source: https://github.com/sdgathman/pymilter/archive/pymilter-%{version}.tar.gz
#Source1: tmpfiles-python-pymilter.conf
# remove unit tests that require network for check
Patch: pymilter-check.patch
Patch: test-nonet.patch
License: GPLv2+
Group: Development/Libraries
BuildRequires: python2-devel, %{python3}-devel, sendmail-devel >= 8.13
Expand Down
10 changes: 0 additions & 10 deletions pymilter-check.patch → test-nonet.patch
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,3 @@ diff -up ./Milter/utils.py.check ./Milter/utils.py
diff -up ./test.py.check ./test.py
--- ./test.py.check 2018-08-04 23:04:58.609420815 -0400
+++ ./test.py 2018-08-04 23:05:40.070949438 -0400
@@ -14,6 +14,8 @@ def suite():
return s

if __name__ == '__main__':
+ import sys
try: os.remove('test/milter.log')
except: pass
- unittest.TextTestRunner().run(suite())
+ rc = unittest.TextTestRunner().run(suite())
+ sys.exit(len(rc.failures))
4 changes: 3 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def suite():
return s

if __name__ == '__main__':
import sys
try: os.remove('test/milter.log')
except: pass
unittest.TextTestRunner().run(suite())
rc = unittest.TextTestRunner().run(suite())
sys.exit(0 if rc.wasSuccessful() else 1)
16 changes: 13 additions & 3 deletions testpolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
import sys
import os
import bsddb3
from Milter.policy import MTAPolicy

class Config(object):
Expand All @@ -10,16 +11,25 @@ def __init__(self):
self.access_file_nulls=True
self.access_file_colon = False

def makemap(in_filename, out_filename):
db = bsddb3.hashopen(out_filename, 'c')
with open(in_filename, 'r', encoding='utf-8') as fh:
for line in fh:
line = line.strip().replace(":", "!")
if not line or line.startswith("#"):
continue
[k, v] = line.split(maxsplit=1)
db[k.lower().encode()] = v.encode()
db.close()

class PolicyTestCase(unittest.TestCase):

def setUp(self):
self.config = Config()
if os.access('test/access',os.R_OK):
if not os.path.exists('test/access.db') or \
os.path.getmtime('test/access') > os.path.getmtime('test/access.db'):
cmd = 'tr : ! <test/access | makemap hash test/access.db'
if os.system(cmd):
print('failed!')
makemap("test/access", "test/access.db")
else:
print("Missing test/access")

Expand Down