2016-04-17 17:48:51 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
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-06-21 09:48:12 -04:00
|
|
|
expect(helper.commit_author_link(commit))
|
|
|
|
.not_to include('onmouseover="alert(1)"')
|
2016-04-17 17:48:51 -04:00
|
|
|
end
|
2017-09-04 06:28:30 -04:00
|
|
|
|
|
|
|
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 <script>')
|
|
|
|
expect(helper.commit_author_link(commit, avatar: true))
|
|
|
|
.to include('commit-author-name', 'Foo <script>')
|
|
|
|
end
|
2016-04-17 17:48:51 -04:00
|
|
|
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-06-21 09:48:12 -04:00
|
|
|
expect(helper.commit_committer_link(commit))
|
|
|
|
.not_to include('onmouseover="alert(1)"')
|
2016-04-17 17:48:51 -04:00
|
|
|
end
|
2017-09-04 06:28:30 -04:00
|
|
|
|
|
|
|
it 'escapes the commiter name' do
|
|
|
|
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 <script>')
|
|
|
|
expect(helper.commit_committer_link(commit, avatar: true))
|
|
|
|
.to include('commit-committer-name', 'Foo <script>')
|
|
|
|
end
|
2016-04-17 17:48:51 -04:00
|
|
|
end
|
2017-01-29 23:01:31 -05:00
|
|
|
|
2017-02-06 19:06:46 -05:00
|
|
|
describe '#view_on_environment_button' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-01-29 23:01:31 -05:00
|
|
|
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
|
2017-02-06 19:06:46 -05:00
|
|
|
html = helper.view_on_environment_button(sha, path, environment)
|
2017-01-29 23:01:31 -05:00
|
|
|
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
|
2016-04-17 17:48:51 -04:00
|
|
|
end
|