1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedKeysWorker, feature_category: :source_code_management do
let(:worker) { described_class.new }
describe '#perform' do
context 'authorized_keys is enabled' do
before do
stub_application_setting(authorized_keys_enabled: true)
end
describe '#add_key' do
it 'delegates to Gitlab::AuthorizedKeys' do
expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
expect(instance).to receive(:add_key).with('foo', 'bar')
end
worker.perform('add_key', 'foo', 'bar')
end
end
describe '#remove_key' do
it 'delegates to Gitlab::AuthorizedKeys' do
expect_next_instance_of(Gitlab::AuthorizedKeys) do |instance|
expect(instance).to receive(:remove_key).with('foo', 'bar')
end
worker.perform('remove_key', 'foo', 'bar')
end
end
describe 'valid action but it is a symbol not a string' do
it 'raises an error' do
expect(Gitlab::AuthorizedKeys).not_to receive(:new)
expect do
worker.perform(:add_key, 'foo', 'bar')
end.to raise_error('Unknown action: :add_key')
end
end
describe 'all other commands' do
it 'raises an error' do
expect(Gitlab::AuthorizedKeys).not_to receive(:new)
expect do
worker.perform('foo', 'bar', 'baz')
end.to raise_error('Unknown action: "foo"')
end
end
end
context 'authorized_keys is disabled' do
before do
stub_application_setting(authorized_keys_enabled: false)
end
it 'does nothing' do
expect(Gitlab::AuthorizedKeys).not_to receive(:new)
worker.perform('add_key', 'foo', 'bar')
end
end
end
end
|