aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp
diff options
context:
space:
mode:
authorJ08nY2017-07-07 18:44:08 +0200
committerJ08nY2017-07-07 18:44:08 +0200
commitfd226c656b9f300681a826a7c9d759ece05f28d5 (patch)
treeae94ed0b8e48436e39c823278279df3deee9448f /src/mailman_pgp
parent0b18a7c76d82eef8ec3cf11dab29bf219aeb3035 (diff)
downloadmailman-pgp-fd226c656b9f300681a826a7c9d759ece05f28d5.tar.gz
mailman-pgp-fd226c656b9f300681a826a7c9d759ece05f28d5.tar.zst
mailman-pgp-fd226c656b9f300681a826a7c9d759ece05f28d5.zip
Diffstat (limited to 'src/mailman_pgp')
-rw-r--r--src/mailman_pgp/model/list.py2
-rw-r--r--src/mailman_pgp/rest/tests/test_lists.py19
-rw-r--r--src/mailman_pgp/runners/tests/test_incoming.py65
-rw-r--r--src/mailman_pgp/testing/layers.py4
4 files changed, 70 insertions, 20 deletions
diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py
index eaeb7a3..8b2b5bc 100644
--- a/src/mailman_pgp/model/list.py
+++ b/src/mailman_pgp/model/list.py
@@ -112,6 +112,7 @@ class PGPMailingList(Base):
key_file.write(str(value))
def generate_key(self, block=False):
+ self._key = None
self._key_generator = ListKeyGenerator(config.pgp.keypair_config,
self.mlist.display_name,
self.mlist.posting_address,
@@ -120,6 +121,7 @@ class PGPMailingList(Base):
self._key_generator.start()
if block:
self._key_generator.join()
+ return self.key
@property
def pubkey(self):
diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py
index f5f8754..e940517 100644
--- a/src/mailman_pgp/rest/tests/test_lists.py
+++ b/src/mailman_pgp/rest/tests/test_lists.py
@@ -14,7 +14,6 @@
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-from time import sleep
from unittest import TestCase
from urllib.error import HTTPError
@@ -23,6 +22,7 @@ from mailman.testing.helpers import call_api
from pgpy import PGPKey
from mailman_pgp.database import mm_transaction
+from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.testing.layers import PGPRESTLayer
@@ -56,14 +56,15 @@ class TestLists(TestCase):
self.assertEqual(json['list_id'], self.mlist.list_id)
def test_get_list_key(self):
- for i in range(15):
- try:
- json, response = call_api(
- 'http://localhost:9001/3.1/plugins/pgp/lists/'
- 'test.example.com/key')
- break
- except HTTPError:
- sleep(1)
+ with mm_transaction():
+ mlist = create_list('another@example.com',
+ style_name='pgp-default')
+ pgp_list = PGPMailingList.for_list(mlist)
+ pgp_list.generate_key(True)
+
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/key')
json.pop('http_etag')
self.assertEqual(len(json.keys()), 2)
diff --git a/src/mailman_pgp/runners/tests/test_incoming.py b/src/mailman_pgp/runners/tests/test_incoming.py
index 84a53cc..d06bb2b 100644
--- a/src/mailman_pgp/runners/tests/test_incoming.py
+++ b/src/mailman_pgp/runners/tests/test_incoming.py
@@ -23,7 +23,6 @@ from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import (get_queue_messages, make_testable_runner,
set_preferred,
specialized_message_from_string as mfs)
-from pgpy import PGPMessage
from zope.component import getUtility
from mailman_pgp.config import mm_config
@@ -31,6 +30,7 @@ from mailman_pgp.database import mm_transaction, transaction
from mailman_pgp.model.address import PGPAddress
from mailman_pgp.model.list import PGPMailingList
from mailman_pgp.pgp.tests.base import load_key, load_message
+from mailman_pgp.pgp.wrapper import PGPWrapper
from mailman_pgp.runners.incoming import IncomingRunner
from mailman_pgp.testing.layers import PGPConfigLayer
@@ -47,17 +47,17 @@ class TestIncoming(TestCase):
set_preferred(self.sender)
self.mlist.subscribe(self.sender, MemberRole.member)
+ self.list_key = load_key('ecc_p256.priv.asc')
self.pgp_list = PGPMailingList.for_list(self.mlist)
- self.pgp_list.generate_key(True)
+ self.pgp_list.key = self.list_key
- sender_key = load_key('rsa_1024.pub.asc')
+ self.sender_key = load_key('rsa_1024.priv.asc')
with transaction() as t:
self.pgp_sender = PGPAddress(self.sender.preferred_address)
- self.pgp_sender.key = sender_key
+ self.pgp_sender.key = self.sender_key.pubkey
t.add(self.pgp_sender)
self.msg_clear = load_message('clear.eml')
- self.msg_inline_encrypted = load_message('inline_encrypted.eml')
self.runner = make_testable_runner(IncomingRunner, 'in')
@@ -77,6 +77,26 @@ To: ordinary@example.com
items = get_queue_messages('in_default', expected_count=1)
self.assertEqual(items[0].msg.sender, 'anne@example.com')
+ def test_no_key(self):
+ with mm_transaction():
+ create_list('no-key@example.com',
+ style_name='pgp-default')
+ msg = mfs("""\
+From: anne@example.com
+To: no-key@example.com
+
+Some text.
+""")
+ wrapped = PGPWrapper(msg)
+ encrypted = wrapped.encrypt(self.pgp_list.pubkey)
+
+
+ msgdata = dict(listid='no-key.example.com')
+ mm_config.switchboards['in'].enqueue(encrypted, msgdata)
+ self.runner.run()
+ # Expect the message still there. Waiting for list key.
+ get_queue_messages('in', expected_count=1)
+
def test_nonencrypted_action(self):
with transaction():
self.pgp_list.nonencrypted_msg_action = Action.hold
@@ -103,19 +123,42 @@ To: ordinary@example.com
def test_decrypt(self):
payload = 'Some encrypted text.'
- pmsg = PGPMessage.new(payload)
- emsg = self.pgp_list.pubkey.encrypt(pmsg)
- msg = mfs("""
+ msg = mfs("""\
+From: RSA-1024b@example.org
+To: test@example.com
+
+{}
+""".format(str(payload)))
+ wrapped = PGPWrapper(msg)
+ encrypted = wrapped.encrypt(self.pgp_list.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)
+ out_msg = items[0].msg
+ self.assertEqual(out_msg.get_payload(), msg.get_payload())
+
+ def test_decrypt_combined(self):
+ payload = 'Some signed and encrypted text.'
+ msg = mfs("""\
From: RSA-1024b@example.org
To: test@example.com
{}
-""".format(str(emsg)))
+""".format(str(payload)))
+ wrapped = PGPWrapper(msg)
+ encrypted_signed = wrapped.sign_encrypt(self.sender_key,
+ self.pgp_list.pubkey,
+ self.pgp_sender.key)
msgdata = dict(listid='test.example.com')
- mm_config.switchboards['in'].enqueue(msg,
+ mm_config.switchboards['in'].enqueue(encrypted_signed,
msgdata)
self.runner.run()
items = get_queue_messages('in_default', expected_count=1)
out_msg = items[0].msg
- self.assertEqual(out_msg.get_payload(), payload)
+ out_wrapped = PGPWrapper(out_msg)
+ self.assertTrue(out_wrapped.is_signed())
+ self.assertTrue(out_wrapped.verifies(self.pgp_sender.key))
diff --git a/src/mailman_pgp/testing/layers.py b/src/mailman_pgp/testing/layers.py
index 401f7a6..4cadd3a 100644
--- a/src/mailman_pgp/testing/layers.py
+++ b/src/mailman_pgp/testing/layers.py
@@ -39,6 +39,10 @@ def reset_pgp_world():
# and subclass both it and the respective Mailman Core test layer.
class PGPConfigLayer(ConfigLayer):
@classmethod
+ def setUp(cls):
+ config.set('keypairs', 'autogenerate', 'no')
+
+ @classmethod
def tearDown(cls):
reset_pgp_world()