summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/relative_link_filter_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-01-22 17:49:26 -0800
committerStan Hu <stanhu@gmail.com>2019-01-22 17:56:25 -0800
commit494e00caa3c24480592833cf1b223e34c1a2bfb2 (patch)
treed076abdde96e3875870907ae7dbe68712ceeef5b /spec/lib/banzai/filter/relative_link_filter_spec.rb
parent5cf994043fbf8669120e52f7fc345f9168a0d77b (diff)
downloadgitlab-ce-494e00caa3c24480592833cf1b223e34c1a2bfb2.tar.gz
Fix 404s for snippet uploads when relative URL root used
Personal snippet uploads have neither a group nor a project. If a GitLab instance were configured with a relative URL root (e.g. `/gitlab`), then the Markdown filter would not include this root in the generated path. We fix this by adding this root if there is no group or project. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56280
Diffstat (limited to 'spec/lib/banzai/filter/relative_link_filter_spec.rb')
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index 415ded05e6e..dad0a5535c0 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -353,5 +353,59 @@ describe Banzai::Filter::RelativeLinkFilter do
expect(doc.at_css('a')['href']).to eq 'http://example.com'
end
end
+
+ context 'to a personal snippet' do
+ let(:group) { nil }
+ let(:project) { nil }
+ let(:relative_path) { '/uploads/-/system/personal_snippet/6/674e4f07fbf0a7736c3439212896e51a/example.tar.gz' }
+
+ context 'with an absolute URL' do
+ let(:absolute_path) { Gitlab.config.gitlab.url + relative_path }
+ let(:only_path) { false }
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(absolute_path)
+ end
+ end
+
+ context 'with a relative URL root' do
+ let(:gitlab_root) { '/gitlab' }
+ let(:absolute_path) { Gitlab.config.gitlab.url + gitlab_root + relative_path }
+
+ before do
+ stub_config_setting(relative_url_root: gitlab_root)
+ end
+
+ context 'with an absolute URL' do
+ let(:only_path) { false }
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(absolute_path)
+ end
+ end
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(gitlab_root + relative_path)
+ end
+ end
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(relative_path)
+ end
+
+ it 'does not modify absolute URL' do
+ doc = filter(link('http://example.com'))
+
+ expect(doc.at_css('a')['href']).to eq 'http://example.com'
+ end
+ end
end
end