debian-mirror-gitlab/spec/helpers/commits_helper_spec.rb

86 lines
2.7 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2016-06-02 11:05:42 +05:30
describe CommitsHelper do
describe 'commit_author_link' do
it 'escapes the author email' do
commit = double(
author: nil,
author_name: 'Persistent XSS',
author_email: 'my@email.com" onmouseover="alert(1)'
)
2017-09-10 17:25:29 +05:30
expect(helper.commit_author_link(commit))
.not_to include('onmouseover="alert(1)"')
end
it 'escapes the author name' do
user = build_stubbed(:user, name: 'Foo <script>alert("XSS")</script>')
commit = double(author: user, author_name: '', author_email: '')
expect(helper.commit_author_link(commit))
.to include('Foo &lt;script&gt;')
expect(helper.commit_author_link(commit, avatar: true))
2019-02-15 15:39:39 +05:30
.to include('commit-author-name', 'js-user-link', 'Foo &lt;script&gt;')
2016-06-02 11:05:42 +05:30
end
end
describe 'commit_committer_link' do
it 'escapes the committer email' do
commit = double(
committer: nil,
committer_name: 'Persistent XSS',
committer_email: 'my@email.com" onmouseover="alert(1)'
)
2017-09-10 17:25:29 +05:30
expect(helper.commit_committer_link(commit))
.not_to include('onmouseover="alert(1)"')
end
2018-12-05 23:21:45 +05:30
it 'escapes the committer name' do
2017-09-10 17:25:29 +05:30
user = build_stubbed(:user, name: 'Foo <script>alert("XSS")</script>')
commit = double(committer: user, committer_name: '', committer_email: '')
expect(helper.commit_committer_link(commit))
.to include('Foo &lt;script&gt;')
expect(helper.commit_committer_link(commit, avatar: true))
.to include('commit-committer-name', 'Foo &lt;script&gt;')
2016-06-02 11:05:42 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe '#view_on_environment_button' do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:environment) { create(:environment, external_url: 'http://example.com') }
let(:path) { 'source/file.html' }
let(:sha) { RepoHelpers.sample_commit.id }
before do
allow(environment).to receive(:external_url_for).with(path, sha).and_return('http://example.com/file.html')
end
it 'returns a link tag linking to the file in the environment' do
html = helper.view_on_environment_button(sha, path, environment)
node = Nokogiri::HTML.parse(html).at_css('a')
expect(node[:title]).to eq('View on example.com')
expect(node[:href]).to eq('http://example.com/file.html')
end
end
2020-03-13 15:44:24 +05:30
describe '#commit_to_html' do
let(:project) { create(:project, :repository) }
let(:ref) { 'master' }
let(:commit) { project.commit(ref) }
it 'renders HTML representation of a commit' do
assign(:project, project)
allow(helper).to receive(:current_user).and_return(project.owner)
expect(helper.commit_to_html(commit, ref, project)).to include('<div class="commit-content')
end
end
2016-06-02 11:05:42 +05:30
end