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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::JobToken::Allowlist, feature_category: :continuous_integration do
include Ci::JobTokenScopeHelpers
using RSpec::Parameterized::TableSyntax
let_it_be(:source_project) { create(:project) }
let(:allowlist) { described_class.new(source_project, direction: direction) }
let(:direction) { :outbound }
describe '#projects' do
subject(:projects) { allowlist.projects }
context 'when no projects are added to the scope' do
[:inbound, :outbound].each do |d|
let(:direction) { d }
it 'returns the project defining the scope' do
expect(projects).to contain_exactly(source_project)
end
end
end
context 'when projects are added to the scope' do
include_context 'with a project in each allowlist'
where(:direction, :additional_project) do
:outbound | ref(:outbound_allowlist_project)
:inbound | ref(:inbound_allowlist_project)
end
with_them do
it 'returns all projects that can be accessed from a given scope' do
expect(projects).to contain_exactly(source_project, additional_project)
end
end
end
end
describe 'add!' do
let_it_be(:added_project) { create(:project) }
let_it_be(:user) { create(:user) }
subject { allowlist.add!(added_project, user: user) }
[:inbound, :outbound].each do |d|
let(:direction) { d }
it 'adds the project' do
subject
expect(allowlist.projects).to contain_exactly(source_project, added_project)
expect(subject.added_by_id).to eq(user.id)
expect(subject.source_project_id).to eq(source_project.id)
expect(subject.target_project_id).to eq(added_project.id)
end
end
end
describe '#includes?' do
subject { allowlist.includes?(includes_project) }
context 'without scoped projects' do
let(:unscoped_project) { build(:project) }
where(:includes_project, :direction, :result) do
ref(:source_project) | :outbound | false
ref(:source_project) | :inbound | false
ref(:unscoped_project) | :outbound | false
ref(:unscoped_project) | :inbound | false
end
with_them do
it { is_expected.to be result }
end
end
context 'with a project in each allowlist' do
include_context 'with a project in each allowlist'
where(:includes_project, :direction, :result) do
ref(:source_project) | :outbound | false
ref(:source_project) | :inbound | false
ref(:inbound_allowlist_project) | :outbound | false
ref(:inbound_allowlist_project) | :inbound | true
ref(:outbound_allowlist_project) | :outbound | true
ref(:outbound_allowlist_project) | :inbound | false
ref(:unscoped_project1) | :outbound | false
ref(:unscoped_project1) | :inbound | false
ref(:unscoped_project2) | :outbound | false
ref(:unscoped_project2) | :inbound | false
end
with_them do
it { is_expected.to be result }
end
end
end
end
|