Commit 7b798038 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '273379-incorrect-status-code-ssh-deletion' into 'master'

Return 404 when deleting non-existant SSH key

See merge request gitlab-org/gitlab!46450
parents 122c9c2e e0e5ee4e
...@@ -17,15 +17,13 @@ module CredentialsInventoryActions ...@@ -17,15 +17,13 @@ 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)
notify_deleted_or_revoked_credential(key) alert = if Keys::DestroyService.new(current_user).execute(key)
_('User key was successfully removed.') notify_deleted_or_revoked_credential(key)
else _('User key was successfully removed.')
_('Failed to remove user key.')
end
else else
_('Cannot find user key.') _('Failed to remove user key.')
end 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
......
---
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