diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-02-11 18:10:14 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-02-11 18:10:14 +0100 |
commit | 34a6f83d3e79670774e916e0b38016a74ae9dff1 (patch) | |
tree | 93216af8d230c54d45a7daeb4f0a61869d6b4340 | |
parent | 771f14b96e058649ca5db7ce6c99e38108d4abec (diff) | |
download | gitlab-ce-34a6f83d3e79670774e916e0b38016a74ae9dff1.tar.gz |
Fix API
-rw-r--r-- | lib/api/repositories.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/workhorse.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/repositories_spec.rb | 13 | ||||
-rw-r--r-- | spec/support/workhorse_helpers.rb | 16 |
4 files changed, 29 insertions, 6 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 0178289f57f..0d0f0d4616d 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -99,7 +99,7 @@ module API begin RepositoryArchiveCacheWorker.perform_async - header *Gitlab::Workhorse.send_git_archive(@project, params[:ref], params[:format]) + header *Gitlab::Workhorse.send_git_archive(user_project, params[:sha], params[:format]) rescue not_found!('File') end diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 2f3e57156b6..c3ddd4c2680 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -3,9 +3,9 @@ require 'json' module Gitlab class Workhorse - class << self - SEND_DATA_HEADER = 'Gitlab-Workhorse-Send-Data' + SEND_DATA_HEADER = 'Gitlab-Workhorse-Send-Data' + class << self def send_git_blob(repository, blob) params = { 'RepoPath' => repository.path_to_repo, diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 4911cdd9da6..0ae63b0afec 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -4,6 +4,7 @@ require 'mime/types' describe API::API, api: true do include ApiHelpers include RepoHelpers + include WorkhorseHelpers let(:user) { create(:user) } let(:user2) { create(:user) } @@ -91,21 +92,27 @@ describe API::API, api: true do get api("/projects/#{project.id}/repository/archive", user) repo_name = project.repository.name.gsub("\.git", "") expect(response.status).to eq(200) - expect(json_response['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/) + type, params = workhorse_send_data + expect(type).to eq('git-archive') + expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/) end it "should get the archive.zip" do get api("/projects/#{project.id}/repository/archive.zip", user) repo_name = project.repository.name.gsub("\.git", "") expect(response.status).to eq(200) - expect(json_response['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/) + type, params = workhorse_send_data + expect(type).to eq('git-archive') + expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/) end it "should get the archive.tar.bz2" do get api("/projects/#{project.id}/repository/archive.tar.bz2", user) repo_name = project.repository.name.gsub("\.git", "") expect(response.status).to eq(200) - expect(json_response['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/) + type, params = workhorse_send_data + expect(type).to eq('git-archive') + expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/) end it "should return 404 for invalid sha" do diff --git a/spec/support/workhorse_helpers.rb b/spec/support/workhorse_helpers.rb new file mode 100644 index 00000000000..c5c5d4c63d1 --- /dev/null +++ b/spec/support/workhorse_helpers.rb @@ -0,0 +1,16 @@ +module WorkhorseHelpers + extend self + + def workhorse_send_data + @_workhorse_send_data ||= begin + header = response.headers[Gitlab::Workhorse::SEND_DATA_HEADER] + split_header = header.split(':') + type = split_header.shift + header = split_header.join(':') + [ + type, + JSON.parse(Base64.urlsafe_decode64(header)), + ] + end + end +end
\ No newline at end of file |