2015-09-02 02:28:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::RawController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:public_project) { create(:project, :public, :repository) }
|
2015-09-02 02:28:48 -04:00
|
|
|
|
2017-03-07 12:57:30 -05:00
|
|
|
describe '#show' do
|
2015-09-02 02:28:48 -04:00
|
|
|
context 'regular filename' do
|
|
|
|
let(:id) { 'master/README.md' }
|
|
|
|
|
|
|
|
it 'delivers ASCII file' do
|
2017-09-07 17:27:04 -04:00
|
|
|
get_show(public_project, id)
|
2015-09-02 02:28:48 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-09-02 02:28:48 -04:00
|
|
|
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(response.header['Content-Disposition'])
|
|
|
|
.to eq('inline')
|
2017-03-07 12:57:30 -05:00
|
|
|
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
|
2015-09-02 02:28:48 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-03 05:55:43 -04:00
|
|
|
|
|
|
|
context 'image header' do
|
|
|
|
let(:id) { 'master/files/images/6049019_460s.jpg' }
|
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'sets image content type header' do
|
2017-09-07 17:27:04 -04:00
|
|
|
get_show(public_project, id)
|
2015-09-03 05:55:43 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2015-09-03 05:55:43 -04:00
|
|
|
expect(response.header['Content-Type']).to eq('image/jpeg')
|
2017-03-07 12:57:30 -05:00
|
|
|
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
|
2015-09-03 05:55:43 -04:00
|
|
|
end
|
|
|
|
end
|
2015-12-07 09:03:50 -05:00
|
|
|
|
|
|
|
context 'lfs object' do
|
2015-12-08 04:58:15 -05:00
|
|
|
let(:id) { 'be93687/files/lfs/lfs_object.iso' }
|
2015-12-07 09:03:50 -05:00
|
|
|
let!(:lfs_object) { create(:lfs_object, oid: '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', size: '1575078') }
|
|
|
|
|
2017-03-07 12:57:30 -05:00
|
|
|
context 'when lfs is enabled' do
|
2015-12-07 09:03:50 -05:00
|
|
|
before do
|
2017-03-07 12:57:30 -05:00
|
|
|
allow_any_instance_of(Project).to receive(:lfs_enabled?).and_return(true)
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
|
2017-03-07 12:57:30 -05:00
|
|
|
context 'when project has access' do
|
|
|
|
before do
|
|
|
|
public_project.lfs_objects << lfs_object
|
|
|
|
allow_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(true)
|
|
|
|
allow(controller).to receive(:send_file) { controller.head :ok }
|
|
|
|
end
|
2015-12-07 09:03:50 -05:00
|
|
|
|
2017-03-07 12:57:30 -05:00
|
|
|
it 'serves the file' do
|
2018-02-02 08:59:43 -05:00
|
|
|
expect(controller).to receive(:send_file).with("#{LfsObjectUploader.root}/91/ef/f75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", filename: 'lfs_object.iso', disposition: 'attachment')
|
2017-09-07 17:27:04 -04:00
|
|
|
get_show(public_project, id)
|
2017-03-07 12:57:30 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-03-07 12:57:30 -05:00
|
|
|
end
|
2017-09-07 17:27:04 -04:00
|
|
|
|
|
|
|
context 'and lfs uses object storage' do
|
2018-05-01 16:27:54 -04:00
|
|
|
let(:lfs_object) { create(:lfs_object, :with_file, oid: '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', size: '1575078') }
|
|
|
|
|
2017-09-07 17:27:04 -04:00
|
|
|
before do
|
|
|
|
stub_lfs_object_storage
|
2018-02-02 08:59:43 -05:00
|
|
|
lfs_object.file.migrate!(LfsObjectUploader::Store::REMOTE)
|
2017-09-07 17:27:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with redirect to file' do
|
|
|
|
get_show(public_project, id)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(302)
|
|
|
|
expect(response.location).to include(lfs_object.reload.file.path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets content disposition' do
|
|
|
|
get_show(public_project, id)
|
|
|
|
|
|
|
|
file_uri = URI.parse(response.location)
|
|
|
|
params = CGI.parse(file_uri.query)
|
|
|
|
|
|
|
|
expect(params["response-content-disposition"].first).to eq 'attachment;filename="lfs_object.iso"'
|
|
|
|
end
|
|
|
|
end
|
2017-03-07 12:57:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not have access' do
|
|
|
|
it 'does not serve the file' do
|
2017-09-07 17:27:04 -04:00
|
|
|
get_show(public_project, id)
|
2017-03-07 12:57:30 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-03-07 12:57:30 -05:00
|
|
|
end
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-07 12:57:30 -05:00
|
|
|
context 'when lfs is not enabled' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Project).to receive(:lfs_enabled?).and_return(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'delivers ASCII file' do
|
2017-09-07 17:27:04 -04:00
|
|
|
get_show(public_project, id)
|
2015-12-07 09:03:50 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-03-07 12:57:30 -05:00
|
|
|
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(response.header['Content-Disposition'])
|
|
|
|
.to eq('inline')
|
2017-03-07 12:57:30 -05:00
|
|
|
expect(response.header[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with('git-blob:')
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-02 02:28:48 -04:00
|
|
|
end
|
2017-09-07 17:27:04 -04:00
|
|
|
|
|
|
|
def get_show(project, id)
|
|
|
|
get(:show, namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id)
|
|
|
|
end
|
2015-09-02 02:28:48 -04:00
|
|
|
end
|