2021-09-04 01:27:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe Ci::JobToken::Scope, feature_category: :continuous_integration do
|
|
|
|
let_it_be(:source_project) { create(:project, ci_outbound_job_token_scope_enabled: true) }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:scope) { described_class.new(source_project) }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
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
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(all_projects).to contain_exactly(source_project)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'when projects are added to the scope' do
|
|
|
|
include_context 'with scoped projects'
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
it 'returns all projects that can be accessed from a given scope' do
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(subject).to contain_exactly(source_project, outbound_scoped_project)
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe '#allows?' do
|
|
|
|
subject { scope.allows?(includes_project) }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'without scoped projects' do
|
|
|
|
context 'when self referential' do
|
|
|
|
let(:includes_project) { source_project }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'with scoped projects' do
|
|
|
|
include_context 'with scoped projects'
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'when project is in outbound scope' do
|
|
|
|
let(:includes_project) { outbound_scoped_project }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
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
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
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
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
context 'when project scope setting is disabled' do
|
2023-03-04 22:38:38 +05:30
|
|
|
let(:includes_project) { unscoped_project1 }
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
before do
|
2023-03-04 22:38:38 +05:30
|
|
|
source_project.ci_outbound_job_token_scope_enabled = false
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'considers any project to be part of the scope' do
|
|
|
|
expect(subject).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|