debian-mirror-gitlab/spec/features/projects/settings/repository_settings_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

353 lines
12 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Projects > Settings > Repository settings', feature_category: :projects do
2023-07-09 08:55:56 +05:30
include Features::MirroringHelpers
2017-09-10 17:25:29 +05:30
let(:project) { create(:project_empty_repo) }
let(:user) { create(:user) }
let(:role) { :developer }
2018-10-15 14:42:47 +05:30
before do
2023-03-04 22:38:38 +05:30
stub_feature_flags(branch_rules: false)
2023-04-23 21:23:45 +05:30
stub_feature_flags(mirror_only_branches_match_regex: false)
2018-03-17 18:26:18 +05:30
project.add_role(user, role)
2017-09-10 17:25:29 +05:30
sign_in(user)
end
context 'for developer' do
2018-10-15 14:42:47 +05:30
let(:role) { :developer }
2017-09-10 17:25:29 +05:30
2018-10-15 14:42:47 +05:30
it 'is not allowed to view' do
2017-09-10 17:25:29 +05:30
visit project_settings_repository_path(project)
expect(page.status_code).to eq(404)
end
end
2018-11-18 11:00:15 +05:30
context 'for maintainer' do
let(:role) { :maintainer }
2017-09-10 17:25:29 +05:30
2022-11-25 23:54:43 +05:30
context 'Deploy tokens', :js do
2020-04-25 10:58:03 +05:30
let!(:deploy_token) { create(:deploy_token, projects: [project]) }
before do
stub_container_registry_config(enabled: true)
end
it_behaves_like 'a deploy token in settings' do
let(:entity_type) { 'project' }
2021-11-11 11:23:49 +05:30
let(:page_path) { project_settings_repository_path(project) }
2020-04-25 10:58:03 +05:30
end
end
2022-07-23 23:45:48 +05:30
context 'Branch rules', :js do
context 'branch_rules feature flag disabled', :js do
it 'does not render branch rules settings' do
visit project_settings_repository_path(project)
expect(page).not_to have_content('Branch rules')
end
end
2023-03-04 22:38:38 +05:30
it 'renders branch rules settings' do
stub_feature_flags(branch_rules: true)
visit project_settings_repository_path(project)
expect(page).to have_content('Branch rules')
end
2022-07-23 23:45:48 +05:30
end
2020-05-05 14:28:15 +05:30
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) }
2021-06-08 01:23:25 +05:30
2020-05-05 14:28:15 +05:30
let(:new_ssh_key) { attributes_for(:key)[:key] }
2023-06-20 00:43:36 +05:30
around do |example|
travel_to Time.zone.local(2022, 3, 1, 1, 0, 0) { example.run }
end
2020-05-05 14:28:15 +05:30
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')
2021-03-11 19:13:27 +05:30
expect(page).to have_content('Grant write permissions to this key')
2020-05-05 14:28:15 +05:30
end
2023-06-20 00:43:36 +05:30
it 'add a new deploy key with expiration' do
one_month = Time.zone.local(2022, 4, 1, 1, 0, 0)
visit project_settings_repository_path(project)
fill_in 'deploy_key_title', with: 'new_deploy_key_with_expiry'
fill_in 'deploy_key_key', with: new_ssh_key
fill_in 'deploy_key_expires_at', with: one_month.to_s
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
click_button 'Add key'
expect(page).to have_content('new_deploy_key_with_expiry')
expect(page).to have_content('in 1 month')
expect(page).to have_content('Grant write permissions to this key')
end
2020-05-05 14:28:15 +05:30
it 'edit an existing deploy key' do
project.deploy_keys << private_deploy_key
visit project_settings_repository_path(project)
2020-11-24 15:15:51 +05:30
find('.deploy-key', text: private_deploy_key.title).find('[data-testid="pencil-icon"]').click
2020-05-05 14:28:15 +05:30
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')
2021-03-11 19:13:27 +05:30
expect(page).to have_content('Grant write permissions to this key')
2020-05-05 14:28:15 +05:30
end
it 'edit an existing public deploy key to be writable' do
project.deploy_keys << public_deploy_key
visit project_settings_repository_path(project)
2020-11-24 15:15:51 +05:30
find('.deploy-key', text: public_deploy_key.title).find('[data-testid="pencil-icon"]').click
2020-05-05 14:28:15 +05:30
check 'deploy_key_deploy_keys_projects_attributes_0_can_push'
click_button 'Save changes'
expect(page).to have_content('public_deploy_key')
2021-03-11 19:13:27 +05:30
expect(page).to have_content('Grant write permissions to this key')
2020-05-05 14:28:15 +05:30
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
2020-11-24 15:15:51 +05:30
find('.deploy-key', text: private_deploy_key.title).find('[data-testid="pencil-icon"]').click
2020-05-05 14:28:15 +05:30
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)
2021-06-08 01:23:25 +05:30
click_button 'Remove'
click_button 'Remove deploy key'
2020-05-05 14:28:15 +05:30
expect(page).not_to have_content(private_deploy_key.title)
end
end
2018-10-15 14:42:47 +05:30
context 'remote mirror settings' do
2022-07-23 23:45:48 +05:30
let(:ssh_url) { 'ssh://user@localhost/project.git' }
2018-10-15 14:42:47 +05:30
before do
visit project_settings_repository_path(project)
end
2018-11-20 20:47:30 +05:30
it 'shows push mirror settings', :js do
expect(page).to have_selector('#mirror_direction')
2018-10-15 14:42:47 +05:30
end
2019-02-15 15:39:39 +05:30
it 'creates a push mirror that mirrors all branches', :js do
2023-07-09 08:55:56 +05:30
wait_for_mirror_field_javascript('protected', '0')
fill_and_wait_for_mirror_url_javascript('url', ssh_url)
2019-02-15 15:39:39 +05:30
2022-07-23 23:45:48 +05:30
select 'SSH public key', from: 'Authentication method'
2019-02-15 15:39:39 +05:30
select_direction
Sidekiq::Testing.fake! do
click_button 'Mirror repository'
end
project.reload
2023-03-04 22:38:38 +05:30
expect(page).to have_content('Mirroring settings were successfully updated')
2019-02-15 15:39:39 +05:30
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
2023-07-09 08:55:56 +05:30
wait_for_mirror_field_javascript('protected', '1')
fill_and_wait_for_mirror_url_javascript('url', ssh_url)
2019-02-15 15:39:39 +05:30
select 'SSH public key', from: 'Authentication method'
select_direction
Sidekiq::Testing.fake! do
click_button 'Mirror repository'
end
project.reload
2023-03-04 22:38:38 +05:30
expect(page).to have_content('Mirroring settings were successfully updated')
2019-02-15 15:39:39 +05:30
expect(project.remote_mirrors.first.only_protected_branches).to eq(true)
end
2020-04-22 19:07:51 +05:30
it 'creates a push mirror that keeps divergent refs', :js do
select_direction
2023-07-09 08:55:56 +05:30
fill_and_wait_for_mirror_url_javascript('url', ssh_url)
2022-07-23 23:45:48 +05:30
2020-04-22 19:07:51 +05:30
fill_in 'Password', with: 'password'
check 'Keep divergent refs'
Sidekiq::Testing.fake! do
click_button 'Mirror repository'
end
2023-03-04 22:38:38 +05:30
# TODO: The following line is skipped because a toast with
# "An error occurred while loading branch rules. Please try again."
# shows up right after which hides the below message. It is causing flakiness.
# https://gitlab.com/gitlab-org/gitlab/-/issues/383717#note_1185091998
# expect(page).to have_content('Mirroring settings were successfully updated')
2020-04-22 19:07:51 +05:30
expect(project.reload.remote_mirrors.first.keep_divergent_refs).to eq(true)
end
2019-02-15 15:39:39 +05:30
it 'generates an SSH public key on submission', :js do
2023-07-09 08:55:56 +05:30
fill_and_wait_for_mirror_url_javascript('url', ssh_url)
2022-10-02 17:18:49 +05:30
2019-02-15 15:39:39 +05:30
select 'SSH public key', from: 'Authentication method'
select_direction
Sidekiq::Testing.fake! do
click_button 'Mirror repository'
end
2023-03-04 22:38:38 +05:30
# TODO: The following line is skipped because a toast with
# "An error occurred while loading branch rules. Please try again."
# shows up right after which hides the below message. It is causing flakiness.
# https://gitlab.com/gitlab-org/gitlab/-/issues/383717#note_1185091998
# expect(page).to have_content('Mirroring settings were successfully updated')
2019-02-15 15:39:39 +05:30
expect(page).to have_selector('[title="Copy SSH public key"]')
end
2020-03-28 13:19:24 +05:30
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
2019-02-15 15:39:39 +05:30
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
end
context 'repository cleanup settings' do
let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') }
it 'uploads an object map file', :js do
visit project_settings_repository_path(project)
expect(page).to have_content('Repository cleanup')
page.within('#cleanup') do
attach_file('project[bfg_object_map]', object_map_file, visible: false)
Sidekiq::Testing.fake! do
click_button 'Start cleanup'
end
end
expect(page).to have_content('Repository cleanup has started')
expect(RepositoryCleanupWorker.jobs.count).to eq(1)
end
2018-10-15 14:42:47 +05:30
end
2019-07-31 22:56:46 +05:30
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
it 'shows a disabled mirror' do
create(:remote_mirror, project: project, enabled: false)
visit project_settings_repository_path(project)
2019-10-12 21:52:04 +05:30
mirror = find('.rspec-mirrored-repository-row')
2019-07-31 22:56:46 +05:30
2019-10-12 21:52:04 +05:30
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-07-31 22:56:46 +05:30
end
2017-09-10 17:25:29 +05:30
end
2020-03-28 13:19:24 +05:30
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
2021-02-22 17:27:13 +05:30
context 'when project mirroring is enabled', :enable_admin_mode do
2020-03-28 13:19:24 +05:30
let(:mirror_available) { true }
include_examples 'shows mirror settings'
end
2021-02-22 17:27:13 +05:30
context 'when project mirroring is disabled', :enable_admin_mode do
2020-03-28 13:19:24 +05:30
let(:mirror_available) { false }
include_examples 'shows mirror settings'
end
end
2017-09-10 17:25:29 +05:30
end