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

103 lines
3 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe API::RemoteMirrors do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, :remote_mirror) }
2020-03-13 15:44:24 +05:30
let_it_be(:developer) { create(:user) { |u| project.add_developer(u) } }
2020-01-01 13:55:28 +05:30
describe 'GET /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
it 'requires `admin_remote_mirror` permission' do
2020-03-13 15:44:24 +05:30
get api(route, developer)
2020-01-01 13:55:28 +05:30
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'returns a list of remote mirrors' do
project.add_maintainer(user)
get api(route, user)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirrors')
end
2020-04-08 14:13:33 +05:30
end
2020-01-01 13:55:28 +05:30
2020-04-08 14:13:33 +05:30
describe 'POST /projects/:id/remote_mirrors' do
let(:route) { "/projects/#{project.id}/remote_mirrors" }
shared_examples 'creates a remote mirror' do
it 'creates a remote mirror and returns reponse' do
project.add_maintainer(user)
post api(route, user), params: params
enabled = params.fetch(:enabled, false)
expect(response).to have_gitlab_http_status(:success)
expect(response).to match_response_schema('remote_mirror')
expect(json_response['enabled']).to eq(enabled)
2020-01-01 13:55:28 +05:30
end
2020-04-08 14:13:33 +05:30
end
2020-01-01 13:55:28 +05:30
2020-04-08 14:13:33 +05:30
it 'requires `admin_remote_mirror` permission' do
post api(route, developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
context 'creates a remote mirror' do
context 'disabled by default' do
let(:params) { { url: 'https://foo:bar@test.com' } }
2020-01-01 13:55:28 +05:30
2020-04-08 14:13:33 +05:30
it_behaves_like 'creates a remote mirror'
2020-01-01 13:55:28 +05:30
end
2020-04-08 14:13:33 +05:30
context 'enabled' do
let(:params) { { url: 'https://foo:bar@test.com', enabled: true } }
it_behaves_like 'creates a remote mirror'
end
end
it 'returns error if url is invalid' do
project.add_maintainer(user)
post api(route, user), params: {
url: 'ftp://foo:bar@test.com'
}
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['url']).to eq(["is blocked: Only allowed schemes are ssh, git, http, https"])
2020-01-01 13:55:28 +05:30
end
end
2020-03-13 15:44:24 +05:30
describe 'PUT /projects/:id/remote_mirrors/:mirror_id' do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first }
it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer)
expect(response).to have_gitlab_http_status(:unauthorized)
end
it 'updates a remote mirror' do
project.add_maintainer(user)
put api(route[mirror.id], user), params: {
enabled: '0',
2020-04-08 14:13:33 +05:30
only_protected_branches: 'true',
keep_divergent_refs: 'true'
2020-03-13 15:44:24 +05:30
}
expect(response).to have_gitlab_http_status(:success)
expect(json_response['enabled']).to eq(false)
expect(json_response['only_protected_branches']).to eq(true)
2020-05-24 23:13:21 +05:30
expect(json_response['keep_divergent_refs']).to eq(true)
2020-03-13 15:44:24 +05:30
end
end
2020-01-01 13:55:28 +05:30
end