debian-mirror-gitlab/spec/requests/api/project_snapshots_spec.rb

65 lines
2 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
require 'spec_helper'
2023-06-20 00:43:36 +05:30
RSpec.describe API::ProjectSnapshots, :aggregate_failures, feature_category: :source_code_management do
2018-05-09 12:01:36 +05:30
include WorkhorseHelpers
let(:project) { create(:project) }
let(:admin) { create(:admin) }
2023-06-20 00:43:36 +05:30
let(:path) { "/projects/#{project.id}/snapshot" }
2018-05-09 12:01:36 +05:30
2019-12-04 20:38:33 +05:30
before do
allow(Feature::Gitaly).to receive(:server_feature_flags).and_return({
'gitaly-feature-foobar' => 'true'
})
end
2018-05-09 12:01:36 +05:30
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' => {
2023-03-04 22:38:38 +05:30
'call_metadata' => { 'gitaly-feature-foobar' => 'true' },
2018-05-09 12:01:36 +05:30
'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
)
2021-12-11 22:18:48 +05:30
expect(response.parsed_body).to be_empty
2018-05-09 12:01:36 +05:30
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'GET request permissions for admin mode'
2018-05-09 12:01:36 +05:30
it 'returns authentication error as project owner' do
2023-06-20 00:43:36 +05:30
get api(path, project.first_owner)
2018-05-09 12:01:36 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2018-05-09 12:01:36 +05:30
end
it 'returns authentication error as unauthenticated user' do
2023-06-20 00:43:36 +05:30
get api(path, nil)
2018-05-09 12:01:36 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:unauthorized)
2018-05-09 12:01:36 +05:30
end
it 'requests project repository raw archive as administrator' do
2023-06-20 00:43:36 +05:30
get api(path, admin, admin_mode: true), params: { wiki: '0' }
2018-05-09 12:01:36 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-05-09 12:01:36 +05:30
expect_snapshot_response_for(project.repository)
end
it 'requests wiki repository raw archive as administrator' do
2023-06-20 00:43:36 +05:30
get api(path, admin, admin_mode: true), params: { wiki: '1' }
2018-05-09 12:01:36 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-05-09 12:01:36 +05:30
expect_snapshot_response_for(project.wiki.repository)
end
end
end