From 6e1d675de97122a966b16b7b732b2b145bbfc201 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Fri, 3 Feb 2017 12:42:11 +0100 Subject: [PATCH 1/2] API: Fix file downloading --- changelogs/unreleased/api-fix-files.yml | 4 ++++ lib/api/helpers.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/api-fix-files.yml diff --git a/changelogs/unreleased/api-fix-files.yml b/changelogs/unreleased/api-fix-files.yml new file mode 100644 index 00000000000..8a9e29109a8 --- /dev/null +++ b/changelogs/unreleased/api-fix-files.yml @@ -0,0 +1,4 @@ +--- +title: 'API: Fix file downloading' +merge_request: Robert Schilling +author: 8267 diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index eb5b947172a..dfab60f7fa5 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -304,7 +304,7 @@ module API header['X-Sendfile'] = path body else - path + file path end end From f5de8f159e9fb79ed523fcb41c4b062eeaf3f811 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Sun, 5 Feb 2017 10:57:14 +0100 Subject: [PATCH 2/2] Ensure the right content is served for the build artifacts API --- spec/requests/api/builds_spec.rb | 1 + spec/support/matchers/match_file.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 spec/support/matchers/match_file.rb diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index bd6e23ee769..acc2b163eaf 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -188,6 +188,7 @@ describe API::Builds, api: true do it 'returns specific build artifacts' do expect(response).to have_http_status(200) expect(response.headers).to include(download_headers) + expect(response.body).to match_file(build.artifacts_file.file.file) end end diff --git a/spec/support/matchers/match_file.rb b/spec/support/matchers/match_file.rb new file mode 100644 index 00000000000..d1888b3376a --- /dev/null +++ b/spec/support/matchers/match_file.rb @@ -0,0 +1,5 @@ +RSpec::Matchers.define :match_file do |expected| + match do |actual| + expect(Digest::MD5.hexdigest(actual)).to eq(Digest::MD5.hexdigest(File.read(expected))) + end +end