Commit 84c0ffe1 authored by Stan Hu's avatar Stan Hu

Merge branch '212178-fix-authorized-keys-worker' into 'master'

Fix updating the authorized_keys file

Closes #212178

See merge request gitlab-org/gitlab!27798
parents 2abade0e 127f1fc6
......@@ -3,7 +3,7 @@
class AuthorizedKeysWorker
include ApplicationWorker
PERMITTED_ACTIONS = [:add_key, :remove_key].freeze
PERMITTED_ACTIONS = %w[add_key remove_key].freeze
feature_category :source_code_management
urgency :high
......@@ -13,11 +13,13 @@ class AuthorizedKeysWorker
def perform(action, *args)
return unless Gitlab::CurrentSettings.authorized_keys_enabled?
case action
when :add_key
case action.to_s
when 'add_key'
authorized_keys.add_key(*args)
when :remove_key
when 'remove_key'
authorized_keys.remove_key(*args)
else
raise "Unknown action: #{action.inspect}"
end
end
......
......@@ -13,7 +13,7 @@ class GitlabShellWorker # rubocop:disable Scalability/IdempotentWorker
# enqueued in the previous release, so handle them here.
#
# See https://gitlab.com/gitlab-org/gitlab/-/issues/25095 for more details
if AuthorizedKeysWorker::PERMITTED_ACTIONS.include?(action)
if AuthorizedKeysWorker::PERMITTED_ACTIONS.include?(action.to_s)
AuthorizedKeysWorker.new.perform(action, *arg)
return
......
---
title: Fix updating the authorized_keys file
merge_request: 27798
author:
type: fixed
......@@ -17,7 +17,7 @@ describe AuthorizedKeysWorker do
expect(instance).to receive(:add_key).with('foo', 'bar')
end
worker.perform(:add_key, 'foo', 'bar')
worker.perform('add_key', 'foo', 'bar')
end
end
......@@ -27,15 +27,17 @@ describe AuthorizedKeysWorker do
expect(instance).to receive(:remove_key).with('foo', 'bar')
end
worker.perform(:remove_key, 'foo', 'bar')
worker.perform('remove_key', 'foo', 'bar')
end
end
describe 'all other commands' do
it 'does nothing' do
it 'raises an error' do
expect(Gitlab::AuthorizedKeys).not_to receive(:new)
worker.perform(:foo, 'bar', 'baz')
expect do
worker.perform('foo', 'bar', 'baz')
end.to raise_error('Unknown action: "foo"')
end
end
end
......@@ -48,7 +50,7 @@ describe AuthorizedKeysWorker do
it 'does nothing' do
expect(Gitlab::AuthorizedKeys).not_to receive(:new)
worker.perform(:add_key, 'foo', 'bar')
worker.perform('add_key', 'foo', 'bar')
end
end
end
......
......@@ -12,7 +12,7 @@ describe GitlabShellWorker do
expect(instance).to receive(:add_key).with('foo', 'bar')
end
worker.perform(:add_key, 'foo', 'bar')
worker.perform('add_key', 'foo', 'bar')
end
end
......@@ -22,7 +22,7 @@ describe GitlabShellWorker do
expect(instance).to receive(:remove_key).with('foo', 'bar')
end
worker.perform(:remove_key, 'foo', 'bar')
worker.perform('remove_key', 'foo', 'bar')
end
end
......@@ -32,7 +32,7 @@ describe GitlabShellWorker do
expect(instance).to receive(:foo).with('bar', 'baz')
end
worker.perform(:foo, 'bar', 'baz')
worker.perform('foo', 'bar', 'baz')
end
end
end
......
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