2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
describe Projects::UploadsController do
|
2018-11-08 19:23:39 +05:30
|
|
|
include WorkhorseHelpers
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:model) { create(:project, :public) }
|
|
|
|
let(:params) do
|
|
|
|
{ namespace_id: model.namespace.to_param, project_id: model }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:other_model) { create(:project, :public) }
|
|
|
|
let(:other_params) do
|
|
|
|
{ namespace_id: other_model.namespace.to_param, project_id: other_model }
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like 'handle uploads'
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when the URL the old style, without /-/system' do
|
|
|
|
it 'responds with a redirect to the login page' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :show, params: { namespace_id: 'project', project_id: 'avatar', filename: 'foo.png', secret: 'bar' }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
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
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(500)
|
|
|
|
expect(response.body).to eq('Error uploading file')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
def post_authorize(verified: true)
|
|
|
|
request.headers.merge!(workhorse_internal_api_request_header) if verified
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
post :authorize, params: { namespace_id: model.namespace, project_id: model.path }, format: :json
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|