summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-04-09 07:49:51 +0000
committerDouwe Maan <douwe@gitlab.com>2018-04-09 07:49:51 +0000
commite9947951a596c3c0d290bee1f7faa30fb824c5e3 (patch)
treec0e9373fdbbc5cf931003b4947556ec13dbd22f7
parent86ca1a77c58b508fc1b037c5fffbfb22fd992b42 (diff)
parent5c735af3b507d4d1514d1fd66318679a4a2e648e (diff)
downloadgitlab-ce-e9947951a596c3c0d290bee1f7faa30fb824c5e3.tar.gz
Merge branch 'sh-handle-legacy-archive-requests' into 'master'
Handle legacy repository archive requests with no ref given Closes #45154 See merge request gitlab-org/gitlab-ce!18246
-rw-r--r--app/controllers/projects/repositories_controller.rb9
-rw-r--r--spec/controllers/projects/repositories_controller_spec.rb6
2 files changed, 13 insertions, 2 deletions
diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb
index a6167e9dc6c..937b0e39cbd 100644
--- a/app/controllers/projects/repositories_controller.rb
+++ b/app/controllers/projects/repositories_controller.rb
@@ -16,8 +16,10 @@ class Projects::RepositoriesController < Projects::ApplicationController
def archive
append_sha = params[:append_sha]
- shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
- append_sha = false if @filename == shortname
+ if @ref
+ shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
+ append_sha = false if @filename == shortname
+ end
send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha
rescue => ex
@@ -27,6 +29,9 @@ class Projects::RepositoriesController < Projects::ApplicationController
def assign_archive_vars
@id = params[:id]
+
+ return unless @id
+
@ref, @filename = extract_ref(@id)
rescue InvalidPathError
render_404
diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb
index 31b1b52fdd1..c3b71458e38 100644
--- a/spec/controllers/projects/repositories_controller_spec.rb
+++ b/spec/controllers/projects/repositories_controller_spec.rb
@@ -34,6 +34,12 @@ describe Projects::RepositoriesController do
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
+ it 'handles legacy queries with no ref' do
+ get :archive, namespace_id: project.namespace, project_id: project, format: "zip"
+
+ expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
+ end
+
context "when the service raises an error" do
before do
allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")