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

scope_spec.rb « job_token « ci « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 37c5697350658bbeccab77bb81f37fcaff768550 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::JobToken::Scope, feature_category: :continuous_integration do
  let_it_be(:source_project) { create(:project, ci_outbound_job_token_scope_enabled: true) }

  let(:scope) { described_class.new(source_project) }

  describe '#all_projects' do
    subject(:all_projects) { scope.all_projects }

    context 'when no projects are added to the scope' do
      it 'returns the project defining the scope' do
        expect(all_projects).to contain_exactly(source_project)
      end
    end

    context 'when projects are added to the scope' do
      include_context 'with scoped projects'

      it 'returns all projects that can be accessed from a given scope' do
        expect(subject).to contain_exactly(source_project, outbound_scoped_project)
      end
    end
  end

  describe '#allows?' do
    subject { scope.allows?(includes_project) }

    context 'without scoped projects' do
      context 'when self referential' do
        let(:includes_project) { source_project }

        it { is_expected.to be_truthy }
      end
    end

    context 'with scoped projects' do
      include_context 'with scoped projects'

      context 'when project is in outbound scope' do
        let(:includes_project) { outbound_scoped_project }

        it { is_expected.to be_truthy }
      end

      context 'when project is in inbound scope' do
        let(:includes_project) { inbound_scoped_project }

        it { is_expected.to be_falsey }
      end

      context 'when project is linked to a different project' do
        let(:includes_project) { unscoped_project1 }

        it { is_expected.to be_falsey }
      end

      context 'when project is unlinked to a project' do
        let(:includes_project) { unscoped_project2 }

        it { is_expected.to be_falsey }
      end

      context 'when project scope setting is disabled' do
        let(:includes_project) { unscoped_project1 }

        before do
          source_project.ci_outbound_job_token_scope_enabled = false
        end

        it 'considers any project to be part of the scope' do
          expect(subject).to be_truthy
        end
      end
    end
  end
end