aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/commands/tests/test_key.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/commands/tests/test_key.py')
-rw-r--r--src/mailman_pgp/commands/tests/test_key.py231
1 files changed, 200 insertions, 31 deletions
diff --git a/src/mailman_pgp/commands/tests/test_key.py b/src/mailman_pgp/commands/tests/test_key.py
index cfda3e8..1a128a1 100644
--- a/src/mailman_pgp/commands/tests/test_key.py
+++ b/src/mailman_pgp/commands/tests/test_key.py
@@ -27,13 +27,13 @@ from mailman.runners.command import CommandRunner
from mailman.testing.helpers import get_queue_messages, make_testable_runner
from mailman.utilities.datetime import now
from pgpy import PGPKey, PGPUID
-from pgpy.constants import (PubKeyAlgorithm, KeyFlags, EllipticCurveOID,
- HashAlgorithm, SymmetricKeyAlgorithm,
- CompressionAlgorithm)
+from pgpy.constants import (
+ CompressionAlgorithm, EllipticCurveOID, HashAlgorithm, KeyFlags,
+ PubKeyAlgorithm, SymmetricKeyAlgorithm)
from zope.component import getUtility
from mailman_pgp.config import mm_config
-from mailman_pgp.database import transaction
+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.mime import MIMEWrapper
@@ -41,7 +41,7 @@ from mailman_pgp.pgp.wrapper import PGPWrapper
from mailman_pgp.testing.layers import PGPConfigLayer
from mailman_pgp.testing.pgp import load_key
from mailman_pgp.workflows.key_change import CHANGE_CONFIRM_REQUEST
-from mailman_pgp.workflows.pubkey import CONFIRM_REQUEST
+from mailman_pgp.workflows.key_confirm import CONFIRM_REQUEST
from mailman_pgp.workflows.subscription import OpenSubscriptionPolicy
@@ -128,8 +128,7 @@ class TestPreSubscription(unittest.TestCase):
hashes=[HashAlgorithm.SHA256,
HashAlgorithm.SHA512],
ciphers=[SymmetricKeyAlgorithm.AES256],
- compression=[CompressionAlgorithm.ZLIB,
- CompressionAlgorithm.Uncompressed]
+ compression=[CompressionAlgorithm.ZLIB]
)
def test_set(self):
@@ -145,7 +144,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set {}'.format(token))
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -186,7 +185,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set {}'.format(token))
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
wrapped_set_message = MIMEWrapper(set_message)
set_message = wrapped_set_message.encrypt(self.pgp_list.pubkey,
self.bart_key.pubkey)
@@ -246,9 +245,9 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.anne_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.anne_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -263,7 +262,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key)
+ set_message = wrapped_set_message.attach_keys(self.bart_key)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -278,7 +277,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'Re: key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.unusable_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.unusable_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -293,7 +292,7 @@ class TestPreSubscription(unittest.TestCase):
def test_set_no_email(self):
message = _create_mixed('', 'test@example.com', 'key set token')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -307,7 +306,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -326,7 +325,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -349,7 +348,7 @@ class TestPreSubscription(unittest.TestCase):
set_message = _create_mixed('bart@example.com', 'test@example.com',
'key set token')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -594,9 +593,13 @@ class TestAfterSubscription(unittest.TestCase):
layer = PGPConfigLayer
def setUp(self):
- self.mlist = create_list('test@example.com', style_name='pgp-default')
- self.pgp_list = PGPMailingList.for_list(self.mlist)
- self.pgp_list.key = load_key('ecc_p256.priv.asc')
+ with mm_transaction():
+ self.mlist = create_list('test@example.com',
+ style_name='pgp-default')
+ with transaction():
+ self.pgp_list = PGPMailingList.for_list(self.mlist)
+ self.pgp_list.key = load_key('ecc_p256.priv.asc')
+ self.pgp_list.key_change_workflow = 'pgp-key-change-workflow'
self.bart_key = load_key('rsa_1024.priv.asc')
self.bart_new_key = load_key('ecc_p256.priv.asc')
@@ -611,8 +614,7 @@ class TestAfterSubscription(unittest.TestCase):
hashes=[HashAlgorithm.SHA256,
HashAlgorithm.SHA512],
ciphers=[SymmetricKeyAlgorithm.AES256],
- compression=[CompressionAlgorithm.ZLIB,
- CompressionAlgorithm.Uncompressed]
+ compression=[CompressionAlgorithm.ZLIB]
)
def test_change(self):
@@ -628,7 +630,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_new_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -663,7 +665,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_new_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
wrapped_message = MIMEWrapper(message)
message = wrapped_message.encrypt(self.pgp_list.pubkey)
@@ -700,7 +702,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_new_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_new_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -751,7 +753,7 @@ class TestAfterSubscription(unittest.TestCase):
def test_change_no_email(self):
message = _create_mixed('', 'test@example.com', 'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -765,7 +767,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_key.pubkey)
+ message = wrapped_message.attach_keys(self.bart_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -810,9 +812,9 @@ class TestAfterSubscription(unittest.TestCase):
'key change')
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_key.pubkey)
wrapped_set_message = MIMEWrapper(set_message)
- set_message = wrapped_set_message.attach_key(self.bart_new_key.pubkey)
+ set_message = wrapped_set_message.attach_keys(self.bart_new_key.pubkey)
mm_config.switchboards['command'].enqueue(set_message,
listid='test.example.com')
@@ -835,7 +837,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.bart_key)
+ message = wrapped_message.attach_keys(self.bart_key)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -858,7 +860,7 @@ class TestAfterSubscription(unittest.TestCase):
message = _create_mixed('bart@example.com', 'test@example.com',
'key change')
wrapped_message = MIMEWrapper(message)
- message = wrapped_message.attach_key(self.unusable_key.pubkey)
+ message = wrapped_message.attach_keys(self.unusable_key.pubkey)
mm_config.switchboards['command'].enqueue(message,
listid='test.example.com')
@@ -870,6 +872,173 @@ class TestAfterSubscription(unittest.TestCase):
'Need a key which can be used to encrypt communications.',
results_msg.get_payload())
+ def test_revoke_extra_arg(self):
+ message = _create_plain('bart@example.com', 'test@example.com',
+ 'key revoke extra arguments', '')
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('Extraneous argument/s: extra,arguments',
+ results_msg.get_payload())
+
+ def test_revoke_no_email(self):
+ message = _create_mixed('', 'test@example.com', 'key revoke')
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('No email to revoke key of.', results_msg.get_payload())
+
+ def test_revoke_no_pgp_address(self):
+ message = _create_mixed('bart@example.com', 'test@example.com',
+ 'key revoke')
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('A pgp enabled address not found.',
+ results_msg.get_payload())
+
+ def test_revoke_no_key_set(self):
+ bart = getUtility(IUserManager).create_address('bart@example.com',
+ 'Bart Person')
+ with transaction() as t:
+ pgp_address = PGPAddress(bart)
+ t.add(pgp_address)
+
+ message = _create_mixed('bart@example.com', 'test@example.com',
+ 'key revoke')
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn("You currently don't have a key set.",
+ results_msg.get_payload())
+
+ def test_revoke_key_not_confirmed(self):
+ bart = getUtility(IUserManager).create_address('bart@example.com',
+ 'Bart Person')
+ with transaction() as t:
+ pgp_address = PGPAddress(bart)
+ pgp_address.key = self.bart_key.pubkey
+ t.add(pgp_address)
+
+ message = _create_mixed('bart@example.com', 'test@example.com',
+ 'key revoke')
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('Your key is currently not confirmed.',
+ results_msg.get_payload())
+
+ def test_revoke_no_revocs(self):
+ bart = getUtility(IUserManager).create_address('bart@example.com',
+ 'Bart Person')
+ with transaction() as t:
+ pgp_address = PGPAddress(bart)
+ pgp_address.key = self.bart_key.pubkey
+ pgp_address.key_confirmed = True
+ t.add(pgp_address)
+
+ message = _create_plain('bart@example.com', 'test@example.com',
+ 'key revoke', '')
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('No key revocations attached? Send a key revocation.',
+ results_msg.get_payload())
+
+ def test_revoke_resets(self):
+ bart = getUtility(IUserManager).create_address('bart@example.com',
+ 'Bart Person')
+ with transaction() as t:
+ pgp_address = PGPAddress(bart)
+ pgp_address.key = self.bart_key.pubkey
+ pgp_address.key_confirmed = True
+ t.add(pgp_address)
+
+ revoc = self.bart_key.revoke(self.bart_key)
+
+ message = _create_mixed('bart@example.com', 'test@example.com',
+ 'key revoke')
+ wrapped_message = MIMEWrapper(message)
+ message = wrapped_message.attach_revocs(revoc)
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=2)
+ if (items[0].msg['Subject'] ==
+ 'The results of your email commands'): # pragma: no cover
+ results_msg = items[0].msg
+ else:
+ results_msg = items[1].msg
+ #TODO: finish test
+
+ self.assertIn('Key needs to be reset.', results_msg.get_payload())
+
+ def test_revoke_updates(self):
+ bart = getUtility(IUserManager).create_address('bart@example.com',
+ 'Bart Person')
+
+ test_key = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 1024)
+ uid = PGPUID.new('Some Name', email='anne@example.org')
+ test_key.add_uid(uid,
+ usage={KeyFlags.Certify,
+ KeyFlags.EncryptCommunications,
+ KeyFlags.Sign},
+ hashes=[HashAlgorithm.SHA256,
+ HashAlgorithm.SHA512],
+ ciphers=[SymmetricKeyAlgorithm.AES256],
+ compression=[CompressionAlgorithm.ZLIB])
+ sub = PGPKey.new(PubKeyAlgorithm.ECDH, EllipticCurveOID.SECP256K1)
+ test_key.add_subkey(sub, usage={KeyFlags.EncryptCommunications})
+
+ with transaction() as t:
+ pgp_address = PGPAddress(bart)
+ pgp_address.key = test_key.pubkey
+ pgp_address.key_confirmed = True
+ t.add(pgp_address)
+
+ revoc = test_key.revoke(sub.pubkey)
+
+ message = _create_mixed('bart@example.com', 'test@example.com',
+ 'key revoke')
+ wrapped_message = MIMEWrapper(message)
+ message = wrapped_message.attach_revocs(revoc)
+
+ mm_config.switchboards['command'].enqueue(message,
+ listid='test.example.com')
+ make_testable_runner(CommandRunner, 'command').run()
+ items = get_queue_messages('virgin', expected_count=1)
+ results_msg = items[0].msg
+
+ self.assertIn('Key succesfully updated.', results_msg.get_payload())
+ sub = next(iter(pgp_address.key.subkeys.values()))
+ revocs = list(sub.revocation_signatures)
+ self.assertEqual(len(revocs), 1)
+ self.assertEqual(revoc.hash2, revocs[0].hash2)
+
class TestGeneral(unittest.TestCase):
layer = PGPConfigLayer