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

project_snapshots_spec.rb « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf78ff56206f4c5f3140b4d0229f97f12d62c678 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::ProjectSnapshots do
  include WorkhorseHelpers

  let(:project) { create(:project) }
  let(:admin) { create(:admin) }

  before do
    allow(Feature::Gitaly).to receive(:server_feature_flags).and_return({
      'gitaly-feature-foobar' => 'true'
    })
  end

  describe 'GET /projects/:id/snapshot' do
    def expect_snapshot_response_for(repository)
      type, params = workhorse_send_data

      expect(type).to eq('git-snapshot')
      expect(params).to eq(
        'GitalyServer' => {
          'features' => { 'gitaly-feature-foobar' => 'true' },
          'address' => Gitlab::GitalyClient.address(repository.project.repository_storage),
          'token' => Gitlab::GitalyClient.token(repository.project.repository_storage)
        },
        'GetSnapshotRequest' => Gitaly::GetSnapshotRequest.new(
          repository: repository.gitaly_repository
        ).to_json
      )
      expect(response.parsed_body).to be_empty
    end

    it 'returns authentication error as project owner' do
      get api("/projects/#{project.id}/snapshot", project.first_owner)

      expect(response).to have_gitlab_http_status(:forbidden)
    end

    it 'returns authentication error as unauthenticated user' do
      get api("/projects/#{project.id}/snapshot", nil)

      expect(response).to have_gitlab_http_status(:unauthorized)
    end

    it 'requests project repository raw archive as administrator' do
      get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '0' }

      expect(response).to have_gitlab_http_status(:ok)
      expect_snapshot_response_for(project.repository)
    end

    it 'requests wiki repository raw archive as administrator' do
      get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '1' }

      expect(response).to have_gitlab_http_status(:ok)
      expect_snapshot_response_for(project.wiki.repository)
    end
  end
end