mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
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:
@@ -3,33 +3,36 @@ import pytest
|
||||
from app import webauthn_server
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app_with_mock_config(mocker):
|
||||
app = mocker.Mock()
|
||||
|
||||
app.config = {
|
||||
'ADMIN_BASE_URL': 'https://www.notify.works',
|
||||
'NOTIFY_ENVIRONMENT': 'development'
|
||||
}
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('environment, allowed'), [
|
||||
('development', True),
|
||||
('production', False)
|
||||
])
|
||||
def test_server_origin_verification(
|
||||
app_,
|
||||
mocker,
|
||||
app_with_mock_config,
|
||||
environment,
|
||||
allowed
|
||||
):
|
||||
mocker.patch.dict(
|
||||
app_.config,
|
||||
values={'NOTIFY_ENVIRONMENT': environment}
|
||||
)
|
||||
|
||||
webauthn_server.init_app(app_)
|
||||
assert app_.webauthn_server._verify('fake-domain') == allowed
|
||||
app_with_mock_config.config['NOTIFY_ENVIRONMENT'] = environment
|
||||
webauthn_server.init_app(app_with_mock_config)
|
||||
assert app_with_mock_config.webauthn_server._verify('fake-domain') == allowed
|
||||
|
||||
|
||||
def test_server_relying_party_id(
|
||||
app_,
|
||||
app_with_mock_config,
|
||||
mocker,
|
||||
):
|
||||
mocker.patch.dict(
|
||||
app_.config,
|
||||
values={'ADMIN_BASE_URL': 'https://www.notify.works'}
|
||||
)
|
||||
|
||||
webauthn_server.init_app(app_)
|
||||
assert app_.webauthn_server.rp.id == 'www.notify.works'
|
||||
webauthn_server.init_app(app_with_mock_config)
|
||||
assert app_with_mock_config.webauthn_server.rp.id == 'www.notify.works'
|
||||
|
||||
Reference in New Issue
Block a user