aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp
diff options
context:
space:
mode:
authorJ08nY2017-07-17 18:11:55 +0200
committerJ08nY2017-07-17 18:25:32 +0200
commit8de6bac71e3966d89523dbdb4449efe86af3586f (patch)
treecb76d4bcb8660e4e100afb3923fb09497b2fa8f3 /src/mailman_pgp
parent1ffc41fdca212bf157d3272cfe33e864d33ed067 (diff)
downloadmailman-pgp-8de6bac71e3966d89523dbdb4449efe86af3586f.tar.gz
mailman-pgp-8de6bac71e3966d89523dbdb4449efe86af3586f.tar.zst
mailman-pgp-8de6bac71e3966d89523dbdb4449efe86af3586f.zip
Diffstat (limited to 'src/mailman_pgp')
-rw-r--r--src/mailman_pgp/runners/incoming.py15
-rw-r--r--src/mailman_pgp/runners/tests/test_incoming.py29
2 files changed, 39 insertions, 5 deletions
diff --git a/src/mailman_pgp/runners/incoming.py b/src/mailman_pgp/runners/incoming.py
index f7228ff..d25479c 100644
--- a/src/mailman_pgp/runners/incoming.py
+++ b/src/mailman_pgp/runners/incoming.py
@@ -23,6 +23,7 @@ from mailman.core.runner import Runner
from mailman.email.message import Message
from mailman.interfaces.action import Action
from mailman.model.mailinglist import MailingList
+from pgpy.errors import PGPError
from public import public
from mailman_pgp.config import config
@@ -55,9 +56,17 @@ class IncomingRunner(Runner):
# Decrypt it and pass it on.
list_key = pgp_list.key
if list_key is None:
- # keep the message and hope the key generates.
+ # keep the message and hope the key becomes available.
return True
- msg = wrapped.decrypt(list_key)
+
+ try:
+ msg = wrapped.decrypt(list_key)
+ except PGPError:
+ msgdata['moderation_action'] = Action.reject.name
+ msgdata['moderation_sender'] = msg.sender
+ msgdata.setdefault('moderation_reasons', []).append(
+ 'Message could not be decrypted.')
+ msgdata['pgp_moderate'] = True
else:
# Take the `nonencrypted_msg_action`
# just set some data for our `encryption` rule which will
@@ -69,7 +78,7 @@ class IncomingRunner(Runner):
action.name, msg.get('message-id', 'n/a'), reason))
msgdata['moderation_action'] = action.name
msgdata['moderation_sender'] = msg.sender
- msgdata['moderation_reason'] = reason
+ msgdata.setdefault('moderation_reasons', []).append(reason)
msgdata['pgp_moderate'] = True
_pass_default(msg, msgdata, mlist.list_id)
diff --git a/src/mailman_pgp/runners/tests/test_incoming.py b/src/mailman_pgp/runners/tests/test_incoming.py
index 0a37b05..ce03a32 100644
--- a/src/mailman_pgp/runners/tests/test_incoming.py
+++ b/src/mailman_pgp/runners/tests/test_incoming.py
@@ -110,8 +110,8 @@ Some text.
Action.hold.name)
self.assertEqual(items[0].msgdata['moderation_sender'],
self.msg_clear.sender)
- self.assertEqual(items[0].msgdata['moderation_reason'],
- 'Message was not encrypted.')
+ self.assertEqual(items[0].msgdata['moderation_reasons'],
+ ['Message was not encrypted.'])
self.assertTrue(items[0].msgdata['pgp_moderate'])
with transaction():
@@ -163,3 +163,28 @@ To: test@example.com
out_wrapped = PGPWrapper(out_msg)
self.assertTrue(out_wrapped.is_signed())
self.assertTrue(out_wrapped.verifies(self.pgp_sender.key))
+
+ def test_decrypt_fail(self):
+ payload = 'Some signed and encrypted text.'
+ msg = mfs("""\
+From: RSA-1024b@example.org
+To: test@example.com
+
+{}
+ """.format(str(payload)))
+
+ wrapped = PGPWrapper(msg)
+ encrypted = wrapped.encrypt(self.sender_key.pubkey)
+
+ msgdata = dict(listid='test.example.com')
+ mm_config.switchboards['in'].enqueue(encrypted,
+ msgdata)
+ self.runner.run()
+ items = get_queue_messages('in_default', expected_count=1)
+ self.assertEqual(items[0].msgdata['moderation_action'],
+ Action.reject.name)
+ self.assertEqual(items[0].msgdata['moderation_sender'],
+ msg.sender)
+ self.assertEqual(items[0].msgdata['moderation_reasons'],
+ ['Message could not be decrypted.'])
+ self.assertTrue(items[0].msgdata['pgp_moderate'])