2019-03-19 13:02:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::GitHttpController do
|
2020-01-06 04:07:42 -05:00
|
|
|
include GitHttpHelpers
|
|
|
|
|
2019-12-27 10:08:16 -05:00
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
|
|
|
let(:project_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project.path + '.git'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:params) { project_params }
|
|
|
|
|
2019-03-19 13:02:17 -04:00
|
|
|
describe 'HEAD #info_refs' do
|
|
|
|
it 'returns 403' do
|
|
|
|
head :info_refs, params: { namespace_id: project.namespace.to_param, project_id: project.path + '.git' }
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
2019-08-08 15:56:36 -04:00
|
|
|
|
|
|
|
describe 'GET #info_refs' do
|
2019-12-27 10:08:16 -05:00
|
|
|
let(:params) { project_params.merge(service: 'git-upload-pack') }
|
|
|
|
|
2019-08-08 15:56:36 -04:00
|
|
|
it 'returns 401 for unauthenticated requests to public repositories when http protocol is disabled' do
|
|
|
|
stub_application_setting(enabled_git_access_protocol: 'ssh')
|
|
|
|
|
2019-12-27 10:08:16 -05:00
|
|
|
get :info_refs, params: params
|
2019-08-08 15:56:36 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq(401)
|
|
|
|
end
|
2019-10-08 08:06:01 -04:00
|
|
|
|
2020-01-06 04:07:42 -05:00
|
|
|
context 'with authorized user' do
|
|
|
|
let(:user) { project.owner }
|
|
|
|
|
|
|
|
before do
|
|
|
|
request.headers.merge! auth_env(user.username, user.password, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200' do
|
|
|
|
get :info_refs, params: params
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates the user activity' do
|
|
|
|
expect_next_instance_of(Users::ActivityService) do |activity_service|
|
|
|
|
expect(activity_service).to receive(:execute)
|
|
|
|
end
|
|
|
|
|
|
|
|
get :info_refs, params: params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-08 08:06:01 -04:00
|
|
|
context 'with exceptions' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 503 with GRPC Unavailable' do
|
|
|
|
allow(controller).to receive(:access_check).and_raise(GRPC::Unavailable)
|
|
|
|
|
2019-12-27 10:08:16 -05:00
|
|
|
get :info_refs, params: params
|
2019-10-08 08:06:01 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq(503)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 503 with timeout error' do
|
|
|
|
allow(controller).to receive(:access_check).and_raise(Gitlab::GitAccess::TimeoutError)
|
|
|
|
|
2019-12-27 10:08:16 -05:00
|
|
|
get :info_refs, params: params
|
2019-10-08 08:06:01 -04:00
|
|
|
|
|
|
|
expect(response.status).to eq(503)
|
|
|
|
expect(response.body).to eq 'Gitlab::GitAccess::TimeoutError'
|
|
|
|
end
|
|
|
|
end
|
2019-08-08 15:56:36 -04:00
|
|
|
end
|
2019-12-27 10:08:16 -05:00
|
|
|
|
|
|
|
describe 'POST #git_upload_pack' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:authenticate_user).and_return(true)
|
|
|
|
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
|
|
|
|
allow(controller).to receive(:access_check).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
post :git_upload_pack, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates project statistics' do
|
|
|
|
expect(ProjectDailyStatisticsWorker).to receive(:perform_async)
|
|
|
|
end
|
|
|
|
end
|
2019-03-19 13:02:17 -04:00
|
|
|
end
|