@@ -108,64 +108,86 @@ describe Gitlab::Checks::BranchCheck do
...
@@ -108,64 +108,86 @@ describe Gitlab::Checks::BranchCheck do
end
end
context'protected branch creation feature is enabled'do
context'protected branch creation feature is enabled'do
context'user is not allowed to create protected branches'do
context'user can push to branch'do
beforedo
beforedo
allow(user_access)
allow(user_access)
.toreceive(:can_merge_to_branch?)
.toreceive(:can_push_to_branch?)
.with('feature')
.with('feature')
.and_return(false)
.and_return(true)
end
end
it'raises an error'do
it'does not raise an error'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to create protected branches on this project.')
expect{subject.validate!}.not_toraise_error
end
end
end
end
context'user is allowed to create protected branches'do
context'user cannot push to branch'do
beforedo
beforedo
allow(user_access)
allow(user_access)
.toreceive(:can_merge_to_branch?)
.toreceive(:can_push_to_branch?)
.with('feature')
.with('feature')
.and_return(true)
.and_return(false)
allow(project.repository)
.toreceive(:branch_names_contains_sha)
.with(newrev)
.and_return(['branch'])
end
end
context"newrev isn't in any protected branches"do
context'user cannot merge to branch'do
beforedo
beforedo
allow(ProtectedBranch)
allow(user_access)
.toreceive(:any_protected?)
.toreceive(:can_merge_to_branch?)
.with(project,['branch'])
.with('feature')
.and_return(false)
.and_return(false)
end
end
it'raises an error'do
it'raises an error'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only use an existing protected branch ref as the basis of a new protected branch.')
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You are not allowed to create protected branches on this project.')
end
end
end
end
context'newrev is included in a protected branch'do
context'user can merge to branch'do
beforedo
beforedo
allow(ProtectedBranch)
allow(user_access)
.toreceive(:any_protected?)
.toreceive(:can_merge_to_branch?)
.with(project,['branch'])
.with('feature')
.and_return(true)
.and_return(true)
allow(project.repository)
.toreceive(:branch_names_contains_sha)
.with(newrev)
.and_return(['branch'])
end
end
context'via web interface'do
context"newrev isn't in any protected branches"do
let(:protocol){'web'}
beforedo
allow(ProtectedBranch)
.toreceive(:any_protected?)
.with(project,['branch'])
.and_return(false)
end
it'allows branch creation'do
it'raises an error'do
expect{subject.validate!}.not_toraise_error
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only use an existing protected branch ref as the basis of a new protected branch.')
end
end
end
end
context'via SSH'do
context'newrev is included in a protected branch'do
it'raises an error'do
beforedo
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only create protected branches using the web interface and API.')
allow(ProtectedBranch)
.toreceive(:any_protected?)
.with(project,['branch'])
.and_return(true)
end
context'via web interface'do
let(:protocol){'web'}
it'allows branch creation'do
expect{subject.validate!}.not_toraise_error
end
end
context'via SSH'do
it'raises an error'do
expect{subject.validate!}.toraise_error(Gitlab::GitAccess::UnauthorizedError,'You can only create protected branches using the web interface and API.')