incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [07/14] git commit: [#6783] ticket:463 added tests
Date Thu, 07 Nov 2013 21:07:20 GMT
[#6783] ticket:463 added tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/b7aced8d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b7aced8d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b7aced8d

Branch: refs/heads/master
Commit: b7aced8df31b5fd767803d4699e511226adca6c5
Parents: 5afc373
Author: coldmind <sokandpal@yandex.ru>
Authored: Sat Oct 26 01:37:29 2013 +0300
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Thu Nov 7 21:05:03 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_auth.py | 62 ++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b7aced8d/Allura/allura/tests/model/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index f8e7ed8..755e0d1 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -20,7 +20,7 @@
 """
 Model tests for auth
 """
-from nose.tools import with_setup, assert_equal
+from nose.tools import with_setup, assert_equal, assert_not_equal
 from pylons import tmpl_context as c, app_globals as g
 from webob import Request
 from mock import patch
@@ -32,6 +32,10 @@ from allura import model as M
 from allura.lib import plugin
 from allura.tests import decorators as td
 from alluratest.controller import setup_basic_test, setup_global_objects
+from allura.tests import TestController
+from allura.lib.helpers import push_config
+from tg import config
+from mock import patch
 
 
 def setUp():
@@ -225,3 +229,59 @@ def test_user_projects_by_role():
     g.credentials.clear()
     assert_equal(set(p.shortname for p in c.user.my_projects()), set(['test', 'test2', 'u/test-admin',
'adobe-1', '--init--']))
     assert_equal(set(p.shortname for p in c.user.my_projects('Admin')), set(['test', 'u/test-admin',
'adobe-1', '--init--']))
+
+
+class TestForgotPassword(TestController):
+
+    @patch('allura.tasks.mail_tasks.sendmail')
+    @patch('allura.lib.helpers.gen_message_id')
+    def test_forgot_password_reset(self, gen_message_id, sendmail):
+        user = M.User.query.get(username='test-admin')
+        password1 = user.password
+        email = M.EmailAddress.query.find({'claimed_by_user_id': user._id}).first()
+        email.confirmed = False
+        user.disabled = True
+
+        r = self.app.post('/auth/password_recovery_hash', {'email': email._id})
+        hash = user.get_tool_data('AuthPasswordReset', 'hash')
+        assert hash is None
+
+        user = M.User.query.get(username='test-admin')
+        user.disabled = True
+        email = M.EmailAddress.query.find({'claimed_by_user_id': user._id}).first()
+        email.confirmed = True
+        r = self.app.post('/auth/password_recovery_hash', {'email': email._id})
+        hash = user.get_tool_data('AuthPasswordReset', 'hash')
+        assert hash is None
+
+        user = M.User.query.get(username='test-admin')
+        user.disabled = False
+        email = M.EmailAddress.query.find({'claimed_by_user_id': user._id}).first()
+        email.confirmed = True
+
+        with push_config(config, **{'auth.recovery_hash_expiry_period': '1'}):
+            r = self.app.post('/auth/password_recovery_hash', {'email': email._id})
+            hash = user.get_tool_data('AuthPasswordReset', 'hash')
+            hash_expiry = user.get_tool_data('AuthPasswordReset', 'hash_expiry')
+            assert hash is not None
+            assert hash_expiry is not None
+
+            r = self.app.post('/auth/forgotten_password/%s' % hash, {'pw': 154321, 'pw2':
154321})
+            user = M.User.query.get(username='test-admin')
+            password2 = user.password
+            assert_not_equal(password1, password2)
+
+            text = '''
+To reset your password on %s, please visit the following URL:
+
+%s/auth/forgotten_password/%s
+
+''' % (config['site_name'], config['base_url'], hash)
+
+            sendmail.post.assert_called_once_with(
+                destinations=[email._id],
+                fromaddr=config['forgemail.return_path'],
+                reply_to='',
+                subject='Password recovery',
+                message_id=gen_message_id(),
+                text=text)


Mime
View raw message