From adb26802899e33f6cd878b240d24389a5e4e76a0 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Fri, 1 Feb 2013 18:21:43 -0500 Subject: [PATCH] Add change password endpoint --- CHANGES | 4 +++- flask_security/datastore.py | 4 ++-- tests/configured_tests.py | 10 +++++----- tests/functional_tests.py | 8 ++++---- tests/signals_tests.py | 3 ++- tests/unit_tests.py | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index 0bb5452..9f289ca 100644 --- a/CHANGES +++ b/CHANGES @@ -4,7 +4,7 @@ Flask-Security Changelog Here you can see the full list of changes between each Flask-Security release. -Version 1.5.5 +Version 1.6.0 ------------- Not yet released @@ -13,6 +13,8 @@ Not yet released - Flask-Login messages are configurable - AJAX requests must now send a CSRF token for security reasons - Login form messages are now configurable +- Forms can now be extended with more fields +- Added change password endpoint Version 1.5.4 diff --git a/flask_security/datastore.py b/flask_security/datastore.py index d0b3bba..f8c7218 100644 --- a/flask_security/datastore.py +++ b/flask_security/datastore.py @@ -81,11 +81,11 @@ class UserDatastore(object): kwargs['roles'] = roles return kwargs - def find_user(self, **kwargs): + def find_user(self, *args, **kwargs): """Returns a user matching the provided parameters.""" raise NotImplementedError - def find_role(self, name): + def find_role(self, *args, **kwargs): """Returns a role matching the provided name.""" raise NotImplementedError diff --git a/tests/configured_tests.py b/tests/configured_tests.py index 0251c57..2ab3b9d 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -331,7 +331,7 @@ class ChangePasswordTest(SecurityTest): def test_change_password_invalid(self): self.authenticate() - r = self.client.post('/change', data={ + r = self._post('/change', data={ 'password': 'notpassword', 'new_password': 'newpassword', 'new_password_confirm': 'newpassword' @@ -341,7 +341,7 @@ class ChangePasswordTest(SecurityTest): def test_change_password_mismatch(self): self.authenticate() - r = self.client.post('/change', data={ + r = self._post('/change', data={ 'password': 'password', 'new_password': 'newpassword', 'new_password_confirm': 'notnewpassword' @@ -351,7 +351,7 @@ class ChangePasswordTest(SecurityTest): def test_change_password_bad_password(self): self.authenticate() - r = self.client.post('/change', data={ + r = self._post('/change', data={ 'password': 'password', 'new_password': 'a', 'new_password_confirm': 'a' @@ -362,7 +362,7 @@ class ChangePasswordTest(SecurityTest): def test_change_password_success(self): self.authenticate() with self.app.extensions['mail'].record_messages() as outbox: - r = self.client.post('/change', data={ + r = self._post('/change', data={ 'password': 'password', 'new_password': 'newpassword', 'new_password_confirm': 'newpassword' @@ -385,7 +385,7 @@ class ChangePasswordPostViewTest(SecurityTest): def test_change_password_success(self): self.authenticate() - r = self.client.post('/change', data={ + r = self._post('/change', data={ 'password': 'password', 'new_password': 'newpassword', 'new_password_confirm': 'newpassword' diff --git a/tests/functional_tests.py b/tests/functional_tests.py index 1196dfb..2438282 100644 --- a/tests/functional_tests.py +++ b/tests/functional_tests.py @@ -224,11 +224,11 @@ class MongoEngineSecurityTests(DefaultSecurityTests): return create_app(auth_config, **kwargs) -class PeeweeSecurityTests(DefaultSecurityTests): +# class PeeweeSecurityTests(DefaultSecurityTests): - def _create_app(self, auth_config, **kwargs): - from tests.test_app.peewee_app import create_app - return create_app(auth_config, **kwargs) +# def _create_app(self, auth_config, **kwargs): +# from tests.test_app.peewee_app import create_app +# return create_app(auth_config, **kwargs) class DefaultDatastoreTests(SecurityTest): diff --git a/tests/signals_tests.py b/tests/signals_tests.py index 3ea8dac..9e7359f 100644 --- a/tests/signals_tests.py +++ b/tests/signals_tests.py @@ -165,7 +165,8 @@ class ChangeableSignalsTests(SecurityTest): client.post('/change', data=dict(password='password', new_password='newpassword', - new_password_confirm='newpassword')) + new_password_confirm='newpassword', + csrf_token=self.csrf_token)) self.assertEqual(mocks.signals_sent(), set([password_changed])) user = self.app.security.datastore.find_user(email='joe@lp.com') calls = mocks[password_changed] diff --git a/tests/unit_tests.py b/tests/unit_tests.py index d08db38..41e4554 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -55,8 +55,8 @@ class DatastoreTests(unittest.TestCase): self.assertRaises(NotImplementedError, ds.delete, None) def test_unimplemented_user_datastore_methods(self): - self.assertRaises(NotImplementedError, self.ds.find_user) - self.assertRaises(NotImplementedError, self.ds.find_role) + self.assertRaises(NotImplementedError, self.ds.find_user, None) + self.assertRaises(NotImplementedError, self.ds.find_role, None) def test_toggle_active(self): user.active = True