From c439cafd370807a1052d6605364589a1712a1d10 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 10 Jun 2021 23:51:39 +0100 Subject: [PATCH] always create platform admin users with webauthn in tests --- tests/app/main/views/test_accept_invite.py | 1 - tests/app/main/views/test_two_factor.py | 1 - tests/app/main/views/test_webauthn_credentials.py | 10 +--------- tests/conftest.py | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index 1fff1a06f..6f84a082d 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -713,7 +713,6 @@ def test_platform_admin_user_accepts_and_preserves_auth( sample_invite['email_address'] = platform_admin_user['email_address'] sample_invite['auth_type'] = 'email_auth' service_one['permissions'].append('email_auth') - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user_by_email', return_value=platform_admin_user) diff --git a/tests/app/main/views/test_two_factor.py b/tests/app/main/views/test_two_factor.py index c25e3b4ff..5d5111755 100644 --- a/tests/app/main/views/test_two_factor.py +++ b/tests/app/main/views/test_two_factor.py @@ -282,7 +282,6 @@ def test_two_factor_webauthn_should_have_auth_signin_button( platform_admin_user, mocker, ): - platform_admin_user['auth_type'] = 'webauthn_auth' mock_get_user = mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) with client.session_transaction() as session: session['user_details'] = {'id': platform_admin_user['id'], 'email': platform_admin_user['email_address']} diff --git a/tests/app/main/views/test_webauthn_credentials.py b/tests/app/main/views/test_webauthn_credentials.py index 1b4ba5f31..645ad766e 100644 --- a/tests/app/main/views/test_webauthn_credentials.py +++ b/tests/app/main/views/test_webauthn_credentials.py @@ -209,6 +209,7 @@ def test_begin_authentication_forbidden_for_non_platform_admins(client, api_user def test_begin_authentication_forbidden_for_users_without_webauthn(client, mocker, platform_admin_user): + platform_admin_user['auth_type'] = 'sms_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) with client.session_transaction() as session: @@ -219,7 +220,6 @@ def test_begin_authentication_forbidden_for_users_without_webauthn(client, mocke def test_begin_authentication_returns_encoded_options(client, mocker, webauthn_credential, platform_admin_user): - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) with client.session_transaction() as session: @@ -240,7 +240,6 @@ def test_begin_authentication_returns_encoded_options(client, mocker, webauthn_c def test_begin_authentication_stores_state_in_session(client, mocker, webauthn_credential, platform_admin_user): - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) with client.session_transaction() as session: @@ -265,7 +264,6 @@ def test_complete_authentication_checks_credentials( webauthn_authentication_post_data, platform_admin_user ): - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) mocker.patch('app.models.webauthn_credential.WebAuthnCredentials.client_method', return_value=[webauthn_credential]) mocker.patch( @@ -287,7 +285,6 @@ def test_complete_authentication_403s_if_key_isnt_in_users_credentials( webauthn_authentication_post_data, platform_admin_user ): - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) # user has no keys in the database mocker.patch('app.models.webauthn_credential.WebAuthnCredentials.client_method', return_value=[]) @@ -320,7 +317,6 @@ def test_complete_authentication_clears_session( mock_create_event, platform_admin_user ): - platform_admin_user['auth_type'] = 'webauthn_auth' mocker.patch('app.user_api_client.get_user', return_value=platform_admin_user) mocker.patch('app.user_api_client.get_webauthn_credentials_for_user', return_value=[webauthn_credential]) mocker.patch( @@ -347,8 +343,6 @@ def test_verify_webauthn_login_signs_user_in( url_kwargs, expected_redirect, ): - platform_admin_user['auth_type'] = 'webauthn_auth' - with client.session_transaction() as session: session['user_details'] = { 'id': platform_admin_user['id'], @@ -375,7 +369,6 @@ def test_verify_webauthn_login_signs_user_in_doesnt_sign_user_in_if_api_rejects( mocker, platform_admin_user, ): - platform_admin_user['auth_type'] = 'webauthn_auth' with client.session_transaction() as session: session['user_details'] = { @@ -401,7 +394,6 @@ def test_verify_webauthn_login_signs_user_in_sends_revalidation_email_if_needed( mock_send_verify_code, platform_admin_user, ): - platform_admin_user['auth_type'] = 'webauthn_auth' user_details = { 'id': platform_admin_user['id'], 'email': platform_admin_user['email_address'] diff --git a/tests/conftest.py b/tests/conftest.py index 42395edb3..d7e7959f5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3628,7 +3628,7 @@ def create_active_user_manage_template_permissions(with_unique_id=False): ) -def create_platform_admin_user(with_unique_id=False, auth_type='sms_auth', permissions=None): +def create_platform_admin_user(with_unique_id=False, auth_type='webauthn_auth', permissions=None): return create_user( id=str(uuid4()) if with_unique_id else sample_uuid(), name='Platform admin user',