summaryrefslogtreecommitdiff
path: root/spec/workers/authorized_keys_worker_spec.rb
blob: 4f1dde0bfc0c2be18028b9ba8c7d12c6effb5c66 (plain)
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
# frozen_string_literal: true

require 'spec_helper'

describe AuthorizedKeysWorker 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 '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