aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/rest/tests/test_lists.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/rest/tests/test_lists.py')
-rw-r--r--src/mailman_pgp/rest/tests/test_lists.py111
1 files changed, 105 insertions, 6 deletions
diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py
index 2ebac6b..6509c04 100644
--- a/src/mailman_pgp/rest/tests/test_lists.py
+++ b/src/mailman_pgp/rest/tests/test_lists.py
@@ -14,10 +14,13 @@
#
# 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 unittest import TestCase
from urllib.error import HTTPError
from mailman.app.lifecycle import create_list
+from mailman.interfaces.action import Action
from mailman.testing.helpers import call_api
from pgpy import PGPKey
@@ -35,11 +38,24 @@ class TestLists(TestCase):
self.mlist = create_list('test@example.com',
style_name='pgp-default')
+ self.list_key = load_key('ecc_p256.priv.asc')
+ with transaction():
+ self.pgp_list = PGPMailingList.for_list(self.mlist)
+ self.pgp_list.key = self.list_key
+
def test_missing_list(self):
with self.assertRaises(HTTPError) as cm:
call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
'missing.example.com')
self.assertEqual(cm.exception.code, 404)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'missing.example.com/key')
+ self.assertEqual(cm.exception.code, 404)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'missing.example.com/pubkey')
+ self.assertEqual(cm.exception.code, 404)
def test_all_lists(self):
json, response = call_api(
@@ -60,17 +76,90 @@ class TestLists(TestCase):
'test@example.com')
self.assertEqual(json['list_id'], self.mlist.list_id)
+ def test_put_list_config(self):
+ config = dict(unsigned_msg_action='defer',
+ inline_pgp_action='defer',
+ expired_sig_action='defer',
+ revoked_sig_action='defer',
+ invalid_sig_action='defer',
+ duplicate_sig_action='defer',
+ strip_original_sig=False,
+ sign_outgoing=True,
+ nonencrypted_msg_action='defer',
+ encrypt_outgoing=False)
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com',
+ data=config,
+ method='PUT')
+
+ self.assertEqual(response.status_code, 204)
+ for key in config:
+ attr = getattr(self.pgp_list, key)
+ if isinstance(attr, Action):
+ attr = attr.name
+ self.assertEqual(attr, config[key])
+
+ def test_patch_list_config(self):
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com',
+ data=dict(unsigned_msg_action='defer'),
+ method='PATCH')
+ self.assertEqual(response.status_code, 204)
+ self.assertEqual(self.pgp_list.unsigned_msg_action, Action.defer)
+
def test_get_list_key(self):
- with mm_transaction():
- mlist = create_list('another@example.com',
- style_name='pgp-default')
+ 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)
+ self.assertIn('key', json.keys())
+ self.assertIn('key_fingerprint', json.keys())
+
+ key, _ = PGPKey.from_blob(json['key'])
+ self.assertFalse(key.is_public)
+ self.assertEqual(json['key_fingerprint'], key.fingerprint)
+ self.assertEqual(self.list_key.fingerprint, key.fingerprint)
+
+ def test_missing_list_key(self):
with transaction():
- pgp_list = PGPMailingList.for_list(mlist)
- pgp_list.key = load_key('ecc_p256.priv.asc')
+ self.pgp_list.key = None
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/key')
+ self.assertEqual(cm.exception.code, 404)
+
+ def test_set_list_key(self):
+ new_key = load_key('rsa_1024.priv.asc')
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/key',
+ data=dict(key=str(new_key)),
+ method='PUT')
+
+ self.assertEqual(response.status_code, 202)
+
+ json, response = call_api(
+ 'http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/key')
+
+ key, _ = PGPKey.from_blob(json['key'])
+ self.assertEqual(key.fingerprint, new_key.fingerprint)
+
+ def test_set_list_key_wrong(self):
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/key',
+ dict(key='some stuff?'),
+ method='PUT')
+ self.assertEqual(cm.exception.code, 400)
+ def test_get_list_pubkey(self):
json, response = call_api(
'http://localhost:9001/3.1/plugins/pgp/lists/'
- 'another.example.com/pubkey')
+ 'test.example.com/pubkey')
json.pop('http_etag')
self.assertEqual(len(json.keys()), 2)
@@ -78,4 +167,14 @@ class TestLists(TestCase):
self.assertIn('key_fingerprint', json.keys())
key, _ = PGPKey.from_blob(json['public_key'])
+ self.assertTrue(key.is_public)
self.assertEqual(json['key_fingerprint'], key.fingerprint)
+ self.assertEqual(self.list_key.fingerprint, key.fingerprint)
+
+ def test_missing_list_pubkey(self):
+ with transaction():
+ self.pgp_list.key = None
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.1/plugins/pgp/lists/'
+ 'test.example.com/pubkey')
+ self.assertEqual(cm.exception.code, 404)