Test next redirects with realistic URL

This change has been made following PR review, to ensure
that special signs are transformed correctly when passing
through the next URL.
This commit is contained in:
Pea Tyczynska
2020-10-12 12:01:39 +01:00
parent 2203fae195
commit 6578719103
5 changed files with 26 additions and 19 deletions

View File

@@ -2,6 +2,8 @@ import pytest
from bs4 import BeautifulSoup
from flask import url_for
from tests.conftest import SERVICE_ONE_ID
def test_should_render_email_verification_resend_show_email_address_and_resend_verify_email(
client,
@@ -29,7 +31,7 @@ def test_should_render_email_verification_resend_show_email_address_and_resend_v
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_should_render_correct_resend_template_for_active_user(
client,
@@ -82,7 +84,7 @@ def test_should_render_correct_resend_template_for_pending_user(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
@pytest.mark.parametrize('phone_number_to_register_with', [
'+447700900460',
@@ -121,7 +123,7 @@ def test_should_resend_verify_code_and_update_mobile_for_pending_user(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_check_and_redirect_to_two_factor_if_user_active(
client,
@@ -141,7 +143,7 @@ def test_check_and_redirect_to_two_factor_if_user_active(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_check_and_redirect_to_verify_if_user_pending(
client,
@@ -180,7 +182,7 @@ def test_redirect_to_sign_in_if_not_logged_in(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_should_render_correct_email_not_received_template_for_active_user(
client,

View File

@@ -4,6 +4,7 @@ from notifications_python_client.errors import HTTPError
import app
from tests import user_json
from tests.conftest import SERVICE_ONE_ID
def test_should_render_forgot_password(client):
@@ -42,11 +43,11 @@ def test_forgot_password_sends_next_link_with_reset_password_email_request(
sample_user = user_json(email_address='test@user.gov.uk')
mocker.patch('app.user_api_client.send_reset_password_url', return_value=None)
response = client.post(
url_for('.forgot_password') + "?next=blob",
url_for('.forgot_password') + f"?next=/services/{SERVICE_ONE_ID}/templates",
data={'email_address': sample_user['email_address']})
assert response.status_code == 200
app.user_api_client.send_reset_password_url.assert_called_once_with(
sample_user['email_address'], next_string="blob"
sample_user['email_address'], next_string=f'/services/{SERVICE_ONE_ID}/templates'
)

View File

@@ -6,7 +6,7 @@ from flask import url_for
from itsdangerous import SignatureExpired
from notifications_utils.url_safe_token import generate_token
from tests.conftest import url_for_endpoint_with_token
from tests.conftest import SERVICE_ONE_ID, url_for_endpoint_with_token
def test_should_render_new_password_template(
@@ -39,7 +39,7 @@ def test_should_return_404_when_email_address_does_not_exist(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_should_redirect_to_two_factor_when_password_reset_is_successful(
app_,

View File

@@ -5,7 +5,7 @@ from bs4 import BeautifulSoup
from flask import url_for
from app.models.user import User
from tests.conftest import normalize_spaces
from tests.conftest import SERVICE_ONE_ID, normalize_spaces
def test_render_sign_in_template_for_new_user(
@@ -31,10 +31,14 @@ def test_render_sign_in_template_with_next_link_for_password_reset(
client_request
):
client_request.logout()
page = client_request.get('main.sign_in', _optional_args="?next=blob", _test_page_title=False)
page = client_request.get(
'main.sign_in',
_optional_args=f"?next=/services/{SERVICE_ONE_ID}/templates",
_test_page_title=False
)
forgot_password_link = page.find('a', class_="govuk-link govuk-link--no-visited-state page-footer-secondary-link")
assert forgot_password_link.text == 'Forgotten your password?'
assert forgot_password_link['href'] == url_for('main.forgot_password') + "?next=blob"
assert forgot_password_link['href'] == url_for('main.forgot_password', next=f'/services/{SERVICE_ONE_ID}/templates')
def test_sign_in_explains_session_timeout(client):
@@ -104,7 +108,7 @@ def test_logged_in_user_redirects_to_account(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
@pytest.mark.parametrize('email_address, password', [
('valid@example.gov.uk', 'val1dPassw0rd!'),
@@ -133,7 +137,7 @@ def test_process_sms_auth_sign_in_return_2fa_template(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_process_email_auth_sign_in_return_2fa_template(
client,
@@ -197,7 +201,7 @@ def test_should_return_redirect_when_user_is_pending(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_should_attempt_redirect_when_user_is_pending(
client,

View File

@@ -12,7 +12,7 @@ from tests.conftest import (
@pytest.mark.parametrize('request_url', ['two_factor_email_sent', 'revalidate_email_sent'])
@pytest.mark.parametrize('redirect_url', [None, 'blob'])
@pytest.mark.parametrize('redirect_url', [None, f'/services/{SERVICE_ONE_ID}/templates'])
@pytest.mark.parametrize('email_resent, page_title', [
(None, 'Check your email'),
(True, 'Email resent')
@@ -38,7 +38,7 @@ def test_two_factor_email_sent_page(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_should_render_two_factor_page(
client,
@@ -353,7 +353,7 @@ def test_valid_two_factor_email_link_logs_in_user(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_two_factor_email_link_has_expired(
app_,
@@ -397,7 +397,7 @@ def test_two_factor_email_link_is_invalid(
@pytest.mark.parametrize('redirect_url', [
None,
'blob',
f'/services/{SERVICE_ONE_ID}/templates',
])
def test_two_factor_email_link_is_already_used(
client,