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

global_template_finder_spec.rb « finders « template « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7f58fbd2a5e551950562e52ad1217371005199b (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
require 'spec_helper'

describe Gitlab::Template::Finders::GlobalTemplateFinder do
  let(:base_dir) { Dir.mktmpdir }

  def create_template!(name_with_category)
    full_path = File.join(base_dir, name_with_category)
    FileUtils.mkdir_p(File.dirname(full_path))
    FileUtils.touch(full_path)
  end

  after do
    FileUtils.rm_rf(base_dir)
  end

  subject(:finder) { described_class.new(base_dir, '', 'Foo' => '', 'Bar' => 'bar') }

  describe '.find' do
    it 'finds a template in the Foo category' do
      create_template!('test-template')

      expect(finder.find('test-template')).to be_present
    end

    it 'finds a template in the Bar category' do
      create_template!('bar/test-template')

      expect(finder.find('test-template')).to be_present
    end

    it 'does not permit path traversal requests' do
      expect { finder.find('../foo') }.to raise_error(/Invalid path/)
    end
  end
end