Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for reset password
  • Loading branch information
fangpenlin committed Sep 21, 2020
1 parent aa6c74d commit ddb8ba6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/functional/test_login.py
Expand Up @@ -111,7 +111,7 @@ def test_reset_password_invalid_token(testapp, user):
assert "Invalid token" in res


def test_reset_password(testapp, user):
def test_reset_password(testapp, user, default_password):
now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
token = jwt.encode(
dict(
Expand All @@ -122,6 +122,7 @@ def test_reset_password(testapp, user):
algorithm="HS256",
)

# Ensure reset password link expires
with freeze_time(now):
testapp.get(url_for("public.reset_password", token=token), status=200)

Expand All @@ -131,3 +132,14 @@ def test_reset_password(testapp, user):
with freeze_time(now + datetime.timedelta(seconds=11)):
res = testapp.get(url_for("public.reset_password", token=token)).follow()
assert "Your reset password link is expired" in res

# Reset password
new_password = "new" + default_password
with freeze_time(now):
res = testapp.get(url_for("public.reset_password", token=token), status=200)
form = res.form
form["password"] = new_password
form["confirm"] = new_password
res = form.submit().follow()
assert "Your password is reset" in res
assert user.check_password(new_password)

0 comments on commit ddb8ba6

Please sign in to comment.