2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::OtherMarkup do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:context) { {} }
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'XSS Checks' do
|
2017-08-17 22:00:37 +05:30
|
|
|
links = {
|
|
|
|
'links' => {
|
|
|
|
file: 'file.rdoc',
|
|
|
|
input: 'XSS[JaVaScriPt:alert(1)]',
|
|
|
|
output: "\n" + '<p><a>XSS</a></p>' + "\n"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
links.each do |name, data|
|
|
|
|
it "does not convert dangerous #{name} into HTML" do
|
|
|
|
expect(render(data[:file], data[:input], context)).to eq(data[:output])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
context 'when rendering takes too long' do
|
|
|
|
let_it_be(:file_name) { 'foo.bar' }
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:context) { { project: project } }
|
|
|
|
let_it_be(:text) { +'Noël' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('Gitlab::OtherMarkup::RENDER_TIMEOUT', 0.1)
|
|
|
|
allow(GitHub::Markup).to receive(:render) do
|
|
|
|
sleep(0.2)
|
|
|
|
text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'times out' do
|
|
|
|
# expect twice because of timeout in SyntaxHighlightFilter
|
|
|
|
expect(Gitlab::RenderTimeout).to receive(:timeout).twice.and_call_original
|
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
|
|
|
|
instance_of(Timeout::Error),
|
|
|
|
project_id: context[:project].id, file_name: file_name,
|
|
|
|
class_name: described_class.name.demodulize
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(render(file_name, text, context)).to eq("<p>#{text}</p>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def render(...)
|
|
|
|
described_class.render(...)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|