mirror of
https://github.com/wassname/flask-security.git
synced 2026-08-07 11:22:21 +08:00
Add a password-changed signal
This commit is contained in:
@@ -350,6 +350,16 @@ class ChangePasswordTest(SecurityTest):
|
||||
self.assertNotIn('You successfully changed your password', r.data)
|
||||
self.assertIn('Passwords do not match', r.data)
|
||||
|
||||
def test_change_password_bad_password(self):
|
||||
self.authenticate()
|
||||
r = self.client.post('/change', data={
|
||||
'password': 'password',
|
||||
'new_password': 'a',
|
||||
'new_password_confirm': 'a'
|
||||
}, follow_redirects=True)
|
||||
self.assertNotIn('You successfully changed your password', r.data)
|
||||
self.assertIn('Field must be between', r.data)
|
||||
|
||||
def test_change_password_success(self):
|
||||
self.authenticate()
|
||||
r = self.client.post('/change', data={
|
||||
|
||||
+53
-1
@@ -3,7 +3,8 @@ from __future__ import with_statement
|
||||
from flask_security.utils import (capture_registrations, capture_reset_password_requests, capture_signals)
|
||||
from flask_security.signals import (user_registered, user_confirmed,
|
||||
confirm_instructions_sent, login_instructions_sent,
|
||||
password_reset, reset_password_instructions_sent)
|
||||
password_reset, password_changed,
|
||||
reset_password_instructions_sent)
|
||||
from tests import SecurityTest
|
||||
|
||||
|
||||
@@ -158,6 +159,57 @@ class RecoverableSignalsTests(SecurityTest):
|
||||
self.assertEqual(mocks.signals_sent(), set())
|
||||
|
||||
|
||||
class ChangeableSignalsTests(SecurityTest):
|
||||
|
||||
AUTH_CONFIG = {
|
||||
'SECURITY_CHANGEABLE': True,
|
||||
}
|
||||
|
||||
def test_change_password(self):
|
||||
self.authenticate('joe@lp.com')
|
||||
with capture_signals() as mocks:
|
||||
with self.client as client:
|
||||
client.post('/change',
|
||||
data=dict(password='password',
|
||||
new_password='newpassword',
|
||||
new_password_confirm='newpassword'),
|
||||
follow_redirects=True)
|
||||
self.assertEqual(mocks.signals_sent(), set([password_changed]))
|
||||
user = self.app.security.datastore.find_user(email='joe@lp.com')
|
||||
calls = mocks[password_changed]
|
||||
self.assertEqual(len(calls), 1)
|
||||
args, kwargs = calls[0]
|
||||
self.assertTrue(compare_user(args[0], user))
|
||||
self.assertEqual(kwargs['app'], self.app)
|
||||
|
||||
def test_change_password_invalid_password(self):
|
||||
with capture_signals() as mocks:
|
||||
self.client.post('/change',
|
||||
data=dict(password='notpassword',
|
||||
new_password='newpassword',
|
||||
new_password_confirm='newpassword'),
|
||||
follow_redirects=True)
|
||||
self.assertEqual(mocks.signals_sent(), set())
|
||||
|
||||
def test_change_password_bad_password(self):
|
||||
with capture_signals() as mocks:
|
||||
self.client.post('/change',
|
||||
data=dict(password='notpassword',
|
||||
new_password='a',
|
||||
new_password_confirm='a'),
|
||||
follow_redirects=True)
|
||||
self.assertEqual(mocks.signals_sent(), set())
|
||||
|
||||
def test_change_password_mismatch_password(self):
|
||||
with capture_signals() as mocks:
|
||||
self.client.post('/change',
|
||||
data=dict(password='password',
|
||||
new_password='newpassword',
|
||||
new_password_confirm='notnewpassword'),
|
||||
follow_redirects=True)
|
||||
self.assertEqual(mocks.signals_sent(), set())
|
||||
|
||||
|
||||
class PasswordlessTests(SecurityTest):
|
||||
|
||||
AUTH_CONFIG = {
|
||||
|
||||
Reference in New Issue
Block a user