-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
159 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import datetime | ||
|
||
from apis.authentication import set_now | ||
from model.db import db | ||
|
||
|
||
# ------------------- Password Change ------------------- # | ||
|
||
|
||
|
@@ -118,6 +122,131 @@ def test_post_login_new_password(clients): | |
assert len(session_entries) == 1 | ||
|
||
|
||
def test_post_reset_password(flask_app): | ||
""" | ||
Given a Flask application configured for testing | ||
WHEN the '/auth/password/reset-password' endpoint is requested (POST) | ||
THEN check that the response is valid and the password is changed | ||
""" | ||
_test_client = flask_app.test_client() | ||
|
||
forgot_response = _test_client.post( | ||
"/auth/forgot-password", | ||
json={ | ||
"email_address": "[email protected]", | ||
|
||
}, | ||
) | ||
assert forgot_response.status_code == 200 | ||
|
||
token = forgot_response.headers["X-Token"] | ||
assert token is not None | ||
|
||
reset_response = _test_client.post( | ||
"/auth/reset-password", | ||
json={ | ||
"token": token, | ||
"confirm_password": "Updatedpassword4testing!1", | ||
"new_password": "Updatedpassword4testing!1", | ||
}, | ||
) | ||
assert reset_response.status_code == 200 | ||
|
||
response = _test_client.post( | ||
"/auth/login", | ||
json={ | ||
"email_address": "[email protected]", | ||
"password": "Updatedpassword4testing!1", | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
logout_response = _test_client.post( | ||
"/auth/logout" | ||
) | ||
assert logout_response.status_code == 204 | ||
|
||
|
||
def test_post_reset_password_is_not_same_old(flask_app): | ||
""" | ||
Given a Flask application configured for testing | ||
WHEN the '/auth/password/reset-password' endpoint is requested (POST) | ||
THEN check that the response is valid and the password is changed | ||
""" | ||
_test_client = flask_app.test_client() | ||
|
||
forgot_response = _test_client.post( | ||
"/auth/forgot-password", | ||
json={ | ||
"email_address": "[email protected]", | ||
|
||
}, | ||
) | ||
assert forgot_response.status_code == 200 | ||
|
||
token = forgot_response.headers["X-Token"] | ||
assert token is not None | ||
|
||
reset_response = _test_client.post( | ||
"/auth/reset-password", | ||
json={ | ||
"token": token, | ||
"confirm_password": "uniquepassword4testing!", | ||
"new_password": "uniquepassword4testing!", | ||
}, | ||
) | ||
|
||
assert reset_response.status_code == 200 | ||
|
||
reset_response_old = _test_client.post( | ||
"/auth/reset-password", | ||
json={ | ||
"token": token, | ||
"confirm_password": "uniquepassword4testing!", | ||
"new_password": "uniquepassword4testing!", | ||
}, | ||
) | ||
|
||
assert reset_response_old.status_code == 422 | ||
|
||
|
||
def test_post_reset_password_expired(flask_app): | ||
""" | ||
Given a Flask application configured for testing | ||
WHEN the '/auth/password/reset-password' endpoint is requested (POST) | ||
THEN check that the response is valid and the password is changed | ||
""" | ||
_test_client = flask_app.test_client() | ||
|
||
set_now(datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta( | ||
minutes=6 | ||
)) | ||
forgot_response = _test_client.post( | ||
"/auth/forgot-password", | ||
json={ | ||
"email_address": "[email protected]", | ||
|
||
}, | ||
) | ||
set_now(None) | ||
|
||
assert forgot_response.status_code == 200 | ||
|
||
token = forgot_response.headers["X-Token"] | ||
|
||
assert token is not None | ||
|
||
reset_response = _test_client.post( | ||
"/auth/reset-password", | ||
json={ | ||
"token": token, | ||
"confirm_password": "Updatedpassword4testing!", | ||
"new_password": "Updatedpassword4testing!", | ||
}, | ||
) | ||
assert reset_response.status_code == 401 | ||
|
||
|
||
def test_post_logout(clients): | ||
""" | ||
Given a Flask application configured for testing | ||
|