diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-09-08 08:12:43 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-09-08 08:12:43 -0500 |
commit | f373599bd745b7afa58013c4b6a17d1c59769cdb (patch) | |
tree | 077aeb3825a2cad6871874d0cfa03bcfcd62fba7 /mediagoblin/tests/test_auth.py | |
parent | 34fddf47f0b4f7cfa9fbd865bd9eb8ae96913ce4 (diff) | |
parent | f7ab66707c4d5ef5941e13131dbf9ce2a8c7a875 (diff) | |
download | mediagoblin-f373599bd745b7afa58013c4b6a17d1c59769cdb.tar.lz mediagoblin-f373599bd745b7afa58013c4b6a17d1c59769cdb.tar.xz mediagoblin-f373599bd745b7afa58013c4b6a17d1c59769cdb.zip |
Merge branch 'gullydwarf-cfdv-f357_lost_password_functionality'
Conflicts:
mediagoblin/auth/routing.py
Diffstat (limited to 'mediagoblin/tests/test_auth.py')
-rw-r--r-- | mediagoblin/tests/test_auth.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index eed418c6..fbbe1613 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -15,6 +15,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import urlparse +import datetime from nose.tools import assert_equal @@ -237,6 +238,93 @@ def test_register_views(test_app): ## TODO: Also check for double instances of an email address? + ### Oops, forgot the password + # ------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/forgot_password/', + {'username': 'happygirl'}) + response.follow() + + ## Did we redirect to the proper page? Use the right template? + assert_equal( + urlparse.urlsplit(response.location)[2], + '/auth/forgot_password/email_sent/') + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/auth/fp_email_sent.html') + + ## Make sure link to change password is sent by email + assert len(util.EMAIL_TEST_INBOX) == 1 + message = util.EMAIL_TEST_INBOX.pop() + assert message['To'] == 'happygrrl@example.org' + email_context = util.TEMPLATE_TEST_CONTEXT[ + 'mediagoblin/auth/fp_verification_email.txt'] + #TODO - change the name of verification_url to something forgot-password-ish + assert email_context['verification_url'] in message.get_payload(decode=True) + + path = urlparse.urlsplit(email_context['verification_url'])[2] + get_params = urlparse.urlsplit(email_context['verification_url'])[3] + assert path == u'/auth/forgot_password/verify/' + parsed_get_params = urlparse.parse_qs(get_params) + + # user should have matching parameters + new_user = mg_globals.database.User.find_one({'username': 'happygirl'}) + assert parsed_get_params['userid'] == [unicode(new_user['_id'])] + assert parsed_get_params['token'] == [new_user['fp_verification_key']] + + ### The forgotten password token should be set to expire in ~ 10 days + # A few ticks have expired so there are only 9 full days left... + assert (new_user['fp_token_expire'] - datetime.datetime.now()).days == 9 + + ## Try using a bs password-changing verification key, shouldn't work + util.clear_test_template_context() + response = test_app.get( + "/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode( + new_user['_id']), status=400) + assert response.status == '400 Bad Request' + + ## Try using an expired token to change password, shouldn't work + util.clear_test_template_context() + real_token_expiration = new_user['fp_token_expire'] + new_user['fp_token_expire'] = datetime.datetime.now() + new_user.save() + response = test_app.get("%s?%s" % (path, get_params), status=400) + assert response.status == '400 Bad Request' + new_user['fp_token_expire'] = real_token_expiration + new_user.save() + + ## Verify step 1 of password-change works -- can see form to change password + util.clear_test_template_context() + response = test_app.get("%s?%s" % (path, get_params)) + assert util.TEMPLATE_TEST_CONTEXT.has_key('mediagoblin/auth/change_fp.html') + + ## Verify step 2.1 of password-change works -- report success to user + util.clear_test_template_context() + response = test_app.post( + '/auth/forgot_password/verify/', { + 'userid': parsed_get_params['userid'], + 'password': 'iamveryveryhappy', + 'confirm_password': 'iamveryveryhappy', + 'token': parsed_get_params['token']}) + response.follow() + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/auth/fp_changed_success.html') + + ## Verify step 2.2 of password-change works -- login w/ new password success + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'username': u'happygirl', + 'password': 'iamveryveryhappy'}) + + # User should be redirected + response.follow() + assert_equal( + urlparse.urlsplit(response.location)[2], + '/') + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/root.html') + @setup_fresh_app def test_authentication_views(test_app): |