Include token creation date in the url token.

This commit is contained in:
Rebecca Law
2016-03-07 18:20:20 +00:00
parent 10296f0cc2
commit 5c4ac9d938
4 changed files with 30 additions and 30 deletions

View File

@@ -299,7 +299,7 @@ def test_get_user_by_email_not_found_returns_404(notify_api,
assert resp.status_code == 404
json_resp = json.loads(resp.get_data(as_text=True))
assert json_resp['result'] == 'error'
assert json_resp['message'] == 'User not found for email address: {}'.format('no_user@digital.gov.uk')
assert json_resp['message'] == 'User not found for email address'
def test_get_user_by_email_bad_url_returns_404(notify_api,
@@ -430,63 +430,60 @@ def test_set_user_permissions_remove_old(notify_api,
assert query.first().permission == MANAGE_SETTINGS
def test_send_reset_password_should_send_reset_password_link(notify_api,
sample_user,
mocker):
def test_send_user_reset_password_should_send_reset_password_link(notify_api,
sample_user,
mocker,
mock_encryption):
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch('app.celery.tasks.email_reset_password.apply_async')
data = json.dumps({'email': sample_user.email_address})
auth_header = create_authorization_header(
path=url_for('user.send_reset_password'),
path=url_for('user.send_user_reset_password'),
method='POST',
request_body=data)
resp = client.post(
url_for('user.send_reset_password'),
url_for('user.send_user_reset_password'),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
from app.user.rest import _create_reset_password_url
url = _create_reset_password_url(sample_user.email_address)
encrypted = encryption.encrypt({'to': sample_user.email_address, 'reset_password_url': url})
app.celery.tasks.email_reset_password.apply_async.assert_called_once_with([encrypted],
queue='send-reset-password')
app.celery.tasks.email_reset_password.apply_async.assert_called_once_with(['something_encrypted'],
queue='email-reset-password')
def test_send_reset_password_should_return_400_when_user_doesnot_exist(notify_api,
mocker):
def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(notify_api,
mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
bad_email_address = 'bad@email.gov.uk'
data = json.dumps({'email': bad_email_address})
auth_header = create_authorization_header(
path=url_for('user.send_reset_password'),
path=url_for('user.send_user_reset_password'),
method='POST',
request_body=data)
resp = client.post(
url_for('user.send_reset_password'),
url_for('user.send_user_reset_password'),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 404
assert json.loads(resp.get_data(as_text=True))['message'] == 'User not found for email address: {}'.format(
bad_email_address)
assert json.loads(resp.get_data(as_text=True))['message'] == 'User not found for email address'
def test_send_reset_password_should_return_400_when_data_is_not_email_address(notify_api, mocker):
def test_send_user_reset_password_should_return_400_when_data_is_not_email_address(notify_api, mocker):
with notify_api.test_request_context():
with notify_api.test_client() as client:
bad_email_address = 'bad.email.gov.uk'
data = json.dumps({'email': bad_email_address})
auth_header = create_authorization_header(
path=url_for('user.send_reset_password'),
path=url_for('user.send_user_reset_password'),
method='POST',
request_body=data)
resp = client.post(
url_for('user.send_reset_password'),
url_for('user.send_user_reset_password'),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])