mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Remove webauthn hooks
This changeset removes webauthn from the Notify.gov admin app. We are not using webauthn at all in our implementation and will be looking at an entirely different authentication system in the near future. Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
@@ -3,13 +3,8 @@ import uuid
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.url_safe_token import generate_token
|
||||
|
||||
from app.models.webauthn_credential import (
|
||||
WebAuthnCredential,
|
||||
WebAuthnCredentials,
|
||||
)
|
||||
from tests.conftest import (
|
||||
create_api_user_active,
|
||||
create_user,
|
||||
@@ -29,10 +24,8 @@ def test_should_show_overview_page(
|
||||
|
||||
def test_overview_page_shows_disable_for_platform_admin(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker
|
||||
platform_admin_user
|
||||
):
|
||||
mocker.patch('app.models.webauthn_credential.WebAuthnCredentials.client_method')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('main.user_profile')
|
||||
assert page.select_one('h1').text.strip() == 'Your profile'
|
||||
@@ -41,30 +34,6 @@ def test_overview_page_shows_disable_for_platform_admin(
|
||||
'Use platform admin view Yes Change whether to use platform admin view'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key_count, expected_row_text', [
|
||||
(0, 'Security keys None registered Change security keys'),
|
||||
(1, 'Security keys 1 registered Change security keys'),
|
||||
(2, 'Security keys 2 registered Change security keys'),
|
||||
])
|
||||
def test_overview_page_shows_security_keys_if_user_they_can_use_webauthn(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
key_count,
|
||||
expected_row_text,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
credentials = [webauthn_credential for _ in range(key_count)]
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=credentials,
|
||||
)
|
||||
page = client_request.get('main.user_profile')
|
||||
security_keys_row = page.select_one('#security-keys')
|
||||
assert ' '.join(security_keys_row.text.split()) == expected_row_text
|
||||
|
||||
|
||||
def test_should_show_name_page(
|
||||
client_request
|
||||
):
|
||||
@@ -448,291 +417,3 @@ def test_can_reenable_platform_admin(client_request, platform_admin_user):
|
||||
|
||||
with client_request.session_transaction() as session:
|
||||
assert session['disable_platform_admin_view'] is False
|
||||
|
||||
|
||||
def test_user_doesnt_see_security_keys_unless_they_can_use_webauthn(
|
||||
client_request,
|
||||
platform_admin_user
|
||||
):
|
||||
platform_admin_user['can_use_webauthn'] = False
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
client_request.get(
|
||||
'.user_profile_security_keys',
|
||||
_expected_status=403,
|
||||
)
|
||||
|
||||
|
||||
def test_should_show_security_keys_page(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
page = client_request.get('.user_profile_security_keys')
|
||||
assert page.select_one('h1').text.strip() == 'Security keys'
|
||||
|
||||
credential_row = page.select('tr')[-1]
|
||||
assert 'Test credential' in credential_row.text
|
||||
assert "Manage" in credential_row.find('a').text
|
||||
assert credential_row.find('a')["href"] == url_for(
|
||||
'.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id']
|
||||
)
|
||||
|
||||
register_button = page.select_one("[data-module='register-security-key']")
|
||||
assert register_button.text.strip() == 'Register a key'
|
||||
|
||||
|
||||
def test_get_key_from_list_of_keys(
|
||||
mocker,
|
||||
webauthn_credential,
|
||||
webauthn_credential_2,
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential, webauthn_credential_2],
|
||||
)
|
||||
assert WebAuthnCredentials(fake_uuid).by_id(webauthn_credential["id"]) == WebAuthnCredential(webauthn_credential)
|
||||
|
||||
|
||||
def test_should_show_manage_security_key_page(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
page = client_request.get('.user_profile_manage_security_key', key_id=webauthn_credential['id'])
|
||||
assert page.select_one('h1').text.strip() == f'Manage ‘{webauthn_credential["name"]}’'
|
||||
|
||||
assert page.select_one('.usa-back-link').text.strip() == 'Back'
|
||||
assert page.select_one('.usa-back-link')['href'] == url_for('.user_profile_security_keys')
|
||||
|
||||
assert page.select_one('#security_key_name')["value"] == webauthn_credential["name"]
|
||||
|
||||
|
||||
def test_manage_security_key_page_404s_when_key_not_found(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
webauthn_credential_2
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential_2],
|
||||
)
|
||||
client_request.get(
|
||||
'.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_expected_status=404,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('endpoint,method', [
|
||||
(".user_profile_manage_security_key", "get"),
|
||||
(".user_profile_manage_security_key", "post"),
|
||||
(".user_profile_confirm_delete_security_key", "get"),
|
||||
(".user_profile_confirm_delete_security_key", "post"),
|
||||
(".user_profile_delete_security_key", "post"),
|
||||
])
|
||||
def test_cant_manage_security_keys_unless_can_use_webauthn(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
endpoint,
|
||||
method
|
||||
):
|
||||
platform_admin_user['can_use_webauthn'] = False
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
if method == "get":
|
||||
client_request.get(
|
||||
endpoint,
|
||||
key_id=webauthn_credential['id'],
|
||||
_expected_status=403,
|
||||
)
|
||||
|
||||
else:
|
||||
client_request.post(
|
||||
endpoint,
|
||||
key_id=webauthn_credential['id'],
|
||||
_expected_status=403,
|
||||
)
|
||||
|
||||
|
||||
def test_should_redirect_after_change_of_security_key_name(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
mock_update = mocker.patch('app.user_api_client.update_webauthn_credential_name_for_user')
|
||||
|
||||
client_request.post(
|
||||
'main.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_data={'security_key_name': "new name"},
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.user_profile_security_keys',
|
||||
)
|
||||
)
|
||||
|
||||
mock_update.assert_called_once_with(
|
||||
credential_id=webauthn_credential['id'],
|
||||
new_name_for_credential="new name",
|
||||
user_id=platform_admin_user["id"]
|
||||
)
|
||||
|
||||
|
||||
def test_user_profile_manage_security_key_should_not_call_api_if_key_name_stays_the_same(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
mock_update = mocker.patch('app.user_api_client.update_webauthn_credential_name_for_user')
|
||||
|
||||
client_request.post(
|
||||
'main.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_data={'security_key_name': webauthn_credential['name']},
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.user_profile_security_keys',
|
||||
)
|
||||
)
|
||||
|
||||
assert not mock_update.called
|
||||
|
||||
|
||||
def test_shows_delete_link_for_security_key(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
page = client_request.get('.user_profile_manage_security_key', key_id=webauthn_credential['id'])
|
||||
assert page.select_one('h1').text.strip() == f'Manage ‘{webauthn_credential["name"]}’'
|
||||
|
||||
link = page.select_one('.page-footer a')
|
||||
assert normalize_spaces(link.text) == 'Delete'
|
||||
assert link['href'] == url_for('.user_profile_confirm_delete_security_key', key_id=webauthn_credential['id'])
|
||||
|
||||
|
||||
def test_confirm_delete_security_key(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'.user_profile_confirm_delete_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_test_page_title=False,
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select_one('.banner-dangerous').text) == (
|
||||
'Are you sure you want to delete this security key? '
|
||||
'Yes, delete'
|
||||
)
|
||||
assert 'action' not in page.select_one('.banner-dangerous form')
|
||||
assert page.select_one('.banner-dangerous form')['method'] == 'post'
|
||||
|
||||
|
||||
def test_delete_security_key(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
mock_delete = mocker.patch('app.user_api_client.delete_webauthn_credential_for_user')
|
||||
|
||||
client_request.post(
|
||||
'.user_profile_delete_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_expected_redirect=url_for(
|
||||
'.user_profile_security_keys',
|
||||
)
|
||||
)
|
||||
mock_delete.assert_called_once_with(
|
||||
credential_id=webauthn_credential['id'],
|
||||
user_id=platform_admin_user["id"]
|
||||
)
|
||||
|
||||
|
||||
def test_delete_security_key_handles_last_credential_error(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
'app.user_api_client.delete_webauthn_credential_for_user',
|
||||
side_effect=HTTPError(
|
||||
response={},
|
||||
message='Cannot delete last remaining webauthn credential for user'
|
||||
)
|
||||
)
|
||||
|
||||
page = client_request.post(
|
||||
'.user_profile_delete_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_follow_redirects=True
|
||||
)
|
||||
assert 'Manage ‘Test credential’' in page.find('h1').text
|
||||
expected_message = "You cannot delete your last security key."
|
||||
assert expected_message in page.find('div', class_="banner-dangerous").text
|
||||
|
||||
Reference in New Issue
Block a user