2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
RSpec.describe Banzai::Filter::References::AbstractReferenceFilter do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
let(:doc) { Nokogiri::HTML.fragment('') }
|
|
|
|
let(:filter) { described_class.new(doc, project: project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-07-02 01:45:43 +05:30
|
|
|
describe '#data_attributes_for' do
|
|
|
|
let_it_be(:issue) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
it 'is not an XSS vector' do
|
|
|
|
allow(described_class).to receive(:object_class).and_return(Issue)
|
|
|
|
|
|
|
|
data_attributes = filter.data_attributes_for('xss <img onerror=alert(1) src=x>', project, issue, link_content: true)
|
|
|
|
|
|
|
|
expect(data_attributes[:original]).to eq('xss &lt;img onerror=alert(1) src=x&gt;')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'abstract methods' do
|
|
|
|
describe '#find_object' do
|
|
|
|
it 'raises NotImplementedError' do
|
|
|
|
expect { filter.find_object(nil, nil) }.to raise_error(NotImplementedError)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
describe '#url_for_object' do
|
|
|
|
it 'raises NotImplementedError' do
|
|
|
|
expect { filter.url_for_object(nil, nil) }.to raise_error(NotImplementedError)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|