diff options
| author | J08nY | 2017-06-27 22:48:17 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-27 22:48:17 +0200 |
| commit | a3c44b197c84b43a7fa76c3f2c20eddd6ae7dc9f (patch) | |
| tree | a74d018edbc0613cff2a4af3ffa5fca904f2a26a | |
| parent | d9863d91ba8be95f432830d8ac53baf8e50cf7c7 (diff) | |
| download | mailman-pgp-a3c44b197c84b43a7fa76c3f2c20eddd6ae7dc9f.tar.gz mailman-pgp-a3c44b197c84b43a7fa76c3f2c20eddd6ae7dc9f.tar.zst mailman-pgp-a3c44b197c84b43a7fa76c3f2c20eddd6ae7dc9f.zip | |
| -rw-r--r-- | src/mailman_pgp/rest/lists.py | 6 | ||||
| -rw-r--r-- | src/mailman_pgp/rest/tests/test_lists.py | 29 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/mailman_pgp/rest/lists.py b/src/mailman_pgp/rest/lists.py index 4cffa38..72fa7a4 100644 --- a/src/mailman_pgp/rest/lists.py +++ b/src/mailman_pgp/rest/lists.py @@ -80,8 +80,12 @@ class AListPubkey: def on_get(self, request, response): """/lists/<list_id>/key""" if self._mlist is None: - return not_found() + return not_found(response) else: + pubkey = self._mlist.pubkey + if pubkey is None: + return not_found(response) + resource = dict(public_key=str(self._mlist.pubkey), key_fingerprint=str( self._mlist.pubkey.fingerprint)) diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py index 3bdd01d..4a80bde 100644 --- a/src/mailman_pgp/rest/tests/test_lists.py +++ b/src/mailman_pgp/rest/tests/test_lists.py @@ -14,7 +14,7 @@ # # 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 @@ -22,6 +22,7 @@ from mailman.app.lifecycle import create_list from mailman.database.transaction import transaction as mailman_transaction from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer +from pgpy import PGPKey class TestLists(TestCase): @@ -38,7 +39,7 @@ class TestLists(TestCase): 'missing.example.com') self.assertEqual(cm.exception.code, 404) - def test_has_list(self): + def test_all_lists(self): json, response = call_api( 'http://localhost:9001/3.1/plugins/pgp/lists/') self.assertEqual(json['total_size'], 1) @@ -46,3 +47,27 @@ class TestLists(TestCase): lists = json['entries'] plist = lists[0] self.assertEqual(plist['list_id'], self.mlist.list_id) + + def test_get_list(self): + json, response = call_api( + 'http://localhost:9001/3.1/plugins/pgp/lists/' + 'test.example.com') + 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) + + json.pop('http_etag') + self.assertEqual(len(json.keys()), 2) + self.assertIn('public_key', json.keys()) + self.assertIn('key_fingerprint', json.keys()) + + key, _ = PGPKey.from_blob(json['public_key']) + self.assertEqual(json['key_fingerprint'], key.fingerprint) |
