Fix app config leaking between tests

We need to re-initialise the webauthn_server module with original
app config, since this state is global across all tests. Since the
behaviour of the original fixture wasn't specific to verifying the
origin, I've renamed the fixture as part of making it global.

In order to keep the fixture simple, I've rewritten the test for
the webauthn_server module, so they don't touch the app fixture.
This commit is contained in:
Ben Thorner
2021-05-17 11:37:47 +01:00
parent 8502827afb
commit fd6329b92e
4 changed files with 40 additions and 49 deletions

View File

@@ -2,7 +2,6 @@ import pytest
from fido2 import cbor
from flask import url_for
from app import webauthn_server
from app.models.webauthn_credential import RegistrationError
@@ -21,18 +20,10 @@ def test_begin_register_returns_encoded_options(
mocker,
platform_admin_user,
platform_admin_client,
webauthn_dev_server,
):
# override base URL so it's consistent on CI and locally
mocker.patch.dict(
app_.config,
values={'ADMIN_BASE_URL': 'http://localhost:6012'}
)
webauthn_server.init_app(app_)
mocker.patch('app.user_api_client.get_webauthn_credentials_for_user', return_value=[])
response = platform_admin_client.get(
url_for('main.webauthn_begin_register')
)
response = platform_admin_client.get(url_for('main.webauthn_begin_register'))
assert response.status_code == 200
@@ -50,7 +41,7 @@ def test_begin_register_returns_encoded_options(
relying_party_options = webauthn_options['rp']
assert relying_party_options['name'] == 'GOV.UK Notify'
assert relying_party_options['id'] == 'localhost'
assert relying_party_options['id'] == 'webauthn.io'
def test_begin_register_includes_existing_credentials(