2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-31 08:54:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
describe 'Projects > Settings > Repository settings' do
|
2017-03-31 08:54:38 -04:00
|
|
|
let(:project) { create(:project_empty_repo) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:role) { :developer }
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_role(user, role)
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'for developer' do
|
2018-04-06 08:40:33 -04:00
|
|
|
let(:role) { :developer }
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'is not allowed to view' do
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
expect(page.status_code).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'for maintainer' do
|
|
|
|
let(:role) { :maintainer }
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
context 'Deploy Keys', :js do
|
2017-03-31 08:54:38 -04:00
|
|
|
let(:private_deploy_key) { create(:deploy_key, title: 'private_deploy_key', public: false) }
|
|
|
|
let(:public_deploy_key) { create(:another_deploy_key, title: 'public_deploy_key', public: true) }
|
|
|
|
let(:new_ssh_key) { attributes_for(:key)[:key] }
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'get list of keys' do
|
2017-03-31 08:54:38 -04:00
|
|
|
project.deploy_keys << private_deploy_key
|
|
|
|
project.deploy_keys << public_deploy_key
|
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
expect(page).to have_content('private_deploy_key')
|
|
|
|
expect(page).to have_content('public_deploy_key')
|
|
|
|
end
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'add a new deploy key' do
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'new_deploy_key'
|
|
|
|
fill_in 'deploy_key_key', with: new_ssh_key
|
2018-01-05 10:23:44 -05:00
|
|
|
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
|
2017-03-31 08:54:38 -04:00
|
|
|
click_button 'Add key'
|
|
|
|
|
|
|
|
expect(page).to have_content('new_deploy_key')
|
|
|
|
expect(page).to have_content('Write access allowed')
|
|
|
|
end
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'edit an existing deploy key' do
|
2017-03-31 08:54:38 -04:00
|
|
|
project.deploy_keys << private_deploy_key
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2019-01-24 08:43:02 -05:00
|
|
|
find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'updated_deploy_key'
|
2018-01-05 10:23:44 -05:00
|
|
|
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
|
2017-03-31 08:54:38 -04:00
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content('updated_deploy_key')
|
|
|
|
expect(page).to have_content('Write access allowed')
|
|
|
|
end
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'edit a deploy key from projects user has access to' do
|
2017-06-20 05:37:07 -04:00
|
|
|
project2 = create(:project_empty_repo)
|
2017-12-22 03:18:28 -05:00
|
|
|
project2.add_role(user, role)
|
2017-06-20 05:37:07 -04:00
|
|
|
project2.deploy_keys << private_deploy_key
|
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-06-20 05:37:07 -04:00
|
|
|
|
2019-01-24 08:43:02 -05:00
|
|
|
find('.js-deployKeys-tab-available_project_keys').click
|
2018-05-07 14:21:34 -04:00
|
|
|
|
2019-01-24 08:43:02 -05:00
|
|
|
find('.deploy-key', text: private_deploy_key.title).find('.ic-pencil').click
|
2017-06-20 05:37:07 -04:00
|
|
|
|
|
|
|
fill_in 'deploy_key_title', with: 'updated_deploy_key'
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
2019-01-24 08:43:02 -05:00
|
|
|
find('.js-deployKeys-tab-available_project_keys').click
|
2018-05-07 14:21:34 -04:00
|
|
|
|
2017-06-20 05:37:07 -04:00
|
|
|
expect(page).to have_content('updated_deploy_key')
|
|
|
|
end
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
it 'remove an existing deploy key' do
|
2017-03-31 08:54:38 -04:00
|
|
|
project.deploy_keys << private_deploy_key
|
2017-07-06 12:20:50 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2017-03-31 08:54:38 -04:00
|
|
|
|
2019-01-24 08:43:02 -05:00
|
|
|
accept_confirm { find('.deploy-key', text: private_deploy_key.title).find('.ic-remove').click }
|
2017-03-31 08:54:38 -04:00
|
|
|
|
|
|
|
expect(page).not_to have_content(private_deploy_key.title)
|
|
|
|
end
|
|
|
|
end
|
2018-03-29 18:56:35 -04:00
|
|
|
|
|
|
|
context 'Deploy tokens' do
|
2018-04-06 15:48:17 -04:00
|
|
|
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
|
2018-03-29 18:56:35 -04:00
|
|
|
|
|
|
|
before do
|
2018-04-06 10:30:21 -04:00
|
|
|
stub_container_registry_config(enabled: true)
|
2018-03-29 18:56:35 -04:00
|
|
|
visit project_settings_repository_path(project)
|
2018-03-29 22:11:36 -04:00
|
|
|
end
|
2018-03-29 18:56:35 -04:00
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'view deploy tokens' do
|
2018-03-29 18:56:35 -04:00
|
|
|
within('.deploy-tokens') do
|
|
|
|
expect(page).to have_content(deploy_token.name)
|
2018-04-05 13:22:34 -04:00
|
|
|
expect(page).to have_content('read_repository')
|
|
|
|
expect(page).to have_content('read_registry')
|
2018-03-29 18:56:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'add a new deploy token' do
|
2018-03-29 18:56:35 -04:00
|
|
|
fill_in 'deploy_token_name', with: 'new_deploy_key'
|
|
|
|
fill_in 'deploy_token_expires_at', with: (Date.today + 1.month).to_s
|
2019-07-02 14:56:48 -04:00
|
|
|
fill_in 'deploy_token_username', with: 'deployer'
|
2018-04-05 13:22:34 -04:00
|
|
|
check 'deploy_token_read_repository'
|
|
|
|
check 'deploy_token_read_registry'
|
2018-03-29 18:56:35 -04:00
|
|
|
click_button 'Create deploy token'
|
|
|
|
|
|
|
|
expect(page).to have_content('Your new project deploy token has been created')
|
2019-07-02 14:56:48 -04:00
|
|
|
|
|
|
|
within('.created-deploy-token-container') do
|
|
|
|
expect(page).to have_selector("input[name='deploy-token-user'][value='deployer']")
|
|
|
|
expect(page).to have_selector("input[name='deploy-token'][readonly='readonly']")
|
|
|
|
end
|
2018-03-29 18:56:35 -04:00
|
|
|
end
|
|
|
|
end
|
2018-05-03 08:55:14 -04:00
|
|
|
|
|
|
|
context 'remote mirror settings' do
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user2)
|
2018-05-03 08:55:14 -04:00
|
|
|
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
end
|
|
|
|
|
2018-08-01 20:01:45 -04:00
|
|
|
it 'shows push mirror settings', :js do
|
|
|
|
expect(page).to have_selector('#mirror_direction')
|
2018-05-03 08:55:14 -04:00
|
|
|
end
|
2018-11-12 05:52:48 -05:00
|
|
|
|
2018-11-28 15:31:01 -05: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 05:52:48 -05:00
|
|
|
fill_in 'url', with: 'ssh://user@localhost/project.git'
|
|
|
|
select 'SSH public key', from: 'Authentication method'
|
|
|
|
|
2018-11-28 15:31:01 -05:00
|
|
|
select_direction
|
2018-11-12 05:52:48 -05:00
|
|
|
|
2018-11-28 15:31:01 -05:00
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Mirror repository'
|
2018-11-12 05:52:48 -05:00
|
|
|
end
|
|
|
|
|
2018-11-28 15:31:01 -05: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
|
|
|
|
|
|
|
|
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 05:52:48 -05: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 15:31:01 -05: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 08:55:14 -04:00
|
|
|
end
|
2018-11-19 10:03:58 -05:00
|
|
|
|
|
|
|
context 'repository cleanup settings' do
|
|
|
|
let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') }
|
|
|
|
|
2018-12-13 12:52:38 -05:00
|
|
|
it 'uploads an object map file', :js do
|
|
|
|
visit project_settings_repository_path(project)
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2018-12-13 12:52:38 -05:00
|
|
|
expect(page).to have_content('Repository cleanup')
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2018-12-13 12:52:38 -05:00
|
|
|
page.within('#cleanup') do
|
|
|
|
attach_file('project[bfg_object_map]', object_map_file, visible: false)
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2018-12-13 12:52:38 -05:00
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
click_button 'Start cleanup'
|
2018-11-19 10:03:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 12:52:38 -05:00
|
|
|
expect(page).to have_content('Repository cleanup has started')
|
|
|
|
expect(RepositoryCleanupWorker.jobs.count).to eq(1)
|
2018-11-19 10:03:58 -05:00
|
|
|
end
|
|
|
|
end
|
2019-05-06 09:15:03 -04: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 18:24:48 -04:00
|
|
|
|
|
|
|
it 'shows a disabled mirror' do
|
|
|
|
create(:remote_mirror, project: project, enabled: false)
|
|
|
|
|
|
|
|
visit project_settings_repository_path(project)
|
|
|
|
|
|
|
|
mirror = find('.qa-mirrored-repository-row')
|
|
|
|
|
|
|
|
expect(mirror).to have_selector('.qa-delete-mirror')
|
|
|
|
expect(mirror).to have_selector('.qa-disabled-mirror-badge')
|
|
|
|
expect(mirror).not_to have_selector('.qa-update-now-button')
|
|
|
|
end
|
2017-03-31 08:54:38 -04:00
|
|
|
end
|
|
|
|
end
|