From caefb5542ddde4760b6688e6ea33eb426a9a3099 Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 19 Jul 2017 18:02:16 +0200 Subject: Add more PersonalizedDelivery tests. --- src/mailman_pgp/mta/personalized.py | 10 ++++++++-- src/mailman_pgp/mta/tests/test_personalized.py | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/mailman_pgp/mta/personalized.py b/src/mailman_pgp/mta/personalized.py index d05cc4b..2b6d228 100644 --- a/src/mailman_pgp/mta/personalized.py +++ b/src/mailman_pgp/mta/personalized.py @@ -49,10 +49,10 @@ class PGPIndividualMixin: recipient = msgdata['recipient'] pgp_address = PGPAddress.for_email(recipient) if pgp_address is None: - # TODO: log failure here + msgdata['no_deliver'] = True return if pgp_address.key is None or not pgp_address.key_confirmed: - # TODO: log failure here? + msgdata['no_deliver'] = True return key = pgp_address.key @@ -84,3 +84,9 @@ class PGPPersonalizedDelivery(IndividualDelivery, VERPMixin, DecoratingMixin, self.personalize_to, self.sign_encrypt ]) + + def _deliver_to_recipients(self, mlist, msg, msgdata, recipients): + if msgdata.get('no_deliver', False): + return dict((recipient, (444, BaseException)) for recipient in + recipients) + return super()._deliver_to_recipients(mlist, msg, msgdata, recipients) diff --git a/src/mailman_pgp/mta/tests/test_personalized.py b/src/mailman_pgp/mta/tests/test_personalized.py index d9d0132..9200a3b 100644 --- a/src/mailman_pgp/mta/tests/test_personalized.py +++ b/src/mailman_pgp/mta/tests/test_personalized.py @@ -162,4 +162,20 @@ Subject: test refused = agent.deliver(ordinary_list, self.msg, msgdata) self.assertEqual(len(refused), 0) - self.assertEqual(len(agent.deliveries), 1) \ No newline at end of file + self.assertEqual(len(agent.deliveries), 1) + + def test_no_pgp_address(self): + msgdata = dict(recipients=['someone@example.org']) + agent = PGPPersonalizedDelivery() + refused = agent.deliver(self.mlist, self.msg, msgdata) + + self.assertEqual(len(refused), 1) + + def test_no_key(self): + with transaction(): + self.pgp_anne.key = None + msgdata = dict(recipients=['anne@example.org']) + agent = PGPPersonalizedDelivery() + refused = agent.deliver(self.mlist, self.msg, msgdata) + + self.assertEqual(len(refused), 1) -- cgit v1.2.3-70-g09d2