2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-17 04:49:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'Protected Branches', :js do
|
2019-04-24 14:17:46 -04:00
|
|
|
include ProtectedBranchHelpers
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:admin) { create(:admin) }
|
2017-03-28 17:13:16 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2020-09-22 05:09:43 -04:00
|
|
|
before do
|
|
|
|
stub_feature_flags(deploy_keys_on_protected_branches: false)
|
|
|
|
end
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
context 'logged in as developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
describe 'Delete protected branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'fix')
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not allow developer to removes protected branch' do
|
|
|
|
visit project_branches_path(project)
|
|
|
|
|
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2020-10-09 08:09:07 -04:00
|
|
|
expect(page).to have_css('.btn-danger.disabled')
|
2017-09-15 07:25:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'logged in as maintainer' do
|
2017-09-15 07:25:12 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-15 07:25:12 -04:00
|
|
|
sign_in(user)
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
describe 'Delete protected branch' do
|
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'fix')
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
it 'removes branch after modal confirmation' do
|
|
|
|
visit project_branches_path(project)
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
expect(page).to have_content('fix')
|
|
|
|
expect(find('.all-branches')).to have_selector('li', count: 1)
|
2017-10-11 17:54:05 -04:00
|
|
|
page.find('[data-target="#modal-delete-branch"]').click
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
expect(page).to have_css('.js-delete-branch[disabled]')
|
|
|
|
fill_in 'delete_branch_input', with: 'fix'
|
|
|
|
click_link 'Delete protected branch'
|
|
|
|
|
|
|
|
fill_in 'branch-search', with: 'fix'
|
|
|
|
find('#branch-search').native.send_keys(:enter)
|
|
|
|
|
|
|
|
expect(page).to have_content('No branches to show')
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
context 'logged in as admin' do
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
2020-11-23 10:09:37 -05:00
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
describe "explicit protected branches" do
|
|
|
|
it "allows creating explicit protected branches" do
|
|
|
|
visit project_protected_branches_path(project)
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
within(".protected-branches-list") { expect(page).to have_content('some-branch') }
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
expect(ProtectedBranch.last.name).to eq('some-branch')
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
it "displays the last commit on the matching branch if it exists" do
|
|
|
|
commit = create(:commit, project: project)
|
|
|
|
project.repository.add_branch(admin, 'some-branch', commit.id)
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
|
|
|
|
2019-10-15 17:06:25 -04:00
|
|
|
within(".protected-branches-list") do
|
|
|
|
expect(page).not_to have_content("matching")
|
|
|
|
expect(page).not_to have_content("was deleted")
|
|
|
|
end
|
2017-09-15 07:25:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "displays an error message if the named branch does not exist" do
|
|
|
|
visit project_protected_branches_path(project)
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
set_protected_branch_name('some-branch')
|
|
|
|
click_on "Protect"
|
|
|
|
|
2019-10-15 17:06:25 -04:00
|
|
|
within(".protected-branches-list") { expect(page).to have_content('Branch was deleted') }
|
2017-09-15 07:25:12 -04:00
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
describe "wildcard protected branches" do
|
|
|
|
it "allows creating protected branches with a wildcard" do
|
|
|
|
visit project_protected_branches_path(project)
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
set_protected_branch_name('*-stable')
|
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
within(".protected-branches-list") { expect(page).to have_content('*-stable') }
|
|
|
|
expect(ProtectedBranch.count).to eq(1)
|
|
|
|
expect(ProtectedBranch.last.name).to eq('*-stable')
|
|
|
|
end
|
2016-08-16 01:09:13 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
it "displays the number of matching branches" do
|
|
|
|
project.repository.add_branch(admin, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'staging-stable', 'master')
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2017-09-15 07:25:12 -04:00
|
|
|
visit project_protected_branches_path(project)
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
set_protected_branch_name('*-stable')
|
|
|
|
click_on "Protect"
|
2016-06-17 04:49:02 -04:00
|
|
|
|
2018-04-04 06:37:44 -04:00
|
|
|
within(".protected-branches-list") do
|
|
|
|
expect(page).to have_content("2 matching branches")
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|
2017-09-15 07:25:12 -04:00
|
|
|
|
|
|
|
it "displays all the branches matching the wildcard" do
|
|
|
|
project.repository.add_branch(admin, 'production-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'staging-stable', 'master')
|
|
|
|
project.repository.add_branch(admin, 'development', 'master')
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
set_protected_branch_name('*-stable')
|
2018-06-27 07:41:16 -04:00
|
|
|
set_defaults
|
2017-09-15 07:25:12 -04:00
|
|
|
click_on "Protect"
|
|
|
|
|
|
|
|
visit project_protected_branches_path(project)
|
|
|
|
click_on "2 matching branches"
|
|
|
|
|
|
|
|
within(".protected-branches-list") do
|
|
|
|
expect(page).to have_content("production-stable")
|
|
|
|
expect(page).to have_content("staging-stable")
|
|
|
|
expect(page).not_to have_content("development")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "access control" do
|
2019-04-24 14:17:46 -04:00
|
|
|
before do
|
|
|
|
stub_licensed_features(protected_refs_for_users: false)
|
|
|
|
end
|
2018-06-27 07:41:16 -04:00
|
|
|
|
2019-04-24 14:17:46 -04:00
|
|
|
include_examples "protected branches > access control > CE"
|
2018-06-27 07:41:16 -04:00
|
|
|
end
|
|
|
|
end
|
2020-09-22 05:09:43 -04:00
|
|
|
|
|
|
|
context 'when the users for protected branches feature is off' do
|
|
|
|
before do
|
|
|
|
stub_licensed_features(protected_refs_for_users: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'when the deploy_keys_on_protected_branches FF is turned on' do
|
|
|
|
let(:all_dropdown_sections) { %w(Roles Deploy\ Keys) }
|
|
|
|
end
|
|
|
|
end
|
2016-06-17 04:49:02 -04:00
|
|
|
end
|