Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git_http_controller_spec.rb « projects « controllers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4df53121aaa2675e08dfbd25c6910b6a8e2b4c20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true

require 'spec_helper'

describe Projects::GitHttpController do
  include GitHttpHelpers

  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 }

  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

  describe 'GET #info_refs' do
    let(:params) { project_params.merge(service: 'git-upload-pack') }

    it 'returns 401 for unauthenticated requests to public repositories when http protocol is disabled' do
      stub_application_setting(enabled_git_access_protocol: 'ssh')

      get :info_refs, params: params

      expect(response.status).to eq(401)
    end

    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

    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)

        get :info_refs, params: params

        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)

        get :info_refs, params: params

        expect(response.status).to eq(503)
        expect(response.body).to eq 'Gitlab::GitAccess::TimeoutError'
      end
    end
  end

  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

    context 'on a read-only instance' do
      before do
        allow(Gitlab::Database).to receive(:read_only?).and_return(true)
      end

      it 'does not update project statistics' do
        expect(ProjectDailyStatisticsWorker).not_to receive(:perform_async)
      end
    end

    it 'updates project statistics' do
      expect(ProjectDailyStatisticsWorker).to receive(:perform_async)
    end
  end
end