diff options
Diffstat (limited to 'src/mailman/rest')
| -rw-r--r-- | src/mailman/rest/docs/users.rst | 14 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_addresses.py | 9 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_domains.py | 13 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_lists.py | 22 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_membership.py | 58 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_moderation.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_users.py | 7 | ||||
| -rw-r--r-- | src/mailman/rest/users.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/wsgiapp.py | 13 |
9 files changed, 73 insertions, 73 deletions
diff --git a/src/mailman/rest/docs/users.rst b/src/mailman/rest/docs/users.rst index a20306e17..cdede10ee 100644 --- a/src/mailman/rest/docs/users.rst +++ b/src/mailman/rest/docs/users.rst @@ -94,7 +94,7 @@ It is also available via the location given in the response. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 @@ -105,7 +105,7 @@ them with user ids. Thus, a user can be retrieved via its email address. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 @@ -129,7 +129,7 @@ therefore cannot be retrieved. It can be reset though. created_on: 2005-08-01T07:49:23 display_name: Cris Person http_etag: "..." - password: {CLEARTEXT}... + password: {plaintext}... self_link: http://localhost:9001/3.0/users/4 user_id: 4 @@ -227,7 +227,7 @@ In fact, any of these addresses can be used to look up Bart's user record. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 @@ -235,7 +235,7 @@ In fact, any of these addresses can be used to look up Bart's user record. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 @@ -243,7 +243,7 @@ In fact, any of these addresses can be used to look up Bart's user record. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 @@ -251,6 +251,6 @@ In fact, any of these addresses can be used to look up Bart's user record. created_on: 2005-08-01T07:49:23 display_name: Bart Person http_etag: "..." - password: {CLEARTEXT}bbb + password: {plaintext}bbb self_link: http://localhost:9001/3.0/users/3 user_id: 3 diff --git a/src/mailman/rest/tests/test_addresses.py b/src/mailman/rest/tests/test_addresses.py index f4e7cab62..385b83912 100644 --- a/src/mailman/rest/tests/test_addresses.py +++ b/src/mailman/rest/tests/test_addresses.py @@ -17,10 +17,11 @@ """REST address tests.""" -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestAddresses', ] @@ -29,7 +30,7 @@ import unittest from urllib2 import HTTPError from mailman.app.lifecycle import create_list -from mailman.config import config +from mailman.database.transaction import transaction from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -39,8 +40,8 @@ class TestAddresses(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('test@example.com') - config.db.commit() + with transaction(): + self._mlist = create_list('test@example.com') def test_membership_of_missing_address(self): # Try to get the memberships of a missing address. diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py index 89cc34630..a86768481 100644 --- a/src/mailman/rest/tests/test_domains.py +++ b/src/mailman/rest/tests/test_domains.py @@ -17,10 +17,11 @@ """REST domain tests.""" -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestDomains', ] @@ -30,7 +31,7 @@ from urllib2 import HTTPError from zope.component import getUtility from mailman.app.lifecycle import create_list -from mailman.config import config +from mailman.database.transaction import transaction from mailman.interfaces.listmanager import IListManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -41,8 +42,8 @@ class TestDomains(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('test@example.com') - config.db.commit() + with transaction(): + self._mlist = create_list('test@example.com') def test_bogus_endpoint_extension(self): # /domains/<domain>/lists/<anything> is not a valid endpoint. @@ -67,8 +68,8 @@ class TestDomains(unittest.TestCase): def test_lists_are_deleted_when_domain_is_deleted(self): # /domains/<domain> DELETE removes all associated mailing lists. - create_list('ant@example.com') - config.db.commit() + with transaction(): + create_list('ant@example.com') content, response = call_api( 'http://localhost:9001/3.0/domains/example.com', method='DELETE') self.assertEqual(response.status, 204) diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index b030a2e8d..cd0ebaf8e 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -32,7 +32,7 @@ from urllib2 import HTTPError from zope.component import getUtility from mailman.app.lifecycle import create_list -from mailman.config import config +from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -96,8 +96,8 @@ class TestLists(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('test@example.com') - config.db.commit() + with transaction(): + self._mlist = create_list('test@example.com') self._usermanager = getUtility(IUserManager) def test_member_count_with_no_members(self): @@ -109,9 +109,9 @@ class TestLists(unittest.TestCase): def test_member_count_with_one_member(self): # Add a member to a list and check that the resource reflects this. - anne = self._usermanager.create_address('anne@example.com') - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_address('anne@example.com') + self._mlist.subscribe(anne) resource, response = call_api( 'http://localhost:9001/3.0/lists/test@example.com') self.assertEqual(response.status, 200) @@ -119,11 +119,11 @@ class TestLists(unittest.TestCase): def test_member_count_with_two_members(self): # Add two members to a list and check that the resource reflects this. - anne = self._usermanager.create_address('anne@example.com') - self._mlist.subscribe(anne) - bart = self._usermanager.create_address('bar@example.com') - self._mlist.subscribe(bart) - config.db.commit() + with transaction(): + anne = self._usermanager.create_address('anne@example.com') + self._mlist.subscribe(anne) + bart = self._usermanager.create_address('bar@example.com') + self._mlist.subscribe(bart) resource, response = call_api( 'http://localhost:9001/3.0/lists/test@example.com') self.assertEqual(response.status, 200) diff --git a/src/mailman/rest/tests/test_membership.py b/src/mailman/rest/tests/test_membership.py index 202e5f057..875f5e254 100644 --- a/src/mailman/rest/tests/test_membership.py +++ b/src/mailman/rest/tests/test_membership.py @@ -17,10 +17,11 @@ """REST membership tests.""" -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestMembership', ] @@ -31,6 +32,7 @@ from zope.component import getUtility from mailman.app.lifecycle import create_list from mailman.config import config +from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -42,8 +44,8 @@ class TestMembership(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('test@example.com') - config.db.commit() + with transaction(): + self._mlist = create_list('test@example.com') self._usermanager = getUtility(IUserManager) def test_try_to_join_missing_list(self): @@ -85,9 +87,9 @@ class TestMembership(unittest.TestCase): raise AssertionError('Expected HTTPError') def test_try_to_leave_a_list_twice(self): - anne = self._usermanager.create_address('anne@example.com') - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_address('anne@example.com') + self._mlist.subscribe(anne) url = 'http://localhost:9001/3.0/members/1' content, response = call_api(url, method='DELETE') # For a successful DELETE, the response code is 204 and there is no @@ -104,9 +106,9 @@ class TestMembership(unittest.TestCase): raise AssertionError('Expected HTTPError') def test_try_to_join_a_list_twice(self): - anne = self._usermanager.create_address('anne@example.com') - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_address('anne@example.com') + self._mlist.subscribe(anne) try: # For Python 2.6. call_api('http://localhost:9001/3.0/members', { @@ -151,12 +153,12 @@ class TestMembership(unittest.TestCase): self.assertEqual(members[0].address.email, 'hugh/person@example.com') def test_join_as_user_with_preferred_address(self): - anne = self._usermanager.create_user('anne@example.com') - preferred = list(anne.addresses)[0] - preferred.verified_on = now() - anne.preferred_address = preferred - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_user('anne@example.com') + preferred = list(anne.addresses)[0] + preferred.verified_on = now() + anne.preferred_address = preferred + self._mlist.subscribe(anne) content, response = call_api('http://localhost:9001/3.0/members') self.assertEqual(response.status, 200) self.assertEqual(int(content['total_size']), 1) @@ -169,12 +171,12 @@ class TestMembership(unittest.TestCase): self.assertEqual(entry_0['fqdn_listname'], 'test@example.com') def test_member_changes_preferred_address(self): - anne = self._usermanager.create_user('anne@example.com') - preferred = list(anne.addresses)[0] - preferred.verified_on = now() - anne.preferred_address = preferred - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_user('anne@example.com') + preferred = list(anne.addresses)[0] + preferred.verified_on = now() + anne.preferred_address = preferred + self._mlist.subscribe(anne) # Take a look at Anne's current membership. content, response = call_api('http://localhost:9001/3.0/members') self.assertEqual(int(content['total_size']), 1) @@ -182,10 +184,10 @@ class TestMembership(unittest.TestCase): self.assertEqual(entry_0['address'], 'anne@example.com') # Anne registers a new address and makes it her preferred address. # There are no changes to her membership. - new_preferred = anne.register('aperson@example.com') - new_preferred.verified_on = now() - anne.preferred_address = new_preferred - config.db.commit() + with transaction(): + new_preferred = anne.register('aperson@example.com') + new_preferred.verified_on = now() + anne.preferred_address = new_preferred # Take another look at Anne's current membership. content, response = call_api('http://localhost:9001/3.0/members') self.assertEqual(int(content['total_size']), 1) @@ -214,9 +216,9 @@ class TestMembership(unittest.TestCase): def test_patch_member_bogus_attribute(self): # /members/<id> PATCH 'bogus' returns 400 - anne = self._usermanager.create_address('anne@example.com') - self._mlist.subscribe(anne) - config.db.commit() + with transaction(): + anne = self._usermanager.create_address('anne@example.com') + self._mlist.subscribe(anne) try: # For Python 2.6 call_api('http://localhost:9001/3.0/members/1', { diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index 79b0c8b80..dfcedef05 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -31,6 +31,7 @@ from urllib2 import HTTPError from mailman.app.lifecycle import create_list from mailman.app.moderator import hold_message, hold_subscription from mailman.config import config +from mailman.database.transaction import transaction from mailman.interfaces.member import DeliveryMode from mailman.testing.helpers import ( call_api, specialized_message_from_string as mfs) @@ -42,7 +43,8 @@ class TestModeration(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('ant@example.com') + with transaction(): + self._mlist = create_list('ant@example.com') self._msg = mfs("""\ From: anne@example.com To: ant@example.com @@ -51,7 +53,6 @@ Message-ID: <alpha> Something else. """) - config.db.commit() def test_not_found(self): # When a bogus mailing list is given, 404 should result. diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py index 1630eb96a..301027885 100644 --- a/src/mailman/rest/tests/test_users.py +++ b/src/mailman/rest/tests/test_users.py @@ -21,6 +21,7 @@ from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ + 'TestUsers', ] @@ -29,7 +30,7 @@ import unittest from urllib2 import HTTPError from mailman.app.lifecycle import create_list -from mailman.config import config +from mailman.database.transaction import transaction from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer @@ -39,8 +40,8 @@ class TestUsers(unittest.TestCase): layer = RESTLayer def setUp(self): - self._mlist = create_list('test@example.com') - config.db.commit() + with transaction(): + self._mlist = create_list('test@example.com') def test_delete_bogus_user(self): # Try to delete a user that does not exist. diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py index 4e1362120..bce541ae5 100644 --- a/src/mailman/rest/users.py +++ b/src/mailman/rest/users.py @@ -26,7 +26,7 @@ __all__ = [ ] -from flufl.password import lookup, make_secret, generate +from passlib.utils import generate_password as generate from restish import http, resource from uuid import UUID from zope.component import getUtility @@ -102,8 +102,7 @@ class AllUsers(_UserBase): if password is None: # This will have to be reset since it cannot be retrieved. password = generate(int(config.passwords.password_length)) - scheme = lookup(config.passwords.password_scheme.upper()) - user.password = make_secret(password, scheme) + user.password = config.password_context.encrypt(password) location = path_to('users/{0}'.format(user.user_id.int)) return http.created(location, [], None) diff --git a/src/mailman/rest/wsgiapp.py b/src/mailman/rest/wsgiapp.py index 36e8ae5ac..a735d2012 100644 --- a/src/mailman/rest/wsgiapp.py +++ b/src/mailman/rest/wsgiapp.py @@ -33,6 +33,7 @@ from wsgiref.simple_server import WSGIRequestHandler from wsgiref.simple_server import make_server as wsgi_server from mailman.config import config +from mailman.database.transaction import transactional from mailman.rest.root import Root @@ -51,17 +52,11 @@ class AdminWebServiceWSGIRequestHandler(WSGIRequestHandler): class AdminWebServiceApplication(RestishApp): """Connect the restish WSGI application to Mailman's database.""" + @transactional def __call__(self, environ, start_response): """See `RestishApp`.""" - try: - response = super(AdminWebServiceApplication, self).__call__( - environ, start_response) - except: - config.db.abort() - raise - else: - config.db.commit() - return response + return super(AdminWebServiceApplication, self).__call__( + environ, start_response) |
