2016-10-26 14:01:01 +01:00
|
|
|
|
import pytest
|
2018-02-20 11:22:17 +00:00
|
|
|
|
from flask import Response, url_for
|
2016-03-16 14:19:41 +00:00
|
|
|
|
from notifications_python_client.errors import HTTPError
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
2016-03-09 09:29:35 +00:00
|
|
|
|
import app
|
2019-12-19 10:22:45 +00:00
|
|
|
|
from tests import user_json
|
2020-10-12 12:01:39 +01:00
|
|
|
|
from tests.conftest import SERVICE_ONE_ID
|
2016-03-09 09:29:35 +00:00
|
|
|
|
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
2022-01-04 15:40:42 +00:00
|
|
|
|
def test_should_render_forgot_password(client_request):
|
|
|
|
|
|
client_request.logout()
|
|
|
|
|
|
page = client_request.get('.forgot_password')
|
|
|
|
|
|
assert 'We’ll send you an email to create a new password.' in page.text
|
2016-01-04 14:00:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-10-26 14:01:01 +01:00
|
|
|
|
@pytest.mark.parametrize('email_address', [
|
2022-08-05 00:25:03 -07:00
|
|
|
|
'test@user.gsa.gov',
|
2020-06-12 09:15:23 +01:00
|
|
|
|
'someuser@notgovernment.com'
|
2016-10-26 14:01:01 +01:00
|
|
|
|
])
|
2016-03-07 18:18:52 +00:00
|
|
|
|
def test_should_redirect_to_password_reset_sent_for_valid_email(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
email_address,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2019-12-19 10:22:45 +00:00
|
|
|
|
sample_user = user_json(email_address=email_address)
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'.forgot_password',
|
|
|
|
|
|
_data={'email_address': sample_user['email_address']},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert 'Click the link in the email to reset your password.' in page.text
|
2020-10-05 15:51:44 +01:00
|
|
|
|
app.user_api_client.send_reset_password_url.assert_called_once_with(sample_user['email_address'], next_string=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_forgot_password_sends_next_link_with_reset_password_email_request(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2020-10-05 15:51:44 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2022-08-05 00:25:03 -07:00
|
|
|
|
sample_user = user_json(email_address='test@user.gsa.gov')
|
2020-10-05 15:51:44 +01:00
|
|
|
|
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.post_url(
|
2020-10-12 12:01:39 +01:00
|
|
|
|
url_for('.forgot_password') + f"?next=/services/{SERVICE_ONE_ID}/templates",
|
2022-01-04 15:40:42 +00:00
|
|
|
|
_data={'email_address': sample_user['email_address']},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
2020-10-05 15:51:44 +01:00
|
|
|
|
app.user_api_client.send_reset_password_url.assert_called_once_with(
|
2020-10-12 12:01:39 +01:00
|
|
|
|
sample_user['email_address'], next_string=f'/services/{SERVICE_ONE_ID}/templates'
|
2020-10-05 15:51:44 +01:00
|
|
|
|
)
|
2016-03-16 14:19:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_should_redirect_to_password_reset_sent_for_missing_email(
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request,
|
2017-02-03 10:42:01 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
):
|
2022-01-04 15:40:42 +00:00
|
|
|
|
client_request.logout()
|
2017-02-03 12:07:21 +00:00
|
|
|
|
mocker.patch('app.user_api_client.send_reset_password_url', side_effect=HTTPError(Response(status=404),
|
|
|
|
|
|
'Not found'))
|
2022-01-04 15:40:42 +00:00
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'.forgot_password',
|
|
|
|
|
|
_data={'email_address': api_user_active['email_address']},
|
|
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert 'Click the link in the email to reset your password.' in page.text
|
2020-10-05 15:51:44 +01:00
|
|
|
|
app.user_api_client.send_reset_password_url.assert_called_once_with(
|
|
|
|
|
|
api_user_active['email_address'], next_string=None
|
|
|
|
|
|
)
|