2019-10-28 20:06:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-03 13:57:55 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe API::ProjectSnapshots do
|
2018-04-03 13:57:55 -04:00
|
|
|
include WorkhorseHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2019-08-28 12:51:17 -04:00
|
|
|
before do
|
|
|
|
allow(Feature::Gitaly).to receive(:server_feature_flags).and_return({
|
|
|
|
'gitaly-feature-foobar' => 'true'
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2018-04-03 13:57:55 -04:00
|
|
|
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' => {
|
2019-08-28 12:51:17 -04:00
|
|
|
'features' => { 'gitaly-feature-foobar' => 'true' },
|
2018-04-03 13:57:55 -04:00
|
|
|
'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
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns authentication error as project owner' do
|
|
|
|
get api("/projects/#{project.id}/snapshot", project.owner)
|
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2018-04-03 13:57:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns authentication error as unauthenticated user' do
|
|
|
|
get api("/projects/#{project.id}/snapshot", nil)
|
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2018-04-03 13:57:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'requests project repository raw archive as administrator' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '0' }
|
2018-04-03 13:57:55 -04:00
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-04-03 13:57:55 -04:00
|
|
|
expect_snapshot_response_for(project.repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requests wiki repository raw archive as administrator' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get api("/projects/#{project.id}/snapshot", admin), params: { wiki: '1' }
|
2018-04-03 13:57:55 -04:00
|
|
|
|
2020-02-27 16:09:17 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2018-04-03 13:57:55 -04:00
|
|
|
expect_snapshot_response_for(project.wiki.repository)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|