Commit 421fbbbf authored by Sean Carroll's avatar Sean Carroll Committed by Peter Leitzen
parent 665cc055
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
class Projects::ReleasesController < Projects::ApplicationController class Projects::ReleasesController < Projects::ApplicationController
# Authorize # Authorize
before_action :require_non_empty_project, except: [:index] before_action :require_non_empty_project, except: [:index]
before_action :release, only: %i[edit show update] before_action :release, only: %i[edit show update downloads]
before_action :authorize_read_release! before_action :authorize_read_release!
before_action do before_action do
push_frontend_feature_flag(:release_issue_summary, project) push_frontend_feature_flag(:release_issue_summary, project)
...@@ -40,6 +40,10 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -40,6 +40,10 @@ class Projects::ReleasesController < Projects::ApplicationController
end end
end end
def downloads
redirect_to link.url
end
protected protected
def releases def releases
...@@ -69,6 +73,14 @@ class Projects::ReleasesController < Projects::ApplicationController ...@@ -69,6 +73,14 @@ class Projects::ReleasesController < Projects::ApplicationController
@release ||= project.releases.find_by_tag!(sanitized_tag_name) @release ||= project.releases.find_by_tag!(sanitized_tag_name)
end end
def link
release.links.find_by_filepath!(sanitized_filepath)
end
def sanitized_filepath
CGI.unescape(params[:filepath])
end
def sanitized_tag_name def sanitized_tag_name
CGI.unescape(params[:tag]) CGI.unescape(params[:tag])
end end
......
---
title: Add filepath redirect url
merge_request: 25541
author:
type: added
...@@ -171,6 +171,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -171,6 +171,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :releases, only: [:index, :show, :edit], param: :tag, constraints: { tag: %r{[^/]+} } do resources :releases, only: [:index, :show, :edit], param: :tag, constraints: { tag: %r{[^/]+} } do
member do member do
get :evidence get :evidence
get :downloads, path: 'downloads/*filepath', format: false
end end
end end
......
...@@ -198,6 +198,63 @@ describe Projects::ReleasesController do ...@@ -198,6 +198,63 @@ describe Projects::ReleasesController do
end end
end end
context 'GET #downloads' do
subject do
get :downloads, params: {
namespace_id: project.namespace,
project_id: project,
tag: tag,
filepath: filepath
}
end
before do
sign_in(user)
end
let(:release) { create(:release, project: project, tag: tag ) }
let(:tag) { 'v11.9.0-rc2' }
let(:db_filepath) { '/binaries/linux-amd64' }
let!(:link) do
create :release_link,
release: release,
name: 'linux-amd64 binaries',
filepath: db_filepath,
url: 'https://downloads.example.com/bin/gitlab-linux-amd64'
end
context 'valid filepath' do
let(:filepath) { CGI.escape('/binaries/linux-amd64') }
it 'redirects to the asset direct link' do
subject
expect(response).to redirect_to(link.url)
end
end
context 'invalid filepath' do
let(:filepath) { CGI.escape('/binaries/win32') }
it 'is not found' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'ignores filepath extension' do
let(:db_filepath) { '/binaries/linux-amd64.json' }
let(:filepath) { CGI.escape(db_filepath) }
it 'redirects to the asset direct link' do
subject
expect(response).to redirect_to(link.url)
end
end
end
describe 'GET #evidence' do describe 'GET #evidence' do
let_it_be(:tag_name) { "v1.1.0-evidence" } let_it_be(:tag_name) { "v1.1.0-evidence" }
let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) } let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) }
......
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