2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2016-03-01 16:59:56 -05:00
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Banzai::Pipeline::WikiPipeline do
|
2020-05-29 14:08:26 -04:00
|
|
|
let_it_be(:namespace) { create(:namespace, name: "wiki_link_ns") }
|
|
|
|
let_it_be(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
|
2020-08-17 05:10:08 -04:00
|
|
|
let_it_be(:wiki) { ProjectWiki.new(project, nil) }
|
2020-05-29 14:08:26 -04:00
|
|
|
let_it_be(:page) { build(:wiki_page, wiki: wiki, title: 'nested/twice/start-page') }
|
|
|
|
|
2016-03-01 16:59:56 -05:00
|
|
|
describe 'TableOfContents' do
|
|
|
|
it 'replaces the tag with the TableOfContentsFilter result' do
|
|
|
|
markdown = <<-MD.strip_heredoc
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
|
|
## Header
|
|
|
|
|
|
|
|
Foo
|
|
|
|
MD
|
|
|
|
|
2020-05-29 14:08:26 -04:00
|
|
|
result = described_class.call(markdown, project: project, wiki: wiki)
|
2016-03-01 16:59:56 -05:00
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(result[:output].text).not_to include '[['
|
|
|
|
expect(result[:output].text).not_to include 'TOC'
|
|
|
|
expect(result[:output].to_html).to include(result[:toc])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is case-sensitive' do
|
|
|
|
markdown = <<-MD.strip_heredoc
|
|
|
|
[[_toc_]]
|
|
|
|
|
|
|
|
# Header 1
|
|
|
|
|
|
|
|
Foo
|
|
|
|
MD
|
|
|
|
|
2020-05-29 14:08:26 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki)
|
2016-03-01 16:59:56 -05:00
|
|
|
|
|
|
|
expect(output).to include('[[<em>toc</em>]]')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles an empty pipeline result' do
|
|
|
|
# No Markdown headers in this doc, so `result[:toc]` will be empty
|
|
|
|
markdown = <<-MD.strip_heredoc
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
|
|
Foo
|
|
|
|
MD
|
|
|
|
|
2020-05-29 14:08:26 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki)
|
2016-03-01 16:59:56 -05:00
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(output).not_to include('<ul>')
|
2016-03-03 12:36:36 -05:00
|
|
|
expect(output).not_to include('[[<em>TOC</em>]]')
|
2016-03-01 16:59:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-08 00:59:20 -04:00
|
|
|
|
|
|
|
describe "Links" do
|
2020-04-22 08:09:29 -04:00
|
|
|
{ 'when GitLab is hosted at a root URL' => '',
|
|
|
|
'when GitLab is hosted at a relative URL' => '/nested/relative/gitlab' }.each do |test_name, relative_url_root|
|
2019-10-31 17:06:28 -04:00
|
|
|
context test_name do
|
2016-06-08 00:59:20 -04:00
|
|
|
before do
|
2020-06-04 14:08:32 -04:00
|
|
|
allow(Rails.application.routes).to receive(:default_url_options).and_return(script_name: relative_url_root)
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "linking to pages within the wiki" do
|
2019-10-22 23:06:01 -04:00
|
|
|
context "when creating hierarchical links to the current directory" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites non-file links to be at the scope of the current directory" do
|
|
|
|
markdown = "[Page](./page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites file links to be at the scope of the current directory" do
|
|
|
|
markdown = "[Link to Page](./page.md)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when creating hierarchical links to the parent directory" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites non-file links to be at the scope of the parent directory" do
|
|
|
|
markdown = "[Link to Page](../page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites file links to be at the scope of the parent directory" do
|
|
|
|
markdown = "[Link to Page](../page.md)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page.md\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when creating hierarchical links to a sub-directory" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites non-file links to be at the scope of the sub-directory" do
|
|
|
|
markdown = "[Link to Page](./subdirectory/page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2016-06-08 00:59:20 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites file links to be at the scope of the sub-directory" do
|
|
|
|
markdown = "[Link to Page](./subdirectory/page.md)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page.md\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when creating non-hierarchical links" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites non-file links to be at the scope of the wiki root' do
|
|
|
|
markdown = "[Link to Page](page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2016-06-08 00:59:20 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do
|
|
|
|
markdown = "[Link to Page](page slug)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page%20slug\"")
|
2018-08-17 11:19:09 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it "rewrites file links to be at the scope of the current directory" do
|
|
|
|
markdown = "[Link to Page](page.md)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
2016-09-11 19:29:39 -04:00
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites links with anchor' do
|
|
|
|
markdown = '[Link to Header](start-page#title)'
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start-page#title\"")
|
2016-09-11 19:29:39 -04:00
|
|
|
end
|
2018-08-17 11:19:09 -04:00
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites links (with spaces) with anchor' do
|
|
|
|
markdown = '[Link to Header](start page#title)'
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start%20page#title\"")
|
2018-08-17 11:19:09 -04:00
|
|
|
end
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "when creating root links" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites non-file links to be at the scope of the wiki root' do
|
|
|
|
markdown = "[Link to Page](/page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2016-06-08 00:59:20 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites file links to be at the scope of the wiki root' do
|
|
|
|
markdown = "[Link to Page](/page.md)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page.md\"")
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "linking to pages outside the wiki (absolute)" do
|
2019-10-31 17:06:28 -04:00
|
|
|
it "doesn't rewrite links" do
|
|
|
|
markdown = "[Link to Page](http://example.com/page)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-31 17:06:28 -04:00
|
|
|
|
|
|
|
expect(output).to include('href="http://example.com/page"')
|
|
|
|
end
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
|
|
|
|
describe "checking slug validity when assembling links" do
|
|
|
|
context "with a valid slug" do
|
|
|
|
let(:valid_slug) { "http://example.com" }
|
|
|
|
|
|
|
|
it "includes the slug in a (.) relative link" do
|
|
|
|
output = described_class.to_html(
|
|
|
|
"[Link](./alert(1);)",
|
|
|
|
project: project,
|
2020-05-25 17:08:00 -04:00
|
|
|
wiki: wiki,
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
page_slug: valid_slug
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(output).to include(valid_slug)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includeds the slug in a (..) relative link" do
|
|
|
|
output = described_class.to_html(
|
|
|
|
"[Link](../alert(1);)",
|
|
|
|
project: project,
|
2020-05-25 17:08:00 -04:00
|
|
|
wiki: wiki,
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
page_slug: valid_slug
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(output).to include(valid_slug)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the slug is deemed unsafe or invalid" do
|
|
|
|
invalid_slugs = [
|
|
|
|
"javascript:",
|
|
|
|
"JaVaScRiPt:",
|
|
|
|
"\u0001java\u0003script:",
|
|
|
|
"javascript :",
|
|
|
|
"javascript: ",
|
|
|
|
"javascript : ",
|
|
|
|
":javascript:",
|
|
|
|
"javascript:",
|
|
|
|
"javascript:",
|
|
|
|
"javascript:",
|
|
|
|
"javascript:",
|
|
|
|
"java\0script:",
|
|
|
|
"  javascript:"
|
|
|
|
]
|
|
|
|
|
|
|
|
invalid_js_links = [
|
|
|
|
"alert(1);",
|
|
|
|
"alert(document.location);"
|
|
|
|
]
|
|
|
|
|
|
|
|
invalid_slugs.each do |slug|
|
2019-12-22 01:07:52 -05:00
|
|
|
context "with the invalid slug #{slug.delete("\000")}" do
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
invalid_js_links.each do |link|
|
|
|
|
it "doesn't include a prohibited slug in a (.) relative link '#{link}'" do
|
|
|
|
output = described_class.to_html(
|
|
|
|
"[Link](./#{link})",
|
|
|
|
project: project,
|
2020-05-25 17:08:00 -04:00
|
|
|
wiki: wiki,
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
page_slug: slug
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(output).not_to include(slug)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't include a prohibited slug in a (..) relative link '#{link}'" do
|
|
|
|
output = described_class.to_html(
|
|
|
|
"[Link](../#{link})",
|
|
|
|
project: project,
|
2020-05-25 17:08:00 -04:00
|
|
|
wiki: wiki,
|
Extract SanitizeNodeLink and apply to WikiLinkFilter
The SanitizationFilter was running before the WikiFilter. Since
WikiFilter can modify links, we could see links that _should_ be stopped
by SanatizationFilter being rendered on the page. I (kerrizor) had
previously addressed the bug in: https://gitlab.com/gitlab-org/gitlab-ee/commit/7bc971915bbeadb950bb0e1f13510bf3038229a4
However, an additional exploit was discovered after that was merged.
Working through the issue, we couldn't simply shuffle the order of
filters, due to some implicit assumptions about the order of filters, so
instead we've extracted the logic that sanitizes a Nokogiri-generated
Node object, and applied it to the WikiLinkFilter as well.
On moving filters around:
Once we start moving around filters, we get cascading failures; fix one,
another one crops up. Many of the existing filters in the WikiPipeline
chain seem to assume that other filters have already done their work,
and thus operate on a "transform anything that's left" basis;
WikiFilter, for instance, assumes any link it finds in the markdown
should be prepended with the wiki_base_path.. but if it does that, it
also turns `href="@user"` into `href="/path/to/wiki/@user"`, which the
UserReferenceFilter doesn't see as a user reference it needs to
transform into a user profile link. This is true for all the reference
filters in the WikiPipeline.
2019-07-26 09:41:11 -04:00
|
|
|
page_slug: slug
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(output).not_to include(slug)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-08 00:59:20 -04:00
|
|
|
end
|
2018-09-07 10:27:44 -04:00
|
|
|
|
2019-10-09 08:06:13 -04:00
|
|
|
describe 'videos and audio' do
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'generates video html structure' do
|
|
|
|
markdown = "![video_file](video_file_name.mp4)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2018-09-07 10:27:44 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video_file_name.mp4"')
|
2018-09-07 10:27:44 -04:00
|
|
|
end
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
it 'rewrites and replaces video links names with white spaces to %20' do
|
|
|
|
markdown = "![video file](video file name.mp4)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2018-09-07 10:27:44 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video%20file%20name.mp4"')
|
2018-09-07 10:27:44 -04:00
|
|
|
end
|
2019-10-09 08:06:13 -04:00
|
|
|
|
|
|
|
it 'generates audio html structure' do
|
|
|
|
markdown = "![audio_file](audio_file_name.wav)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-09 08:06:13 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio_file_name.wav"')
|
2019-10-09 08:06:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'rewrites and replaces audio links names with white spaces to %20' do
|
|
|
|
markdown = "![audio file](audio file name.wav)"
|
2020-05-25 17:08:00 -04:00
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
2019-10-09 08:06:13 -04:00
|
|
|
|
2019-12-05 13:07:51 -05:00
|
|
|
expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio%20file%20name.wav"')
|
2019-10-09 08:06:13 -04:00
|
|
|
end
|
2018-09-07 10:27:44 -04:00
|
|
|
end
|
2021-03-16 11:11:17 -04:00
|
|
|
|
|
|
|
describe 'gollum tag filters' do
|
|
|
|
context 'when local image file exists' do
|
|
|
|
it 'sets the proper attributes for the image' do
|
|
|
|
gollum_file_double = double('Gollum::File',
|
|
|
|
mime_type: 'image/jpeg',
|
|
|
|
name: 'images/image.jpg',
|
|
|
|
path: 'images/image.jpg',
|
2021-04-07 14:09:45 -04:00
|
|
|
data: '')
|
2021-03-16 11:11:17 -04:00
|
|
|
|
|
|
|
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
|
|
|
|
markdown = "[[#{wiki_file.path}]]"
|
|
|
|
|
|
|
|
expect(wiki).to receive(:find_file).with(wiki_file.path, load_content: false).and_return(wiki_file)
|
|
|
|
|
|
|
|
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
|
|
|
|
doc = Nokogiri::HTML::DocumentFragment.parse(output)
|
|
|
|
|
|
|
|
full_path = "/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/#{wiki_file.path}"
|
|
|
|
expect(doc.css('a')[0].attr('href')).to eq(full_path)
|
|
|
|
expect(doc.css('img')[0].attr('class')).to eq('gfm lazy')
|
|
|
|
expect(doc.css('img')[0].attr('data-src')).to eq(full_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-01 16:59:56 -05:00
|
|
|
end
|