diff options
Diffstat (limited to 'spec/lib/gitlab/ci/components/instance_path_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/components/instance_path_spec.rb | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/spec/lib/gitlab/ci/components/instance_path_spec.rb b/spec/lib/gitlab/ci/components/instance_path_spec.rb index 6bc6f04309d..b9b4c3f7c69 100644 --- a/spec/lib/gitlab/ci/components/instance_path_spec.rb +++ b/spec/lib/gitlab/ci/components/instance_path_spec.rb @@ -42,48 +42,86 @@ RSpec.describe Gitlab::Ci::Components::InstancePath, feature_category: :pipeline end end - context 'when the component is simple (single file template)' do - it 'fetches the component content', :aggregate_failures do + shared_examples 'does not find the component' do + it 'returns nil' do result = path.fetch_content!(current_user: user) - expect(result.content).to eq('image: alpine_1') - expect(result.path).to eq('templates/secret-detection.yml') - expect(path.host).to eq(current_host) - expect(path.project).to eq(project) - expect(path.sha).to eq(project.commit('master').id) + expect(result).to be_nil + end + end + + shared_examples 'finds the component' do + shared_examples 'fetches the component content' do + it 'fetches the component content', :aggregate_failures do + result = path.fetch_content!(current_user: user) + expect(result.content).to eq(file_content) + expect(result.path).to eq(file_path) + expect(path.host).to eq(current_host) + expect(path.project).to eq(project) + expect(path.sha).to eq(project.commit('master').id) + end + end + + it_behaves_like 'fetches the component content' + + context 'when feature flag ci_redirect_component_project is disabled' do + before do + stub_feature_flags(ci_redirect_component_project: false) + end + + it_behaves_like 'fetches the component content' + end + + context 'when the there is a redirect set for the project' do + let!(:redirect_route) { project.redirect_routes.create!(path: 'another-group/new-project') } + let(:project_path) { redirect_route.path } + + it_behaves_like 'fetches the component content' + + context 'when feature flag ci_redirect_component_project is disabled' do + before do + stub_feature_flags(ci_redirect_component_project: false) + end + + it_behaves_like 'does not find the component' + end + end + end + + context 'when the component is simple (single file template)' do + it_behaves_like 'finds the component' do + let(:file_path) { 'templates/secret-detection.yml' } + let(:file_content) { 'image: alpine_1' } end end context 'when the component is complex (directory-based template)' do let(:address) { "acme.com/#{project_path}/dast@#{version}" } - it 'fetches the component content', :aggregate_failures do - result = path.fetch_content!(current_user: user) - expect(result.content).to eq('image: alpine_2') - expect(result.path).to eq('templates/dast/template.yml') - expect(path.host).to eq(current_host) - expect(path.project).to eq(project) - expect(path.sha).to eq(project.commit('master').id) + it_behaves_like 'finds the component' do + let(:file_path) { 'templates/dast/template.yml' } + let(:file_content) { 'image: alpine_2' } end context 'when there is an invalid nested component folder' do let(:address) { "acme.com/#{project_path}/dast/another-folder@#{version}" } - it 'returns nil' do - result = path.fetch_content!(current_user: user) - expect(result.content).to be_nil - end + it_behaves_like 'does not find the component' end context 'when there is an invalid nested component path' do let(:address) { "acme.com/#{project_path}/dast/another-template@#{version}" } - it 'returns nil' do - result = path.fetch_content!(current_user: user) - expect(result.content).to be_nil - end + it_behaves_like 'does not find the component' end end + context "when the project path starts with '/'" do + let(:project_path) { "/#{project.full_path}" } + + it_behaves_like 'does not find the component' + end + + # TODO: remove when deleting the feature flag `ci_redirect_component_project` shared_examples 'prevents infinite loop' do |prefix| context "when the project path starts with '#{prefix}'" do let(:project_path) { "#{prefix}#{project.full_path}" } |