summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/hook_data/base_builder_spec.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-10-15 11:42:15 +0100
committerSean McGivern <sean@gitlab.com>2018-10-16 10:54:49 +0100
commit0bcfd0adb303f0fcaac40b703deda49f3dd683f4 (patch)
treedc4f44b2019a47e577bf75a7f2964d14a6655c1d /spec/lib/gitlab/hook_data/base_builder_spec.rb
parentc7fd95584eb2a595d84a5693a14b4b46c2885251 (diff)
downloadgitlab-ce-0bcfd0adb303f0fcaac40b703deda49f3dd683f4.tar.gz
Fix image webhook rewriting for uploads
This rewrote URLs to be absolute URLs. However, for uploads (the most common case), we actually need them to point to not just the GitLab instance, but the project they're from. Thankfully, we can normally get that information from the object we're building the hook for.
Diffstat (limited to 'spec/lib/gitlab/hook_data/base_builder_spec.rb')
-rw-r--r--spec/lib/gitlab/hook_data/base_builder_spec.rb129
1 files changed, 83 insertions, 46 deletions
diff --git a/spec/lib/gitlab/hook_data/base_builder_spec.rb b/spec/lib/gitlab/hook_data/base_builder_spec.rb
index a921dd766c3..e3c5ee3b905 100644
--- a/spec/lib/gitlab/hook_data/base_builder_spec.rb
+++ b/spec/lib/gitlab/hook_data/base_builder_spec.rb
@@ -8,57 +8,94 @@ describe Gitlab::HookData::BaseBuilder do
end
end
- subject { subclass.new(nil) }
-
using RSpec::Parameterized::TableSyntax
- where do
- {
- 'relative image URL' => {
- input: '![an image](foo.png)',
- output: "![an image](#{Gitlab.config.gitlab.url}/foo.png)"
- },
- 'HTTP URL' => {
- input: '![an image](http://example.com/foo.png)',
- output: '![an image](http://example.com/foo.png)'
- },
- 'HTTPS URL' => {
- input: '![an image](https://example.com/foo.png)',
- output: '![an image](https://example.com/foo.png)'
- },
- 'protocol-relative URL' => {
- input: '![an image](//example.com/foo.png)',
- output: '![an image](//example.com/foo.png)'
- },
- 'URL reference by title' => {
- input: "![foo]\n\n[foo]: foo.png",
- output: "![foo]\n\n[foo]: foo.png"
- },
- 'URL reference by label' => {
- input: "![][foo]\n\n[foo]: foo.png",
- output: "![][foo]\n\n[foo]: foo.png"
- },
- 'in Markdown inline code block' => {
- input: '`![an image](foo.png)`',
- output: "`![an image](#{Gitlab.config.gitlab.url}/foo.png)`"
- },
- 'in HTML tag on the same line' => {
- input: '<p>![an image](foo.png)</p>',
- output: "<p>![an image](#{Gitlab.config.gitlab.url}/foo.png)</p>"
- },
- 'in Markdown multi-line code block' => {
- input: "```\n![an image](foo.png)\n```",
- output: "```\n![an image](foo.png)\n```"
- },
- 'in HTML tag on different lines' => {
- input: "<p>\n![an image](foo.png)\n</p>",
- output: "<p>\n![an image](foo.png)\n</p>"
+ context 'with an upload prefix specified' do
+ let(:project_with_path) { double(full_path: 'baz/bar') }
+ let(:object_with_project) { double(project: project_with_path) }
+ subject { subclass.new(object_with_project) }
+
+ where do
+ {
+ 'relative image URL' => {
+ input: '![an image](foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/foo.png)"
+ },
+ 'absolute upload URL' => {
+ input: '![an image](/uploads/foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/baz/bar/uploads/foo.png)"
+ },
+ 'absolute non-upload URL' => {
+ input: '![an image](/downloads/foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/downloads/foo.png)"
+ }
}
- }
+ end
+
+ with_them do
+ it { expect(subject.absolute_image_urls(input)).to eq(output) }
+ end
end
- with_them do
- it { expect(subject.absolute_image_urls(input)).to eq(output) }
+ context 'without an upload prefix specified' do
+ subject { subclass.new(nil) }
+
+ where do
+ {
+ 'relative image URL' => {
+ input: '![an image](foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/foo.png)"
+ },
+ 'absolute upload URL' => {
+ input: '![an image](/uploads/foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/uploads/foo.png)"
+ },
+ 'absolute non-upload URL' => {
+ input: '![an image](/downloads/foo.png)',
+ output: "![an image](#{Gitlab.config.gitlab.url}/downloads/foo.png)"
+ },
+ 'HTTP URL' => {
+ input: '![an image](http://example.com/foo.png)',
+ output: '![an image](http://example.com/foo.png)'
+ },
+ 'HTTPS URL' => {
+ input: '![an image](https://example.com/foo.png)',
+ output: '![an image](https://example.com/foo.png)'
+ },
+ 'protocol-relative URL' => {
+ input: '![an image](//example.com/foo.png)',
+ output: '![an image](//example.com/foo.png)'
+ },
+ 'URL reference by title' => {
+ input: "![foo]\n\n[foo]: foo.png",
+ output: "![foo]\n\n[foo]: foo.png"
+ },
+ 'URL reference by label' => {
+ input: "![][foo]\n\n[foo]: foo.png",
+ output: "![][foo]\n\n[foo]: foo.png"
+ },
+ 'in Markdown inline code block' => {
+ input: '`![an image](foo.png)`',
+ output: "`![an image](#{Gitlab.config.gitlab.url}/foo.png)`"
+ },
+ 'in HTML tag on the same line' => {
+ input: '<p>![an image](foo.png)</p>',
+ output: "<p>![an image](#{Gitlab.config.gitlab.url}/foo.png)</p>"
+ },
+ 'in Markdown multi-line code block' => {
+ input: "```\n![an image](foo.png)\n```",
+ output: "```\n![an image](foo.png)\n```"
+ },
+ 'in HTML tag on different lines' => {
+ input: "<p>\n![an image](foo.png)\n</p>",
+ output: "<p>\n![an image](foo.png)\n</p>"
+ }
+ }
+ end
+
+ with_them do
+ it { expect(subject.absolute_image_urls(input)).to eq(output) }
+ end
end
end
end