require 'spec_helper' require 'nokogiri' module Gitlab describe Asciidoc do let(:input) { 'ascii' } let(:context) { {} } let(:html) { 'H2O' } context "without project" do before do allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults) end it "converts the input using Asciidoctor and default options" do expected_asciidoc_opts = { safe: :secure, backend: :gitlab_html5, attributes: described_class::DEFAULT_ADOC_ATTRS } expect(Asciidoctor).to receive(:convert) .with(input, expected_asciidoc_opts).and_return(html) expect(render(input, context)).to eq(html) end context "with asciidoc_opts" do it "merges the options with default ones" do expected_asciidoc_opts = { safe: :secure, backend: :gitlab_html5, attributes: described_class::DEFAULT_ADOC_ATTRS } expect(Asciidoctor).to receive(:convert) .with(input, expected_asciidoc_opts).and_return(html) render(input, context) end end context "XSS" do links = { 'links' => { input: 'link:mylink"onmouseover="alert(1)[Click Here]', output: "
\">
\neta_x gamma
')
expect(render(input, context)).to include('2+2
is 4