2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-01 15:18:49 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe 'projects/ci/lints/show' do
|
2017-08-17 22:00:37 +05:30
|
|
|
include Devise::Test::ControllerHelpers
|
2018-05-09 12:01:36 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:config_processor) { Gitlab::Ci::YamlProcessor.new(YAML.dump(content)) }
|
2016-10-01 15:18:49 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
describe 'XSS protection' do
|
|
|
|
before do
|
2018-05-09 12:01:36 +05:30
|
|
|
assign(:project, project)
|
2016-11-03 12:29:30 +05:30
|
|
|
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
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
context 'when the content is valid' do
|
|
|
|
let(:content) do
|
|
|
|
{
|
|
|
|
build_template: {
|
|
|
|
script: './build.sh',
|
|
|
|
tags: ['dotnet'],
|
|
|
|
only: ['test@dude/repo'],
|
|
|
|
except: ['deploy'],
|
|
|
|
environment: 'testing'
|
|
|
|
}
|
2016-11-03 12:29:30 +05:30
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
before do
|
2018-05-09 12:01:36 +05:30
|
|
|
assign(:project, project)
|
2016-11-03 12:29:30 +05:30
|
|
|
assign(:status, true)
|
|
|
|
assign(:builds, config_processor.builds)
|
|
|
|
assign(:stages, config_processor.stages)
|
|
|
|
assign(:jobs, config_processor.jobs)
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'shows the correct values' do
|
2016-10-01 15:18:49 +05:30
|
|
|
render
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(rendered).to have_content('Status: syntax is correct')
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(rendered).to have_content('Tag list: dotnet')
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(rendered).to have_content('Only policy: refs, test@dude/repo')
|
|
|
|
expect(rendered).to have_content('Except policy: refs, deploy')
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(rendered).to have_content('Environment: testing')
|
|
|
|
expect(rendered).to have_content('When: on_success')
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
context 'when content has warnings' do
|
|
|
|
before do
|
|
|
|
assign(:warnings, ['Warning 1', 'Warning 2'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows warning messages' do
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('Warning:')
|
|
|
|
expect(rendered).to have_content('Warning 1')
|
|
|
|
expect(rendered).to have_content('Warning 2')
|
|
|
|
end
|
|
|
|
end
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'when the content is invalid' do
|
|
|
|
before do
|
2018-05-09 12:01:36 +05:30
|
|
|
assign(:project, project)
|
2016-11-03 12:29:30 +05:30
|
|
|
assign(:status, false)
|
2020-03-13 15:44:24 +05:30
|
|
|
assign(:errors, ['Undefined error'])
|
2020-10-24 23:57:45 +05:30
|
|
|
assign(:warnings, ['Warning 1', 'Warning 2'])
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'shows error message' do
|
2016-10-01 15:18:49 +05:30
|
|
|
render
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(rendered).to have_content('Status: syntax is incorrect')
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(rendered).to have_content('Undefined error')
|
2016-11-03 12:29:30 +05:30
|
|
|
expect(rendered).not_to have_content('Tag list:')
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
it 'shows warning messages' do
|
|
|
|
render
|
|
|
|
|
|
|
|
expect(rendered).to have_content('Warning:')
|
|
|
|
expect(rendered).to have_content('Warning 1')
|
|
|
|
expect(rendered).to have_content('Warning 2')
|
|
|
|
end
|
2016-10-01 15:18:49 +05:30
|
|
|
end
|
|
|
|
end
|