summaryrefslogtreecommitdiff
path: root/src/mailman/rest/tests/test_users.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/tests/test_users.py')
-rw-r--r--src/mailman/rest/tests/test_users.py67
1 files changed, 60 insertions, 7 deletions
diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py
index 10cc724a3..b4bd50330 100644
--- a/src/mailman/rest/tests/test_users.py
+++ b/src/mailman/rest/tests/test_users.py
@@ -17,9 +17,6 @@
"""REST user tests."""
-from __future__ import absolute_import, print_function, unicode_literals
-
-__metaclass__ = type
__all__ = [
'TestLP1074374',
'TestLogin',
@@ -30,15 +27,14 @@ __all__ = [
import os
import unittest
-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, configuration
from mailman.testing.layers import RESTLayer
+from six.moves.urllib_error import HTTPError
+from zope.component import getUtility
@@ -108,6 +104,48 @@ class TestUsers(unittest.TestCase):
method='DELETE')
self.assertEqual(cm.exception.code, 404)
+ def test_delete_user_twice(self):
+ # You cannot DELETE a user twice, either by address or user id.
+ with transaction():
+ anne = getUtility(IUserManager).create_user(
+ 'anne@example.com', 'Anne Person')
+ user_id = anne.user_id
+ content, response = call_api(
+ 'http://localhost:9001/3.0/users/anne@example.com',
+ method='DELETE')
+ self.assertEqual(response.status, 204)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/users/anne@example.com',
+ method='DELETE')
+ self.assertEqual(cm.exception.code, 404)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/users/{}'.format(user_id),
+ method='DELETE')
+ self.assertEqual(cm.exception.code, 404)
+
+ def test_get_after_delete(self):
+ # You cannot GET a user record after deleting them.
+ with transaction():
+ anne = getUtility(IUserManager).create_user(
+ 'anne@example.com', 'Anne Person')
+ user_id = anne.user_id
+ # You can still GET the user record.
+ content, response = call_api(
+ 'http://localhost:9001/3.0/users/anne@example.com')
+ self.assertEqual(response.status, 200)
+ # Delete the user.
+ content, response = call_api(
+ 'http://localhost:9001/3.0/users/anne@example.com',
+ method='DELETE')
+ self.assertEqual(response.status, 204)
+ # The user record can no longer be retrieved.
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/users/anne@example.com')
+ self.assertEqual(cm.exception.code, 404)
+ with self.assertRaises(HTTPError) as cm:
+ call_api('http://localhost:9001/3.0/users/{}'.format(user_id))
+ self.assertEqual(cm.exception.code, 404)
+
def test_existing_user_error(self):
# Creating a user twice results in an error.
call_api('http://localhost:9001/3.0/users', {
@@ -120,7 +158,7 @@ class TestUsers(unittest.TestCase):
})
self.assertEqual(cm.exception.code, 400)
self.assertEqual(cm.exception.reason,
- 'Address already exists: anne@example.com')
+ b'Address already exists: anne@example.com')
def test_addresses_of_missing_user_id(self):
# Trying to get the /addresses of a missing user id results in error.
@@ -251,6 +289,21 @@ class TestLogin(unittest.TestCase):
'anne@example.com', 'Anne Person')
self.anne.password = config.password_context.encrypt('abc123')
+ def test_login_with_cleartext_password(self):
+ # A user can log in with the correct clear text password.
+ content, response = call_api(
+ 'http://localhost:9001/3.0/users/anne@example.com/login', {
+ 'cleartext_password': 'abc123',
+ }, method='POST')
+ self.assertEqual(response.status, 204)
+ # But the user cannot log in with an incorrect password.
+ with self.assertRaises(HTTPError) as cm:
+ call_api(
+ 'http://localhost:9001/3.0/users/anne@example.com/login', {
+ 'cleartext_password': 'not-the-password',
+ }, method='POST')
+ self.assertEqual(cm.exception.code, 403)
+
def test_wrong_parameter(self):
# A bad request because it is mistyped the required attribute.
with self.assertRaises(HTTPError) as cm: