Stop using _external=True in tests

It looks like, by default, Flask no longer makes full URLs, for example
`https://example.com/path`. Instead it does `/path`. This will still
work fine, and if anything is better because it reduces the number of
bytes of HTML we are sending.

It won’t mean that requests go over `http` instead of `https` without
the protocol because we set the appropriate HSTS header here:
0c57da7781/ansible/roles/paas-proxy/templates/admin.conf.j2 (L11)

This commit changes all our tests to reflect that URLs no longer have
the protocol and domain in them. `_external=True` is Flask’s way of
saying whether a URL should be generated with the domain and protocol
(`True`) or without it (`False`).

Again, I can’t find the changelog or diff where this was introuduced,
but if you’d like to go spelunking then here’s a starting point:
50374e3cfe/src/flask/helpers.py (L192)
This commit is contained in:
Chris Hill-Scott
2022-05-27 14:46:35 +01:00
parent 5b5d4af681
commit 8b7f2fbf04
38 changed files with 83 additions and 251 deletions

View File

@@ -26,7 +26,7 @@ def test_logged_in_user_redirects_to_account(
client_request.get(
'main.register',
_expected_status=302,
_expected_redirect=url_for('main.show_accounts_or_dashboard', _external=True),
_expected_redirect=url_for('main.show_accounts_or_dashboard'),
)
@@ -80,7 +80,7 @@ def test_register_continue_handles_missing_session_sensibly(
# session is not set
client_request.get(
'main.registration_continue',
_expected_redirect=url_for('main.show_accounts_or_dashboard', _external=True),
_expected_redirect=url_for('main.show_accounts_or_dashboard'),
)
@@ -196,7 +196,7 @@ def test_register_with_existing_email_sends_emails(
client_request.post(
'main.register',
_data=user_data,
_expected_redirect=url_for('main.registration_continue', _external=True),
_expected_redirect=url_for('main.registration_continue'),
)
@@ -295,7 +295,7 @@ def test_register_from_invite(
auth_type='sms_auth',
**extra_data
),
_expected_redirect=url_for('main.verify', _external=True),
_expected_redirect=url_for('main.verify'),
)
mock_register_user.assert_called_once_with(
'Registered in another Browser',
@@ -329,7 +329,7 @@ def test_register_from_invite_when_user_registers_in_another_browser(
'password': 'somreallyhardthingtoguess',
'auth_type': 'sms_auth'
},
_expected_redirect=url_for('main.verify', _external=True),
_expected_redirect=url_for('main.verify'),
)
@@ -376,7 +376,6 @@ def test_register_from_email_auth_invite(
_expected_redirect=url_for(
'main.service_dashboard',
service_id=sample_invite['service'],
_external=True,
),
)
@@ -448,7 +447,6 @@ def test_can_register_email_auth_without_phone_number(
_expected_redirect=url_for(
'main.service_dashboard',
service_id=sample_invite['service'],
_external=True,
),
)