2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-06 06:36:11 -05:00
|
|
|
require 'spec_helper'
|
2015-02-16 13:58:40 -05:00
|
|
|
|
|
|
|
describe Projects::UploadsController do
|
2018-06-12 11:54:37 -04:00
|
|
|
include WorkhorseHelpers
|
|
|
|
|
2017-12-06 06:36:11 -05:00
|
|
|
let(:model) { create(:project, :public) }
|
|
|
|
let(:params) do
|
|
|
|
{ namespace_id: model.namespace.to_param, project_id: model }
|
2015-02-16 13:58:40 -05:00
|
|
|
end
|
2015-04-17 05:33:58 -04:00
|
|
|
|
2019-07-11 00:48:50 -04:00
|
|
|
let(:other_model) { create(:project, :public) }
|
|
|
|
let(:other_params) do
|
|
|
|
{ namespace_id: other_model.namespace.to_param, project_id: other_model }
|
|
|
|
end
|
|
|
|
|
2017-12-06 06:36:11 -05:00
|
|
|
it_behaves_like 'handle uploads'
|
2018-02-21 11:09:30 -05:00
|
|
|
|
|
|
|
context 'when the URL the old style, without /-/system' do
|
|
|
|
it 'responds with a redirect to the login page' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { namespace_id: 'project', project_id: 'avatar', filename: 'foo.png', secret: 'bar' }
|
2018-02-21 11:09:30 -05:00
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
2018-06-12 11:54:37 -04:00
|
|
|
|
2020-01-13 04:08:03 -05:00
|
|
|
context 'with a moved project' do
|
|
|
|
let!(:upload) { create(:upload, :issuable_upload, :with_file, model: model) }
|
|
|
|
let(:project) { model }
|
|
|
|
let(:upload_path) { File.basename(upload.path) }
|
|
|
|
let!(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') }
|
|
|
|
|
|
|
|
it 'redirects to a file with the proper extension' do
|
|
|
|
get :show, params: { namespace_id: project.namespace, project_id: project.to_param + 'old', filename: File.basename(upload.path), secret: upload.secret }
|
|
|
|
|
|
|
|
expect(response.location).to eq(show_project_uploads_url(project, upload.secret, upload_path))
|
|
|
|
expect(response.location).to end_with(upload.path)
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-05 09:24:06 -04:00
|
|
|
context "when exception occurs" do
|
|
|
|
before do
|
|
|
|
allow(FileUploader).to receive(:workhorse_authorize).and_raise(SocketError.new)
|
|
|
|
sign_in(create(:user))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "responds with status internal_server_error" do
|
|
|
|
post_authorize
|
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:internal_server_error)
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(response.body).to eq(_('Error uploading file'))
|
2018-09-05 09:24:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-12 11:54:37 -04:00
|
|
|
def post_authorize(verified: true)
|
|
|
|
request.headers.merge!(workhorse_internal_api_request_header) if verified
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :authorize, params: { namespace_id: model.namespace, project_id: model.path }, format: :json
|
2018-06-12 11:54:37 -04:00
|
|
|
end
|
2015-02-16 13:58:40 -05:00
|
|
|
end
|