Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ci_runner_token_author_spec.rb « audit « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f55e1b4493656df20169810edd00e6bfa6a3568b (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Audit::CiRunnerTokenAuthor do
  describe '.initialize' do
    subject { described_class.new(audit_event) }

    let(:details) { }
    let(:audit_event) { instance_double(AuditEvent, details: details, entity_type: 'Project', entity_path: 'd/e') }

    context 'with runner_authentication_token' do
      let(:details) do
        { runner_authentication_token: 'abc1234567' }
      end

      it 'returns CiRunnerTokenAuthor with expected attributes' do
        is_expected.to have_attributes(id: -1, name: 'Authentication token: abc1234567')
      end
    end

    context 'with runner_registration_token' do
      let(:details) do
        { runner_registration_token: 'abc1234567' }
      end

      it 'returns CiRunnerTokenAuthor with expected attributes' do
        is_expected.to have_attributes(id: -1, name: 'Registration token: abc1234567')
      end
    end

    context 'with runner token missing' do
      let(:details) do
        {}
      end

      it 'raises ArgumentError' do
        expect { subject }.to raise_error ArgumentError, 'Runner token missing'
      end
    end
  end

  describe '#full_path' do
    subject { author.full_path }

    let(:author) { described_class.new(audit_event) }

    context 'with instance registration token' do
      let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'User', entity_path: nil) }

      it 'returns correct url' do
        is_expected.to eq('/admin/runners')
      end
    end

    context 'with group registration token' do
      let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'Group', entity_path: 'a/b') }

      it 'returns correct url' do
        expect(::Gitlab::Routing.url_helpers).to receive(:group_settings_ci_cd_path)
          .once
          .with('a/b', { anchor: 'js-runners-settings' })
          .and_return('/path/to/group/runners')

        is_expected.to eq('/path/to/group/runners')
      end
    end

    context 'with project registration token' do
      let(:audit_event) { instance_double(AuditEvent, details: { runner_registration_token: 'abc1234567' }, entity_type: 'Project', entity_path: project.full_path) }
      let(:project) { create(:project) }

      it 'returns correct url' do
        expect(::Gitlab::Routing.url_helpers).to receive(:project_settings_ci_cd_path)
          .once
          .with(project, { anchor: 'js-runners-settings' })
          .and_return('/path/to/project/runners')

        is_expected.to eq('/path/to/project/runners')
      end
    end
  end
end