2015-09-02 02:28:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::RawController do
|
|
|
|
let(:public_project) { create(:project, :public) }
|
|
|
|
|
|
|
|
describe "#show" do
|
|
|
|
context 'regular filename' do
|
|
|
|
let(:id) { 'master/README.md' }
|
|
|
|
|
|
|
|
it 'delivers ASCII file' do
|
|
|
|
get(:show,
|
|
|
|
namespace_id: public_project.namespace.to_param,
|
|
|
|
project_id: public_project.to_param,
|
|
|
|
id: id)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-09-02 02:28:48 -04:00
|
|
|
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
|
|
|
|
expect(response.header['Content-Disposition']).
|
|
|
|
to eq("inline")
|
2016-06-06 07:16:30 -04: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
|
2015-09-03 05:55:43 -04:00
|
|
|
get(:show,
|
|
|
|
namespace_id: public_project.namespace.to_param,
|
|
|
|
project_id: public_project.to_param,
|
|
|
|
id: id)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-09-03 05:55:43 -04:00
|
|
|
expect(response.header['Content-Type']).to eq('image/jpeg')
|
2016-06-06 07:16:30 -04: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') }
|
|
|
|
|
|
|
|
context 'when project has access' do
|
|
|
|
before do
|
|
|
|
public_project.lfs_objects << lfs_object
|
2015-12-08 07:33:12 -05:00
|
|
|
allow_any_instance_of(LfsObjectUploader).to receive(:exists?).and_return(true)
|
2016-03-15 21:16:25 -04:00
|
|
|
allow(controller).to receive(:send_file) { controller.head :ok }
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'serves the file' do
|
2015-12-08 08:00:15 -05:00
|
|
|
expect(controller).to receive(:send_file).with("#{Gitlab.config.shared.path}/lfs-objects/91/ef/f75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897", filename: "lfs_object.iso", disposition: 'attachment')
|
2015-12-07 09:03:50 -05:00
|
|
|
get(:show,
|
|
|
|
namespace_id: public_project.namespace.to_param,
|
|
|
|
project_id: public_project.to_param,
|
|
|
|
id: id)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not have access' do
|
|
|
|
it 'does not serve the file' do
|
|
|
|
get(:show,
|
|
|
|
namespace_id: public_project.namespace.to_param,
|
|
|
|
project_id: public_project.to_param,
|
|
|
|
id: id)
|
|
|
|
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(404)
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-02 02:28:48 -04:00
|
|
|
end
|
|
|
|
end
|