diff options
| author | J08nY | 2017-07-31 01:23:01 +0200 |
|---|---|---|
| committer | J08nY | 2017-07-31 01:23:01 +0200 |
| commit | 57b39b5701dbac48eacfb904e00fbd9ba409317a (patch) | |
| tree | 35b022b8827b1260c1999fcfe9986d13065ad178 | |
| parent | c28fc92df4561d377e415d8b42897ec4c9d7267f (diff) | |
| download | mailman-pgp-57b39b5701dbac48eacfb904e00fbd9ba409317a.tar.gz mailman-pgp-57b39b5701dbac48eacfb904e00fbd9ba409317a.tar.zst mailman-pgp-57b39b5701dbac48eacfb904e00fbd9ba409317a.zip | |
| -rw-r--r-- | src/mailman_pgp/rest/lists.py | 5 | ||||
| -rw-r--r-- | src/mailman_pgp/rest/tests/test_lists.py | 80 |
2 files changed, 78 insertions, 7 deletions
diff --git a/src/mailman_pgp/rest/lists.py b/src/mailman_pgp/rest/lists.py index 1998f91..3ff7756 100644 --- a/src/mailman_pgp/rest/lists.py +++ b/src/mailman_pgp/rest/lists.py @@ -125,11 +125,6 @@ class APGPList(_PGPListBase): response, 'Unknown attribute: {}'.format(error.attribute)) return - except ReadOnlyPATCHRequestError as error: - bad_request( - response, - 'Read-only attribute: {}'.format(error.attribute)) - return try: with transaction(): validator.update(self._mlist, request) diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py index 381d4ac..365cd05 100644 --- a/src/mailman_pgp/rest/tests/test_lists.py +++ b/src/mailman_pgp/rest/tests/test_lists.py @@ -76,7 +76,21 @@ class TestLists(TestCase): 'test@example.com') self.assertEqual(json['list_id'], self.mlist.list_id) - def test_put_list_config(self): + +class TestListConfig(TestCase): + layer = PGPRESTLayer + + def setUp(self): + with mm_transaction(): + 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_put(self): config = dict(unsigned_msg_action='defer', inline_pgp_action='defer', expired_sig_action='defer', @@ -100,7 +114,25 @@ class TestLists(TestCase): attr = attr.name self.assertEqual(attr, config[key]) - def test_patch_list_config(self): + def test_put_wrong_value(self): + config = dict(unsigned_msg_action='not-an-action', + 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) + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.1/plugins/pgp/lists/' + 'test.example.com', + data=config, + method='PUT') + self.assertEqual(cm.exception.code, 400) + + def test_patch(self): json, response = call_api( 'http://localhost:9001/3.1/plugins/pgp/lists/' 'test.example.com', @@ -109,6 +141,50 @@ class TestLists(TestCase): self.assertEqual(response.status_code, 204) self.assertEqual(self.pgp_list.unsigned_msg_action, Action.defer) + def test_patch_wrong_attribute(self): + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.1/plugins/pgp/lists/' + 'test.example.com', + data=dict(something_something='somewhere'), + method='PATCH') + self.assertEqual(cm.exception.code, 400) + + def test_patch_wrong_value(self): + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.1/plugins/pgp/lists/' + 'test.example.com', + data=dict(unsigned_msg_action='not-an-action'), + method='PATCH') + self.assertEqual(cm.exception.code, 400) + + def test_missing_list(self): + with self.assertRaises(HTTPError) as cm: + call_api('http://localhost:9001/3.1/plugins/pgp/lists/' + 'missing.example.com', + data=dict(), + method='PUT') + 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', + data=dict(), + method='PATCH') + self.assertEqual(cm.exception.code, 404) + + +class TestListKey(TestCase): + layer = PGPRESTLayer + + def setUp(self): + with mm_transaction(): + 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_get_list_key(self): json, response = call_api( 'http://localhost:9001/3.1/plugins/pgp/lists/' |
