Commit e0e5ee4e authored by Max Woolf's avatar Max Woolf Committed by Ash McKenzie

Return 404 when deleting non-existant SSH key

Currently when using the UI to delete an SSH key
via the credentials inventory, the HTTP status
code returned is always 201 regardless of the
outcome.

This commits adds a guard clause to render
a 404 Not Found error when attempting to
delete a non-existant SSH key.
parent aa5bde98
...@@ -17,16 +17,14 @@ module CredentialsInventoryActions ...@@ -17,16 +17,14 @@ module CredentialsInventoryActions
def destroy def destroy
key = KeysFinder.new({ users: users, key_type: 'ssh' }).find_by_id(params[:id]) key = KeysFinder.new({ users: users, key_type: 'ssh' }).find_by_id(params[:id])
alert = if key.present? return render_404 if key.nil?
if Keys::DestroyService.new(current_user).execute(key)
alert = if Keys::DestroyService.new(current_user).execute(key)
notify_deleted_or_revoked_credential(key) notify_deleted_or_revoked_credential(key)
_('User key was successfully removed.') _('User key was successfully removed.')
else else
_('Failed to remove user key.') _('Failed to remove user key.')
end end
else
_('Cannot find user key.')
end
redirect_to credentials_inventory_path(filter: 'ssh_keys'), status: :found, notice: alert redirect_to credentials_inventory_path(filter: 'ssh_keys'), status: :found, notice: alert
end end
......
---
title: Return 404 when attempting to delete non-existent SSH key
merge_request: 46450
author:
type: fixed
...@@ -63,8 +63,7 @@ RSpec.shared_examples_for 'credentials inventory controller delete SSH key' do | ...@@ -63,8 +63,7 @@ RSpec.shared_examples_for 'credentials inventory controller delete SSH key' do |
it 'renders a not found message' do it 'renders a not found message' do
subject subject
expect(response).to redirect_to(credentials_path) expect(response).to have_gitlab_http_status(:not_found)
expect(flash[:notice]).to eql 'Cannot find user key.'
end end
end end
end end
......
...@@ -4853,9 +4853,6 @@ msgstr "" ...@@ -4853,9 +4853,6 @@ msgstr ""
msgid "Cannot enable shared runners because parent group does not allow it" msgid "Cannot enable shared runners because parent group does not allow it"
msgstr "" msgstr ""
msgid "Cannot find user key."
msgstr ""
msgid "Cannot have multiple Jira imports running at the same time" msgid "Cannot have multiple Jira imports running at the same time"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment