debian-mirror-gitlab/spec/controllers/repositories/git_http_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

181 lines
6 KiB
Ruby
Raw Permalink Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Repositories::GitHttpController, feature_category: :source_code_management do
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project, :public, :repository) }
2020-04-08 14:13:33 +05:30
let_it_be(:personal_snippet) { create(:personal_snippet, :public, :repository) }
let_it_be(:project_snippet) { create(:project_snippet, :public, :repository, project: project) }
2020-03-13 15:44:24 +05:30
2021-11-18 22:05:49 +05:30
shared_examples 'handles unavailable Gitaly' do
let(:params) { super().merge(service: 'git-upload-pack') }
before do
request.headers.merge! auth_env(user.username, user.password, nil)
end
2023-05-27 22:25:52 +05:30
context 'when Gitaly is unavailable', :use_clean_rails_redis_caching do
2021-11-18 22:05:49 +05:30
it 'responds with a 503 message' do
expect(Gitlab::GitalyClient).to receive(:call).and_raise(GRPC::Unavailable)
get :info_refs, params: params
expect(response).to have_gitlab_http_status(:service_unavailable)
expect(response.body).to eq('The git server, Gitaly, is not available at this time. Please contact your administrator.')
end
end
end
2023-05-27 22:25:52 +05:30
shared_examples 'handles user activity' do
it 'updates the user activity' do
activity_project = container.is_a?(PersonalSnippet) ? nil : project
activity_service = instance_double(Users::ActivityService)
args = { author: user, project: activity_project, namespace: activity_project&.namespace }
expect(Users::ActivityService).to receive(:new).with(args).and_return(activity_service)
expect(activity_service).to receive(:execute)
get :info_refs, params: params
end
end
shared_examples 'handles logging git upload pack operation' do
before do
password = user.try(:password) || user.try(:token)
request.headers.merge! auth_env(user.username, password, nil)
end
context 'with git pull/fetch/clone action' do
let(:params) { super().merge(service: 'git-upload-pack') }
it_behaves_like 'handles user activity'
end
end
shared_examples 'handles logging git receive pack operation' do
let(:params) { super().merge(service: 'git-receive-pack') }
before do
request.headers.merge! auth_env(user.username, user.password, nil)
end
context 'with git push action when log_user_git_push_activity is enabled' do
it_behaves_like 'handles user activity'
end
context 'when log_user_git_push_activity is disabled' do
before do
stub_feature_flags(log_user_git_push_activity: false)
end
it 'does not log user activity' do
expect(controller).not_to receive(:log_user_activity)
get :info_refs, params: params
end
end
end
2021-02-22 17:27:13 +05:30
context 'when repository container is a project' do
it_behaves_like Repositories::GitHttpController do
let(:container) { project }
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2021-02-22 17:27:13 +05:30
let(:access_checker_class) { Gitlab::GitAccess }
2020-03-13 15:44:24 +05:30
2021-11-18 22:05:49 +05:30
it_behaves_like 'handles unavailable Gitaly'
2023-05-27 22:25:52 +05:30
it_behaves_like 'handles logging git upload pack operation'
it_behaves_like 'handles logging git receive pack operation'
2021-11-18 22:05:49 +05:30
2021-02-22 17:27:13 +05:30
describe 'POST #git_upload_pack' do
2020-03-13 15:44:24 +05:30
before do
2021-02-22 17:27:13 +05:30
allow(controller).to receive(:verify_workhorse_api!).and_return(true)
2020-03-13 15:44:24 +05:30
end
2021-02-22 17:27:13 +05:30
def send_request
post :git_upload_pack, params: params
2020-03-13 15:44:24 +05:30
end
2021-02-22 17:27:13 +05:30
it 'updates project statistics sync for projects' do
2021-03-11 19:13:27 +05:30
stub_feature_flags(disable_git_http_fetch_writes: false)
2020-04-22 19:07:51 +05:30
expect { send_request }.to change {
2021-02-22 17:27:13 +05:30
Projects::DailyStatisticsFinder.new(container).total_fetch_count
2020-04-22 19:07:51 +05:30
}.from(0).to(1)
2020-03-13 15:44:24 +05:30
end
2020-04-22 19:07:51 +05:30
2021-04-17 20:07:23 +05:30
describe 'recording the onboarding progress', :sidekiq_inline do
let_it_be(:namespace) { project.namespace }
2021-03-11 19:13:27 +05:30
before do
2022-10-11 01:57:18 +05:30
Onboarding::Progress.onboard(namespace)
2021-04-17 20:07:23 +05:30
send_request
2021-03-11 19:13:27 +05:30
end
2021-04-17 20:07:23 +05:30
2022-10-11 01:57:18 +05:30
subject { Onboarding::Progress.completed?(namespace, :git_pull) }
2021-04-17 20:07:23 +05:30
it { is_expected.to be(true) }
2021-03-11 19:13:27 +05:30
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)
send_request
2020-04-22 19:07:51 +05:30
end
2020-03-13 15:44:24 +05:30
end
end
end
2022-01-26 12:08:38 +05:30
context 'when the user is a deploy token' do
it_behaves_like Repositories::GitHttpController do
let(:container) { project }
let(:user) { create(:deploy_token, :project, projects: [project]) }
let(:access_checker_class) { Gitlab::GitAccess }
2023-05-27 22:25:52 +05:30
it_behaves_like 'handles logging git upload pack operation'
2022-01-26 12:08:38 +05:30
end
end
2020-03-13 15:44:24 +05:30
end
2021-02-22 17:27:13 +05:30
context 'when repository container is a project wiki' do
it_behaves_like Repositories::GitHttpController do
let(:container) { create(:project_wiki, :empty_repo, project: project) }
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2021-02-22 17:27:13 +05:30
let(:access_checker_class) { Gitlab::GitAccessWiki }
2023-05-27 22:25:52 +05:30
it_behaves_like 'handles logging git upload pack operation'
it_behaves_like 'handles logging git receive pack operation'
2020-03-13 15:44:24 +05:30
end
end
2020-04-08 14:13:33 +05:30
context 'when repository container is a personal snippet' do
2021-02-22 17:27:13 +05:30
it_behaves_like Repositories::GitHttpController do
let(:container) { personal_snippet }
2020-04-08 14:13:33 +05:30
let(:user) { personal_snippet.author }
2021-02-22 17:27:13 +05:30
let(:access_checker_class) { Gitlab::GitAccessSnippet }
2021-11-18 22:05:49 +05:30
it_behaves_like 'handles unavailable Gitaly'
2023-05-27 22:25:52 +05:30
it_behaves_like 'handles logging git upload pack operation'
it_behaves_like 'handles logging git receive pack operation'
2020-04-08 14:13:33 +05:30
end
end
context 'when repository container is a project snippet' do
2021-02-22 17:27:13 +05:30
it_behaves_like Repositories::GitHttpController do
let(:container) { project_snippet }
2020-04-08 14:13:33 +05:30
let(:user) { project_snippet.author }
2021-02-22 17:27:13 +05:30
let(:access_checker_class) { Gitlab::GitAccessSnippet }
2021-11-18 22:05:49 +05:30
it_behaves_like 'handles unavailable Gitaly'
2023-05-27 22:25:52 +05:30
it_behaves_like 'handles logging git upload pack operation'
it_behaves_like 'handles logging git receive pack operation'
2020-04-08 14:13:33 +05:30
end
end
2020-03-13 15:44:24 +05:30
end