diff options
Diffstat (limited to 'src/mailman/rules')
| -rw-r--r-- | src/mailman/rules/dmarc.py | 19 | ||||
| -rw-r--r-- | src/mailman/rules/tests/test_dmarc.py | 33 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/mailman/rules/dmarc.py b/src/mailman/rules/dmarc.py index dac1cd88c..90b874e32 100644 --- a/src/mailman/rules/dmarc.py +++ b/src/mailman/rules/dmarc.py @@ -43,8 +43,6 @@ def _get_suffixes(url): # This loads and parses the data from the url argument into s_dict for # use by _get_org_dom. global s_dict - if s_dict: - return if not url: return try: @@ -199,17 +197,16 @@ def _DMARCProhibited(mlist, email, dmarc_domain, org=False): policy = mo.group(1).lower() else: continue - if policy == 'reject': - vlog.info( - """%s: DMARC lookup for %s (%s) - found p=reject in %s = %s""", - mlist.list_name, email, dmarc_domain, name, entry) - return True - if policy == 'quarantine': + if policy in ('reject', 'quarantine'): vlog.info( """%s: DMARC lookup for %s (%s) - found p=quarantine in %s = %s""", - mlist.list_name, email, dmarc_domain, name, entry) + found p=%s in %s = %s""", + mlist.list_name, + email, + dmarc_domain, + policy, + name, + entry) return True return False diff --git a/src/mailman/rules/tests/test_dmarc.py b/src/mailman/rules/tests/test_dmarc.py index 930741997..666375699 100644 --- a/src/mailman/rules/tests/test_dmarc.py +++ b/src/mailman/rules/tests/test_dmarc.py @@ -15,12 +15,15 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. -"""Support for mocking dnspython calls from dmarc rules.""" +"""Provides support for mocking dnspython calls from dmarc rules and some +organizational domain tests.""" from dns.rdatatype import TXT from dns.resolver import NXDOMAIN, NoAnswer +from mailman.rules import dmarc +from mailman.testing.layers import ConfigLayer from public import public -from unittest import mock +from unittest import TestCase, mock @public @@ -79,3 +82,29 @@ def get_dns_resolver(): return self patcher = mock.patch('dns.resolver.Resolver', Resolver) return patcher + + +class TestDMARCRules(TestCase): + """Test organizational domain determination.""" + + layer = ConfigLayer + + def setUp(self): + pass + + def test_no_url(self): + dmarc.s_dict = {} + dmarc._get_suffixes(None) + self.assertEqual(dmarc.s_dict, dict()) + + def test_no_data_for_domain(self): + self.assertEqual( + dmarc._get_org_dom('sub.dom.example.nxtld'), 'example.nxtld') + + def test_domain_with_wild_card(self): + self.assertEqual( + dmarc._get_org_dom('ssub.sub.foo.kobe.jp'), 'sub.foo.kobe.jp') + + def test_exception_to_wild_card(self): + self.assertEqual( + dmarc._get_org_dom('ssub.sub.city.kobe.jp'), 'city.kobe.jp') |
