Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
2f06027d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2f06027d
编写于
8月 12, 2016
作者:
A
Alejandro Rodríguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the order of the access rules to check simpler first, and add specs
上级
11eefba8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
100 addition
and
1 deletion
+100
-1
lib/gitlab/checks/change_access.rb
lib/gitlab/checks/change_access.rb
+1
-1
spec/lib/gitlab/checks/change_access_spec.rb
spec/lib/gitlab/checks/change_access_spec.rb
+99
-0
未找到文件。
lib/gitlab/checks/change_access.rb
浏览文件 @
2f06027d
...
...
@@ -11,7 +11,7 @@ module Gitlab
end
def
exec
error
=
p
rotected_branch_checks
||
tag_checks
||
pus
h_checks
error
=
p
ush_checks
||
tag_checks
||
protected_branc
h_checks
if
error
GitAccessStatus
.
new
(
false
,
error
)
...
...
spec/lib/gitlab/checks/change_access_spec.rb
0 → 100644
浏览文件 @
2f06027d
require
'spec_helper'
describe
Gitlab
::
Checks
::
ChangeAccess
,
lib:
true
do
describe
'#exec'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user_access
)
{
Gitlab
::
UserAccess
.
new
(
user
,
project:
project
)
}
let
(
:changes
)
do
{
oldrev:
'be93687618e4b132087f430a4d8fc3a609c9b77c'
,
newrev:
'54fcc214b94e78d7a41a9a8fe6d87a5e59500e51'
,
ref:
'refs/heads/master'
}
end
subject
{
described_class
.
new
(
changes
,
project:
project
,
user_access:
user_access
).
exec
}
before
{
allow
(
user_access
).
to
receive
(
:can_do_action?
).
with
(
:push_code
).
and_return
(
true
)
}
context
'without failed checks'
do
it
"doesn't return any error"
do
expect
(
subject
.
status
).
to
be
(
true
)
end
end
context
'when the user is not allowed to push code'
do
it
'returns an error'
do
expect
(
user_access
).
to
receive
(
:can_do_action?
).
with
(
:push_code
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to push code to this project.'
)
end
end
context
'tags check'
do
let
(
:changes
)
do
{
oldrev:
'be93687618e4b132087f430a4d8fc3a609c9b77c'
,
newrev:
'54fcc214b94e78d7a41a9a8fe6d87a5e59500e51'
,
ref:
'refs/tags/v1.0.0'
}
end
it
'returns an error if the user is not allowed to update tags'
do
expect
(
user_access
).
to
receive
(
:can_do_action?
).
with
(
:admin_project
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to change existing tags on this project.'
)
end
end
context
'protected branches check'
do
before
do
allow
(
project
).
to
receive
(
:protected_branch?
).
with
(
'master'
).
and_return
(
true
)
end
it
'returns an error if the user is not allowed to do forced pushes to protected branches'
do
expect
(
Gitlab
::
Checks
::
ForcePush
).
to
receive
(
:force_push?
).
and_return
(
true
)
expect
(
user_access
).
to
receive
(
:can_do_action?
).
with
(
:force_push_code_to_protected_branches
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to force push code to a protected branch on this project.'
)
end
it
'returns an error if the user is not allowed to merge to protected branches'
do
expect_any_instance_of
(
Gitlab
::
Checks
::
MatchingMergeRequest
).
to
receive
(
:match?
).
and_return
(
true
)
expect
(
user_access
).
to
receive
(
:can_merge_to_branch?
).
and_return
(
false
)
expect
(
user_access
).
to
receive
(
:can_push_to_branch?
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to merge code into protected branches on this project.'
)
end
it
'returns an error if the user is not allowed to push to protected branches'
do
expect
(
user_access
).
to
receive
(
:can_push_to_branch?
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to push code to protected branches on this project.'
)
end
context
'branch deletion'
do
let
(
:changes
)
do
{
oldrev:
'be93687618e4b132087f430a4d8fc3a609c9b77c'
,
newrev:
'0000000000000000000000000000000000000000'
,
ref:
'refs/heads/master'
}
end
it
'returns an error if the user is not allowed to delete protected branches'
do
expect
(
user_access
).
to
receive
(
:can_do_action?
).
with
(
:remove_protected_branches
).
and_return
(
false
)
expect
(
subject
.
status
).
to
be
(
false
)
expect
(
subject
.
message
).
to
eq
(
'You are not allowed to delete protected branches from this project.'
)
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录