Commit 82fb02ff authored by Douwe Maan's avatar Douwe Maan

Merge branch '45507-fix-repository-archive-url' into 'master'

Fix specifying a non-default ref when requesting an archive using the legacy URL

Closes #45507

See merge request gitlab-org/gitlab-ce!18468
parents 4eb02d59 276d4eb8
...@@ -28,11 +28,12 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -28,11 +28,12 @@ class Projects::RepositoriesController < Projects::ApplicationController
end end
def assign_archive_vars def assign_archive_vars
@id = params[:id] if params[:id]
@ref, @filename = extract_ref(params[:id])
return unless @id else
@ref = params[:ref]
@ref, @filename = extract_ref(@id) @filename = nil
end
rescue InvalidPathError rescue InvalidPathError
render_404 render_404
end end
......
---
title: Fix specifying a non-default ref when requesting an archive using the legacy
URL
merge_request: 18468
author:
type: fixed
...@@ -40,6 +40,30 @@ describe Projects::RepositoriesController do ...@@ -40,6 +40,30 @@ describe Projects::RepositoriesController do
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:") expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end end
it 'handles legacy queries with the ref specified as ref in params' do
get :archive, namespace_id: project.namespace, project_id: project, ref: 'feature', format: 'zip'
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'handles legacy queries with the ref specified as id in params' do
get :archive, namespace_id: project.namespace, project_id: project, id: 'feature', format: 'zip'
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
it 'prioritizes the id param over the ref param when both are specified' do
get :archive, namespace_id: project.namespace, project_id: project, id: 'feature', ref: 'feature_conflict', format: 'zip'
expect(response).to have_gitlab_http_status(200)
expect(assigns(:ref)).to eq('feature')
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-archive:")
end
context "when the service raises an error" do context "when the service raises an error" do
before do before do
allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed") allow(Gitlab::Workhorse).to receive(:send_git_archive).and_raise("Archive failed")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment