mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-15 19:01:04 -04:00
Do not call API if key name did not change
To avoid unnecessary calls to API.
This commit is contained in:
@@ -264,11 +264,12 @@ def user_profile_manage_security_key(key_id):
|
||||
form = ChangeNameOfSecurityKey(name_of_key=security_key["name"])
|
||||
|
||||
if form.validate_on_submit():
|
||||
user_api_client.update_webauthn_credential_for_user(
|
||||
user_id=current_user.id,
|
||||
credential_id=key_id,
|
||||
new_name_for_credential=form.name_of_key.data
|
||||
)
|
||||
if form.name_of_key.data != security_key["name"]:
|
||||
user_api_client.update_webauthn_credential_for_user(
|
||||
user_id=current_user.id,
|
||||
credential_id=key_id,
|
||||
new_name_for_credential=form.name_of_key.data
|
||||
)
|
||||
return redirect(url_for('.user_profile_security_keys'))
|
||||
|
||||
if (request.endpoint == "main.user_profile_confirm_delete_security_key"):
|
||||
|
||||
@@ -469,6 +469,39 @@ def test_should_redirect_after_change_of_security_key_name(
|
||||
)
|
||||
|
||||
|
||||
def test_user_profile_manage_security_key_should_not_call_api_if_key_name_stays_the_same(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
webauthn_credential_2,
|
||||
mocker
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch(
|
||||
'app.user_api_client.get_webauthn_credentials_for_user',
|
||||
return_value=[webauthn_credential, webauthn_credential_2],
|
||||
)
|
||||
|
||||
mock_update = mocker.patch(
|
||||
'app.user_api_client.update_webauthn_credential_for_user',
|
||||
return_value=[webauthn_credential],
|
||||
)
|
||||
|
||||
client_request.post(
|
||||
'main.user_profile_manage_security_key',
|
||||
key_id=webauthn_credential['id'],
|
||||
_data={'name_of_key': webauthn_credential['name']},
|
||||
_expected_status=302,
|
||||
_expected_redirect=url_for(
|
||||
'main.user_profile_security_keys',
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
|
||||
assert not mock_update.called
|
||||
|
||||
|
||||
def test_shows_delete_link_for_security_key(
|
||||
mocker,
|
||||
client_request,
|
||||
|
||||
Reference in New Issue
Block a user