debian-mirror-gitlab/spec/features/protected_branches_spec.rb

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

190 lines
6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Protected Branches', :js do
2019-07-31 22:56:46 +05:30
include ProtectedBranchHelpers
2018-03-17 18:26:18 +05:30
let(:user) { create(:user) }
let(:admin) { create(:admin) }
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
context 'logged in as developer' do
before do
project.add_developer(user)
sign_in(user)
end
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
describe 'Delete protected branch' do
before do
create(:protected_branch, project: project, name: 'fix')
expect(ProtectedBranch.count).to eq(1)
end
2021-09-04 01:27:46 +05:30
it 'does not allow developer to remove protected branch' do
2018-03-17 18:26:18 +05:30
visit project_branches_path(project)
2016-08-24 12:49:21 +05:30
2021-04-29 21:17:54 +05:30
find('input[data-testid="branch-search"]').set('fix')
find('input[data-testid="branch-search"]').native.send_keys(:enter)
2018-03-17 18:26:18 +05:30
2021-09-04 01:27:46 +05:30
expect(page).to have_button('Only a project maintainer or owner can delete a protected branch', disabled: true)
end
2018-03-17 18:26:18 +05:30
end
end
2016-08-24 12:49:21 +05:30
2018-11-18 11:00:15 +05:30
context 'logged in as maintainer' do
2018-03-17 18:26:18 +05:30
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2018-03-17 18:26:18 +05:30
sign_in(user)
2016-08-24 12:49:21 +05:30
end
2022-02-05 19:09:49 +05:30
it 'allows to create a protected branch with name containing HTML tags' do
visit project_protected_branches_path(project)
set_defaults
set_protected_branch_name('foo<b>bar<\b>')
click_on "Protect"
within(".protected-branches-list") { expect(page).to have_content('foo<b>bar<\b>') }
expect(ProtectedBranch.count).to eq(1)
expect(ProtectedBranch.last.name).to eq('foo<b>bar<\b>')
end
2018-03-17 18:26:18 +05:30
describe 'Delete protected branch' do
before do
create(:protected_branch, project: project, name: 'fix')
expect(ProtectedBranch.count).to eq(1)
end
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
it 'removes branch after modal confirmation' do
visit project_branches_path(project)
2016-08-24 12:49:21 +05:30
2021-04-29 21:17:54 +05:30
find('input[data-testid="branch-search"]').set('fix')
find('input[data-testid="branch-search"]').native.send_keys(:enter)
2018-03-17 18:26:18 +05:30
expect(page).to have_content('fix')
expect(find('.all-branches')).to have_selector('li', count: 1)
2016-08-24 12:49:21 +05:30
2021-09-04 01:27:46 +05:30
expect(page).to have_button('Delete protected branch', disabled: false)
page.find('.js-delete-branch-button').click
2018-03-17 18:26:18 +05:30
fill_in 'delete_branch_input', with: 'fix'
2021-09-04 01:27:46 +05:30
click_button 'Yes, delete protected branch'
2016-08-24 12:49:21 +05:30
2021-04-29 21:17:54 +05:30
find('input[data-testid="branch-search"]').set('fix')
find('input[data-testid="branch-search"]').native.send_keys(:enter)
2018-03-17 18:26:18 +05:30
expect(page).to have_content('No branches to show')
end
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
end
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
context 'logged in as admin' do
before do
sign_in(admin)
2021-02-22 17:27:13 +05:30
gitlab_enable_admin_mode_sign_in(admin)
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
describe "explicit protected branches" do
it "allows creating explicit protected branches" do
visit project_protected_branches_path(project)
2018-11-08 19:23:39 +05:30
set_defaults
2021-12-07 22:27:20 +05:30
set_protected_branch_name('some->branch')
2018-03-17 18:26:18 +05:30
click_on "Protect"
2021-12-07 22:27:20 +05:30
within(".protected-branches-list") { expect(page).to have_content('some->branch') }
2018-03-17 18:26:18 +05:30
expect(ProtectedBranch.count).to eq(1)
2021-12-07 22:27:20 +05:30
expect(ProtectedBranch.last.name).to eq('some->branch')
2018-03-17 18:26:18 +05:30
end
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-11-08 19:23:39 +05:30
set_defaults
2018-03-17 18:26:18 +05:30
set_protected_branch_name('some-branch')
click_on "Protect"
2016-08-24 12:49:21 +05:30
2019-12-21 20:55:43 +05:30
within(".protected-branches-list") do
expect(page).not_to have_content("matching")
expect(page).not_to have_content("was deleted")
end
2018-03-17 18:26:18 +05:30
end
it "displays an error message if the named branch does not exist" do
visit project_protected_branches_path(project)
2018-11-08 19:23:39 +05:30
set_defaults
2018-03-17 18:26:18 +05:30
set_protected_branch_name('some-branch')
click_on "Protect"
2016-08-24 12:49:21 +05:30
2019-12-21 20:55:43 +05:30
within(".protected-branches-list") { expect(page).to have_content('Branch was deleted') }
2018-03-17 18:26:18 +05:30
end
2016-08-24 12:49:21 +05:30
end
2018-03-17 18:26:18 +05:30
describe "wildcard protected branches" do
it "allows creating protected branches with a wildcard" do
visit project_protected_branches_path(project)
2018-11-08 19:23:39 +05:30
set_defaults
2018-03-17 18:26:18 +05:30
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
it "displays the number of matching branches" do
project.repository.add_branch(admin, 'production-stable', 'master')
project.repository.add_branch(admin, 'staging-stable', 'master')
visit project_protected_branches_path(project)
2018-11-08 19:23:39 +05:30
set_defaults
2018-03-17 18:26:18 +05:30
set_protected_branch_name('*-stable')
click_on "Protect"
2018-05-09 12:01:36 +05:30
within(".protected-branches-list") do
expect(page).to have_content("2 matching branches")
end
2018-03-17 18:26:18 +05:30
end
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')
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
visit project_protected_branches_path(project)
set_protected_branch_name('*-stable')
2018-11-08 19:23:39 +05:30
set_defaults
2018-03-17 18:26:18 +05:30
click_on "Protect"
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
visit project_protected_branches_path(project)
click_on "2 matching branches"
2016-08-24 12:49:21 +05:30
2018-03-17 18:26:18 +05:30
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
2016-08-24 12:49:21 +05:30
end
end
2018-03-17 18:26:18 +05:30
describe "access control" do
2019-07-31 22:56:46 +05:30
before do
stub_licensed_features(protected_refs_for_users: false)
end
2018-11-08 19:23:39 +05:30
2019-07-31 22:56:46 +05:30
include_examples "protected branches > access control > CE"
2018-11-08 19:23:39 +05:30
end
end
2021-01-03 14:25:43 +05:30
context 'when the users for protected branches feature is off' do
before do
stub_licensed_features(protected_refs_for_users: false)
end
2021-03-11 19:13:27 +05:30
include_examples 'Deploy keys with protected branches' do
2022-11-25 23:54:43 +05:30
let(:all_dropdown_sections) { ['Roles', 'Deploy Keys'] }
2021-01-03 14:25:43 +05:30
end
end
2016-08-24 12:49:21 +05:30
end