show.html.haml_spec.rb 2.3 KB
Newer Older
1 2 3
require 'spec_helper'

describe 'ci/lints/show' do
4 5
  include Devise::TestHelpers

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
  describe 'XSS protection' do
    let(:config_processor) { Ci::GitlabCiYamlProcessor.new(YAML.dump(content)) }
    before do
      assign(:status, true)
      assign(:builds, config_processor.builds)
      assign(:stages, config_processor.stages)
      assign(:jobs, config_processor.jobs)
    end

    context 'when builds attrbiutes contain HTML nodes' do
      let(:content) do
        {
          rspec: {
            script: '<h1>rspec</h1>',
            stage: 'test'
          }
        }
      end

      it 'does not render HTML elements' do
        render

        expect(rendered).not_to have_css('h1', text: 'rspec')
      end
    end

    context 'when builds attributes do not contain HTML nodes' do
      let(:content) do
        {
          rspec: {
            script: 'rspec',
            stage: 'test'
          }
        }
      end

      it 'shows configuration in the table' do
        render

        expect(rendered).to have_css('td pre', text: 'rspec')
      end
    end
48 49
  end

50
  let(:content) do
K
Katarzyna Kobierska 已提交
51 52
    {
      build_template: {
53 54 55 56 57 58 59 60
        script: './build.sh',
        tags: ['dotnet'],
        only: ['test@dude/repo'],
        except: ['deploy'],
        environment: 'testing'
      }
    }
  end
K
Katarzyna Kobierska 已提交
61

62 63
  let(:config_processor) { Ci::GitlabCiYamlProcessor.new(YAML.dump(content)) }

K
Katarzyna Kobierska 已提交
64
  context 'when the content is valid' do
65 66 67 68
    before do
      assign(:status, true)
      assign(:builds, config_processor.builds)
      assign(:stages, config_processor.stages)
K
Katarzyna Kobierska 已提交
69
      assign(:jobs, config_processor.jobs)
70 71
    end

K
Katarzyna Kobierska 已提交
72
    it 'shows the correct values' do
73 74 75 76 77 78 79 80 81
      render

      expect(rendered).to have_content('Tag list: dotnet')
      expect(rendered).to have_content('Refs only: test@dude/repo')
      expect(rendered).to have_content('Refs except: deploy')
      expect(rendered).to have_content('Environment: testing')
      expect(rendered).to have_content('When: on_success')
    end
  end
K
Katarzyna Kobierska 已提交
82 83 84 85 86 87 88 89 90 91

  context 'when the content is invalid' do
    before do
      assign(:status, false)
      assign(:error, 'Undefined error')
    end

    it 'shows error message' do
      render

K
Katarzyna Kobierska 已提交
92
      expect(rendered).to have_content('Status: syntax is incorrect')
K
Katarzyna Kobierska 已提交
93 94 95 96
      expect(rendered).to have_content('Error: Undefined error')
      expect(rendered).not_to have_content('Tag list:')
    end
  end
97
end