diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 18:08:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 18:08:51 +0300 |
commit | 163a7046ac76eb4109184e82ce0af911633e6626 (patch) | |
tree | 9f22bb438db435d518e8f5520b309c6319ae0bd8 /spec/lib/gitlab/template | |
parent | 0637ba1e6e9024f35b2cbf561d9002ec17350bb3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/template')
-rw-r--r-- | spec/lib/gitlab/template/finders/global_template_finder_spec.rb | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/spec/lib/gitlab/template/finders/global_template_finder_spec.rb b/spec/lib/gitlab/template/finders/global_template_finder_spec.rb index 082ffa855b7..580da497944 100644 --- a/spec/lib/gitlab/template/finders/global_template_finder_spec.rb +++ b/spec/lib/gitlab/template/finders/global_template_finder_spec.rb @@ -15,23 +15,87 @@ describe Gitlab::Template::Finders::GlobalTemplateFinder do FileUtils.rm_rf(base_dir) end - subject(:finder) { described_class.new(base_dir, '', 'Foo' => '', 'Bar' => 'bar') } + subject(:finder) { described_class.new(base_dir, '', { 'General' => '', 'Bar' => 'Bar' }, exclusions: exclusions) } + + let(:exclusions) { [] } describe '.find' do - it 'finds a template in the Foo category' do - create_template!('test-template') + context 'with a non-prefixed General template' do + before do + create_template!('test-template') + end - expect(finder.find('test-template')).to be_present - end + it 'finds the template with no prefix' do + expect(finder.find('test-template')).to be_present + end + + it 'does not find a prefixed template' do + expect(finder.find('Bar/test-template')).to be_nil + end + + it 'does not permit path traversal requests' do + expect { finder.find('../foo') }.to raise_error(/Invalid path/) + end - it 'finds a template in the Bar category' do - create_template!('bar/test-template') + context 'while listed as an exclusion' do + let(:exclusions) { %w[test-template] } - expect(finder.find('test-template')).to be_present + it 'does not find the template without a prefix' do + expect(finder.find('test-template')).to be_nil + end + + it 'does not find the template with a prefix' do + expect(finder.find('Bar/test-template')).to be_nil + end + + it 'finds another prefixed template with the same name' do + create_template!('Bar/test-template') + + expect(finder.find('test-template')).to be_nil + expect(finder.find('Bar/test-template')).to be_present + end + end end - it 'does not permit path traversal requests' do - expect { finder.find('../foo') }.to raise_error(/Invalid path/) + context 'with a prefixed template' do + before do + create_template!('Bar/test-template') + end + + it 'finds the template with a prefix' do + expect(finder.find('Bar/test-template')).to be_present + end + + # NOTE: This spec fails, the template Bar/test-template is found + # See Gitlab issue: https://gitlab.com/gitlab-org/gitlab/issues/205719 + xit 'does not find the template without a prefix' do + expect(finder.find('test-template')).to be_nil + end + + it 'does not permit path traversal requests' do + expect { finder.find('../foo') }.to raise_error(/Invalid path/) + end + + context 'while listed as an exclusion' do + let(:exclusions) { %w[Bar/test-template] } + + it 'does not find the template with a prefix' do + expect(finder.find('Bar/test-template')).to be_nil + end + + # NOTE: This spec fails, the template Bar/test-template is found + # See Gitlab issue: https://gitlab.com/gitlab-org/gitlab/issues/205719 + xit 'does not find the template without a prefix' do + expect(finder.find('test-template')).to be_nil + end + + it 'finds another non-prefixed template with the same name' do + create_template!('Bar/test-template') + + expect(finder.find('test-template')).to be_present + expect(finder.find('Bar/test-template')).to be_nil + end + end end end end |