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