2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-31 12:54:38 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe 'Projects > Settings > Repository settings' do
|
2017-03-31 12:54:38 +00:00
|
|
|
let(:project) { create(:project_empty_repo) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:role) { :developer }
|
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_role(user, role)
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(user)
|
2017-03-31 12:54:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for developer' do
|
2018-04-06 12:40:33 +00:00
|
|
|
let(:role) { :developer }
|
2017-03-31 12:54:38 +00:00
|
|
|
|
2018-04-06 12:40:33 +00:00
|
|
|
it 'is not allowed to view' do
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 12:54:38 +00:00
|
|
|
|
|
|
|
expect(page.status_code).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 14:36:08 +00:00
|
|
|
context 'for maintainer' do
|
|
|
|
let(:role) { :maintainer }
|
2017-03-31 12:54:38 +00:00
|
|
|
|
2020-04-23 00:09:41 +00:00
|
|
|
context 'Deploy tokens' do
|
|
|
|
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_container_registry_config(enabled: true)
|
2020-05-13 09:08:37 +00:00
|
|
|
stub_feature_flags(ajax_new_deploy_token: project)
|
2020-04-23 00:09:41 +00:00
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a deploy token in settings' do
|
|
|
|
let(:entity_type) { 'project' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-24 18:09:46 +00:00
|
|
|
context 'Deploy Keys', :js do
|
|
|
|
let_it_be(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) }
|
|
|
|
let_it_be(:public_deploy_key) { create(:another_deploy_key, title: 'public_deploy_key', public: true) }
|
|
|
|
let(:new_ssh_key) { attributes_for(:key)[:key] }
|
|
|
|
|
|
|
|
it 'get list of keys' do
|
|
|
|
project.deploy_keys << private_deploy_key
|
|
|
|
project.deploy_keys << public_deploy_key
|
|
|
|
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
expect(page).to have_content('private_deploy_key')
|
|
|
|
expect(page).to have_content('public_deploy_key')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'add a new deploy key' do
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'new_deploy_key'
|
|
|
|
fill_in 'deploy_key_key', with: new_ssh_key
|
|
|
|
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
|
|
|
|
click_button 'Add key'
|
|
|
|
|
|
|
|
expect(page).to have_content('new_deploy_key')
|
|
|
|
expect(page).to have_content('Write access allowed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edit an existing deploy key' do
|
|
|
|
project.deploy_keys << private_deploy_key
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click
|
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'updated_deploy_key'
|
|
|
|
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content('updated_deploy_key')
|
|
|
|
expect(page).to have_content('Write access allowed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edit an existing public deploy key to be writable' do
|
|
|
|
project.deploy_keys << public_deploy_key
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
find('.deploy-key', text: public_deploy_key.title).find('.ic-pencil').click
|
|
|
|
|
|
|
|
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content('public_deploy_key')
|
|
|
|
expect(page).to have_content('Write access allowed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'edit a deploy key from projects user has access to' do
|
|
|
|
project2 = create(:project_empty_repo)
|
|
|
|
project2.add_role(user, role)
|
|
|
|
project2.deploy_keys << private_deploy_key
|
|
|
|
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
find('.js-deployKeys-tab-available_project_keys').click
|
|
|
|
|
|
|
|
find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click
|
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'updated_deploy_key'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
find('.js-deployKeys-tab-available_project_keys').click
|
|
|
|
|
|
|
|
expect(page).to have_content('updated_deploy_key')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'remove an existing deploy key' do
|
|
|
|
project.deploy_keys << private_deploy_key
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
accept_confirm { find('.deploy-key', text: private_deploy_key.title).find('.ic-remove').click }
|
|
|
|
|
|
|
|
expect(page).not_to have_content(private_deploy_key.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-03 12:55:14 +00:00
|
|
|
context 'remote mirror settings' do
|
|
|
|
before do
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
2018-08-02 00:01:45 +00:00
|
|
|
it 'shows push mirror settings', :js do
|
|
|
|
expect(page).to have_selector('#mirror_direction')
|
2018-05-03 12:55:14 +00:00
|
|
|
end
|
2018-11-12 10:52:48 +00:00
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
it 'creates a push mirror that mirrors all branches', :js do
|
|
|
|
expect(find('.js-mirror-protected-hidden', visible: false).value).to eq('0')
|
|
|
|
|
2018-11-12 10:52:48 +00:00
|
|
|
fill_in 'url', with: 'ssh://user@localhost/project.git'
|
|
|
|
select 'SSH public key', from: 'Authentication method'
|
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
select_direction
|
2018-11-12 10:52:48 +00:00
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Mirror repository'
|
2018-11-12 10:52:48 +00:00
|
|
|
end
|
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(page).to have_content('Mirroring settings were successfully updated')
|
|
|
|
expect(project.remote_mirrors.first.only_protected_branches).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a push mirror that only mirrors protected branches', :js do
|
|
|
|
find('#only_protected_branches').click
|
|
|
|
|
|
|
|
expect(find('.js-mirror-protected-hidden', visible: false).value).to eq('1')
|
|
|
|
|
|
|
|
fill_in 'url', with: 'ssh://user@localhost/project.git'
|
|
|
|
select 'SSH public key', from: 'Authentication method'
|
|
|
|
|
|
|
|
select_direction
|
|
|
|
|
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Mirror repository'
|
|
|
|
end
|
|
|
|
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(page).to have_content('Mirroring settings were successfully updated')
|
|
|
|
expect(project.remote_mirrors.first.only_protected_branches).to eq(true)
|
|
|
|
end
|
|
|
|
|
2020-03-30 15:07:51 +00:00
|
|
|
it 'creates a push mirror that keeps divergent refs', :js do
|
|
|
|
select_direction
|
|
|
|
|
|
|
|
fill_in 'url', with: 'ssh://user@localhost/project.git'
|
|
|
|
fill_in 'Password', with: 'password'
|
|
|
|
check 'Keep divergent refs'
|
|
|
|
|
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Mirror repository'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_content('Mirroring settings were successfully updated')
|
|
|
|
expect(project.reload.remote_mirrors.first.keep_divergent_refs).to eq(true)
|
|
|
|
end
|
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
it 'generates an SSH public key on submission', :js do
|
|
|
|
fill_in 'url', with: 'ssh://user@localhost/project.git'
|
|
|
|
select 'SSH public key', from: 'Authentication method'
|
|
|
|
|
|
|
|
select_direction
|
|
|
|
|
2018-11-12 10:52:48 +00:00
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Mirror repository'
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).to have_content('Mirroring settings were successfully updated')
|
|
|
|
expect(page).to have_selector('[title="Copy SSH public key"]')
|
|
|
|
end
|
2018-11-28 20:31:01 +00:00
|
|
|
|
2020-03-26 18:08:03 +00:00
|
|
|
context 'when project mirroring is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(mirror_available: false)
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides remote mirror settings' do
|
|
|
|
expect(page.find('.project-mirror-settings')).not_to have_selector('form')
|
|
|
|
expect(page).to have_content('Mirror settings are only available to GitLab administrators.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-28 20:31:01 +00:00
|
|
|
def select_direction(direction = 'push')
|
|
|
|
direction_select = find('#mirror_direction')
|
|
|
|
|
|
|
|
# In CE, this select box is disabled, but in EE, it is enabled
|
|
|
|
if direction_select.disabled?
|
|
|
|
expect(direction_select.value).to eq(direction)
|
|
|
|
else
|
|
|
|
direction_select.select(direction.capitalize)
|
|
|
|
end
|
|
|
|
end
|
2018-05-03 12:55:14 +00:00
|
|
|
end
|
2018-11-19 15:03:58 +00:00
|
|
|
|
|
|
|
context 'repository cleanup settings' do
|
|
|
|
let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') }
|
|
|
|
|
2018-12-13 17:52:38 +00:00
|
|
|
it 'uploads an object map file', :js do
|
|
|
|
visit project_settings_repository_path(project)
|
2018-11-19 15:03:58 +00:00
|
|
|
|
2018-12-13 17:52:38 +00:00
|
|
|
expect(page).to have_content('Repository cleanup')
|
2018-11-19 15:03:58 +00:00
|
|
|
|
2018-12-13 17:52:38 +00:00
|
|
|
page.within('#cleanup') do
|
|
|
|
attach_file('project[bfg_object_map]', object_map_file, visible: false)
|
2018-11-19 15:03:58 +00:00
|
|
|
|
2018-12-13 17:52:38 +00:00
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Start cleanup'
|
2018-11-19 15:03:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 17:52:38 +00:00
|
|
|
expect(page).to have_content('Repository cleanup has started')
|
|
|
|
expect(RepositoryCleanupWorker.jobs.count).to eq(1)
|
2018-11-19 15:03:58 +00:00
|
|
|
end
|
|
|
|
end
|
2019-05-06 13:15:03 +00:00
|
|
|
|
|
|
|
context 'with an existing mirror', :js do
|
|
|
|
let(:mirrored_project) { create(:project, :repository, :remote_mirror) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
mirrored_project.add_maintainer(user)
|
|
|
|
|
|
|
|
visit project_settings_repository_path(mirrored_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'delete remote mirrors' do
|
|
|
|
expect(mirrored_project.remote_mirrors.count).to eq(1)
|
|
|
|
|
|
|
|
find('.js-delete-mirror').click
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(mirrored_project.remote_mirrors.count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2019-03-21 22:24:48 +00:00
|
|
|
|
|
|
|
it 'shows a disabled mirror' do
|
|
|
|
create(:remote_mirror, project: project, enabled: false)
|
|
|
|
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
2019-07-29 19:15:16 +00:00
|
|
|
mirror = find('.rspec-mirrored-repository-row')
|
2019-03-21 22:24:48 +00:00
|
|
|
|
2019-07-29 19:15:16 +00:00
|
|
|
expect(mirror).to have_selector('.rspec-delete-mirror')
|
|
|
|
expect(mirror).to have_selector('.rspec-disabled-mirror-badge')
|
|
|
|
expect(mirror).not_to have_selector('.rspec-update-now-button')
|
2019-03-21 22:24:48 +00:00
|
|
|
end
|
2017-03-31 12:54:38 +00:00
|
|
|
end
|
2020-03-26 18:08:03 +00:00
|
|
|
|
|
|
|
context 'for admin' do
|
|
|
|
shared_examples_for 'shows mirror settings' do
|
|
|
|
it 'shows mirror settings' do
|
|
|
|
expect(page.find('.project-mirror-settings')).to have_selector('form')
|
|
|
|
expect(page).not_to have_content('Changing mirroring setting is disabled for non-admin users.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(mirror_available: mirror_available)
|
|
|
|
user.update!(admin: true)
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project mirroring is enabled' do
|
|
|
|
let(:mirror_available) { true }
|
|
|
|
|
|
|
|
include_examples 'shows mirror settings'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project mirroring is disabled' do
|
|
|
|
let(:mirror_available) { false }
|
|
|
|
|
|
|
|
include_examples 'shows mirror settings'
|
|
|
|
end
|
|
|
|
end
|
2017-03-31 12:54:38 +00:00
|
|
|
end
|