delete_default_branch: 'The default branch of a project cannot be deleted.',
force_push_protected_branch: 'You are not allowed to force push code to a protected branch on this project.',
non_master_delete_protected_branch: 'You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.',
non_web_delete_protected_branch: 'You can only delete protected branches using the web interface.',
merge_protected_branch: 'You are not allowed to merge code into protected branches on this project.',
push_protected_branch: 'You are not allowed to push code to protected branches on this project.'
}.freeze
LOG_MESSAGES={
delete_default_branch_check: "Checking if default branch is being deleted...",
protected_branch_checks: "Checking if you are force pushing to a protected branch...",
protected_branch_push_checks: "Checking if you are allowed to push to the protected branch...",
protected_branch_deletion_checks: "Checking if you are allowed to delete the protected branch..."
delete_default_branch: 'The default branch of a project cannot be deleted.',
branch_name tag_name logger commits].freeze
force_push_protected_branch: 'You are not allowed to force push code to a protected branch on this project.',
non_master_delete_protected_branch: 'You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.',
non_web_delete_protected_branch: 'You can only delete protected branches using the web interface.',
merge_protected_branch: 'You are not allowed to merge code into protected branches on this project.',
push_protected_branch: 'You are not allowed to push code to protected branches on this project.',
change_existing_tags: 'You are not allowed to change existing tags on this project.',
update_protected_tag: 'Protected tags cannot be updated.',
delete_protected_tag: 'Protected tags cannot be deleted.',
create_protected_tag: 'You are not allowed to create this tag as it is protected.',
lfs_objects_missing: 'LFS objects are missing. Ensure LFS is properly set up or try a manual "git lfs push --all".'
}.freeze
LOG_MESSAGES={
attr_reader(*ATTRIBUTES)
push_checks: "Checking if you are allowed to push...",
delete_default_branch_check: "Checking if default branch is being deleted...",
protected_branch_checks: "Checking if you are force pushing to a protected branch...",
protected_branch_push_checks: "Checking if you are allowed to push to the protected branch...",
protected_branch_deletion_checks: "Checking if you are allowed to delete the protected branch...",
tag_checks: "Checking if you are allowed to change existing tags...",
protected_tag_checks: "Checking if you are creating, updating or deleting a protected tag...",
lfs_objects_exist_check: "Scanning repository for blobs stored in LFS and verifying their files have been uploaded to GitLab...",
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to force push code to a protected branch on this project.')
end
it'raises an error if the user is not allowed to merge to protected branches'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to merge code into protected branches on this project.')
end
it'raises an error if the user is not allowed to push to protected branches'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to push code to protected branches on this project.')
end
context'when project repository is empty'do
let(:project){create(:project)}
it'raises an error if the user is not allowed to push to protected branches'do
context'if the user is not allowed to delete protected branches'do
it'raises an error'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.')
end
end
context'if the user is allowed to delete protected branches'do
beforedo
project.add_maintainer(user)
end
context'through the web interface'do
let(:protocol){'web'}
it'allows branch deletion'do
expect{subject.validate!}.not_toraise_error
end
end
context'over SSH or HTTP'do
it'raises an error'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only delete protected branches using the web interface.')
expect{subject.exec}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to force push code to a protected branch on this project.')
end
it'raises an error if the user is not allowed to merge to protected branches'do
context'if the user is not allowed to delete protected branches'do
it'raises an error'do
expect{subject.exec}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to delete protected branches from this project. Only a project maintainer or owner can delete a protected branch.')
end
end
context'if the user is allowed to delete protected branches'do
beforedo
project.add_maintainer(user)
end
context'through the web interface'do
let(:protocol){'web'}
it'allows branch deletion'do
expect{subject.exec}.not_toraise_error
end
end
context'over SSH or HTTP'do
it'raises an error'do
expect{subject.exec}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only delete protected branches using the web interface.')