2020-01-24 13:09:00 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Repositories::GitHttpController do
|
2020-01-24 13:09:00 -05:00
|
|
|
let_it_be(:project) { create(:project, :public, :repository) }
|
2020-03-04 19:07:49 -05:00
|
|
|
let_it_be(:personal_snippet) { create(:personal_snippet, :public, :repository) }
|
|
|
|
let_it_be(:project_snippet) { create(:project_snippet, :public, :repository, project: project) }
|
2020-01-24 13:09:00 -05:00
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
context 'when repository container is a project' do
|
|
|
|
it_behaves_like Repositories::GitHttpController do
|
|
|
|
let(:container) { project }
|
|
|
|
let(:user) { project.owner }
|
|
|
|
let(:access_checker_class) { Gitlab::GitAccess }
|
2020-01-24 13:09:00 -05:00
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
describe 'POST #git_upload_pack' do
|
2020-01-24 13:09:00 -05:00
|
|
|
before do
|
2020-12-01 07:09:17 -05:00
|
|
|
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def send_request
|
|
|
|
post :git_upload_pack, params: params
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
context 'on a read-only instance' do
|
2020-04-21 11:21:10 -04:00
|
|
|
before do
|
2020-12-01 07:09:17 -05:00
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
it 'does not update project statistics' do
|
|
|
|
expect(ProjectDailyStatisticsWorker).not_to receive(:perform_async)
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
send_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project_statistics_sync feature flag is disabled' do
|
|
|
|
before do
|
2021-02-16 13:09:24 -05:00
|
|
|
stub_feature_flags(project_statistics_sync: false, disable_git_http_fetch_writes: false)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
it 'updates project statistics async for projects' do
|
|
|
|
expect(ProjectDailyStatisticsWorker).to receive(:perform_async)
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
send_request
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
it 'updates project statistics sync for projects' do
|
2021-02-16 13:09:24 -05:00
|
|
|
stub_feature_flags(disable_git_http_fetch_writes: false)
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
expect { send_request }.to change {
|
|
|
|
Projects::DailyStatisticsFinder.new(container).total_fetch_count
|
|
|
|
}.from(0).to(1)
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2021-01-25 10:09:00 -05:00
|
|
|
it_behaves_like 'records an onboarding progress action', :git_read do
|
|
|
|
let(:namespace) { project.namespace }
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2021-01-25 10:09:00 -05:00
|
|
|
subject { send_request }
|
2021-02-16 13:09:24 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(disable_git_http_fetch_writes: false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when disable_git_http_fetch_writes is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(disable_git_http_fetch_writes: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not increment statistics' do
|
|
|
|
expect(Projects::FetchStatisticsIncrementService).not_to receive(:new)
|
|
|
|
expect(ProjectDailyStatisticsWorker).not_to receive(:perform_async)
|
|
|
|
|
|
|
|
send_request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not record onboarding progress' do
|
|
|
|
expect(OnboardingProgressService).not_to receive(:new)
|
|
|
|
|
|
|
|
send_request
|
|
|
|
end
|
2020-12-03 13:10:10 -05:00
|
|
|
end
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
context 'when repository container is a project wiki' do
|
|
|
|
it_behaves_like Repositories::GitHttpController do
|
|
|
|
let(:container) { create(:project_wiki, :empty_repo, project: project) }
|
2020-03-04 19:07:49 -05:00
|
|
|
let(:user) { project.owner }
|
2020-12-01 07:09:17 -05:00
|
|
|
let(:access_checker_class) { Gitlab::GitAccessWiki }
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
|
|
|
end
|
2020-03-04 19:07:49 -05:00
|
|
|
|
|
|
|
context 'when repository container is a personal snippet' do
|
2020-12-01 07:09:17 -05:00
|
|
|
it_behaves_like Repositories::GitHttpController do
|
|
|
|
let(:container) { personal_snippet }
|
2020-03-04 19:07:49 -05:00
|
|
|
let(:user) { personal_snippet.author }
|
2020-12-01 07:09:17 -05:00
|
|
|
let(:access_checker_class) { Gitlab::GitAccessSnippet }
|
2020-03-04 19:07:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repository container is a project snippet' do
|
2020-12-01 07:09:17 -05:00
|
|
|
it_behaves_like Repositories::GitHttpController do
|
|
|
|
let(:container) { project_snippet }
|
2020-03-04 19:07:49 -05:00
|
|
|
let(:user) { project_snippet.author }
|
2020-12-01 07:09:17 -05:00
|
|
|
let(:access_checker_class) { Gitlab::GitAccessSnippet }
|
2020-03-04 19:07:49 -05:00
|
|
|
end
|
|
|
|
end
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|