aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/rest/tests/test_addresses.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/rest/tests/test_addresses.py')
-rw-r--r--src/mailman_pgp/rest/tests/test_addresses.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/mailman_pgp/rest/tests/test_addresses.py b/src/mailman_pgp/rest/tests/test_addresses.py
index 1730618..ba8ba0e 100644
--- a/src/mailman_pgp/rest/tests/test_addresses.py
+++ b/src/mailman_pgp/rest/tests/test_addresses.py
@@ -23,19 +23,25 @@ from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import call_api
from zope.component import getUtility
-from mailman_pgp.database import transaction
+from mailman_pgp.database import mm_transaction, transaction
from mailman_pgp.model.address import PGPAddress
from mailman_pgp.testing.layers import PGPRESTLayer
+from mailman_pgp.testing.pgp import load_key
+from mailman_pgp.utils.pgp import key_from_blob
class TestAddresses(unittest.TestCase):
layer = PGPRESTLayer
def setUp(self):
- self.mm_address = getUtility(IUserManager).create_address(
- 'anne@example.com')
+ with mm_transaction():
+ self.mm_address = getUtility(IUserManager).create_address(
+ 'anne@example.com')
+ self.address_key = load_key('ecc_p256.pub.asc')
with transaction() as t:
self.address = PGPAddress(self.mm_address)
+ self.address.key = self.address_key
+ self.address.key_confirmed = True
t.add(self.address)
def test_missing_address(self):
@@ -58,3 +64,24 @@ class TestAddresses(unittest.TestCase):
'http://localhost:9001/3.1/plugins/pgp/addresses/'
'anne@example.com')
self.assertEqual(json['email'], self.address.email)
+
+ def test_address_key(self):
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/addresses/'
+ 'anne@example.com/key')
+ key = key_from_blob(json['key'])
+ self.assertEqual(key.fingerprint, self.address_key.fingerprint)
+ self.assertEqual(json['key_fingerprint'], self.address_key.fingerprint)
+ self.assertEqual(json['key_confirmed'], True)
+
+ def test_address_no_key(self):
+ with mm_transaction():
+ mm_address = getUtility(IUserManager).create_address(
+ 'bart@example.com')
+ with transaction() as t:
+ address = PGPAddress(mm_address)
+ t.add(address)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/addresses/'
+ 'bart@example.com/key')
+ self.assertEqual(cm.exception.code, 404)