Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f3e10283
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,发现更多精彩内容 >>
提交
f3e10283
编写于
7月 07, 2018
作者:
B
Brett Walker
提交者:
Stan Hu
7月 07, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor rspec matchers in read_only_spec.rb
上级
06e3ea7a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
33 deletion
+27
-33
lib/gitlab/middleware/read_only/controller.rb
lib/gitlab/middleware/read_only/controller.rb
+1
-0
spec/lib/gitlab/middleware/read_only_spec.rb
spec/lib/gitlab/middleware/read_only_spec.rb
+11
-33
spec/support/matchers/disallow_request_matchers.rb
spec/support/matchers/disallow_request_matchers.rb
+15
-0
未找到文件。
lib/gitlab/middleware/read_only/controller.rb
浏览文件 @
f3e10283
...
...
@@ -69,6 +69,7 @@ module Gitlab
@route_hash
||=
Rails
.
application
.
routes
.
recognize_path
(
request
.
url
,
{
method:
request
.
request_method
})
rescue
{}
end
# Overridden in EE module
def
whitelisted_routes
grack_route
||
ReadOnly
.
internal_routes
.
any?
{
|
path
|
request
.
path
.
include?
(
path
)
}
||
lfs_route
||
sidekiq_route
end
...
...
spec/lib/gitlab/middleware/read_only_spec.rb
浏览文件 @
f3e10283
...
...
@@ -4,28 +4,6 @@ describe Gitlab::Middleware::ReadOnly do
include
Rack
::
Test
::
Methods
using
RSpec
::
Parameterized
::
TableSyntax
RSpec
::
Matchers
.
define
:be_a_redirect
do
match
do
|
response
|
response
.
status
==
301
end
end
RSpec
::
Matchers
.
define
:disallow_request
do
match
do
|
middleware
|
alert
=
middleware
.
env
[
'rack.session'
].
to_hash
.
dig
(
'flash'
,
'flashes'
,
'alert'
)
alert
&
.
include?
(
'You cannot perform write operations'
)
end
end
RSpec
::
Matchers
.
define
:disallow_request_in_json
do
match
do
|
response
|
json_response
=
JSON
.
parse
(
response
.
body
)
response
.
body
.
include?
(
'You cannot perform write operations'
)
&&
json_response
.
key?
(
'message'
)
end
end
let
(
:rack_stack
)
do
rack
=
Rack
::
Builder
.
new
do
use
ActionDispatch
::
Session
::
CacheStore
...
...
@@ -66,38 +44,38 @@ describe Gitlab::Middleware::ReadOnly do
it
'expects PATCH requests to be disallowed'
do
response
=
request
.
patch
(
'/test_request'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
expect
(
subject
).
to
disallow_request
end
it
'expects PUT requests to be disallowed'
do
response
=
request
.
put
(
'/test_request'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
expect
(
subject
).
to
disallow_request
end
it
'expects POST requests to be disallowed'
do
response
=
request
.
post
(
'/test_request'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
expect
(
subject
).
to
disallow_request
end
it
'expects a internal POST request to be allowed after a disallowed request'
do
response
=
request
.
post
(
'/test_request'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
response
=
request
.
post
(
"/api/
#{
API
::
API
.
version
}
/internal"
)
expect
(
response
).
not_to
be_
a_
redirect
expect
(
response
).
not_to
be_redirect
end
it
'expects DELETE requests to be disallowed'
do
response
=
request
.
delete
(
'/test_request'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
expect
(
subject
).
to
disallow_request
end
...
...
@@ -105,7 +83,7 @@ describe Gitlab::Middleware::ReadOnly do
expect
(
Rails
.
application
.
routes
).
to
receive
(
:recognize_path
).
and_call_original
response
=
request
.
post
(
'/root/gitlab-ce/new/master/app/info/lfs/objects/batch'
)
expect
(
response
).
to
be_
a_
redirect
expect
(
response
).
to
be_redirect
expect
(
subject
).
to
disallow_request
end
...
...
@@ -120,19 +98,19 @@ describe Gitlab::Middleware::ReadOnly do
expect
(
Rails
.
application
.
routes
).
not_to
receive
(
:recognize_path
)
response
=
request
.
post
(
"/api/
#{
API
::
API
.
version
}
/internal"
)
expect
(
response
).
not_to
be_
a_
redirect
expect
(
response
).
not_to
be_redirect
expect
(
subject
).
not_to
disallow_request
end
it
'expects requests to sidekiq admin to be allowed'
do
response
=
request
.
post
(
'/admin/sidekiq'
)
expect
(
response
).
not_to
be_
a_
redirect
expect
(
response
).
not_to
be_redirect
expect
(
subject
).
not_to
disallow_request
response
=
request
.
get
(
'/admin/sidekiq'
)
expect
(
response
).
not_to
be_
a_
redirect
expect
(
response
).
not_to
be_redirect
expect
(
subject
).
not_to
disallow_request
end
...
...
@@ -150,7 +128,7 @@ describe Gitlab::Middleware::ReadOnly do
expect
(
Rails
.
application
.
routes
).
to
receive
(
:recognize_path
).
and_call_original
response
=
request
.
post
(
path
)
expect
(
response
).
not_to
be_
a_
redirect
expect
(
response
).
not_to
be_redirect
expect
(
subject
).
not_to
disallow_request
end
end
...
...
spec/support/matchers/disallow_request_matchers.rb
0 → 100644
浏览文件 @
f3e10283
RSpec
::
Matchers
.
define
:disallow_request
do
match
do
|
middleware
|
alert
=
middleware
.
env
[
'rack.session'
].
to_hash
.
dig
(
'flash'
,
'flashes'
,
'alert'
)
alert
&
.
include?
(
'You cannot perform write operations'
)
end
end
RSpec
::
Matchers
.
define
:disallow_request_in_json
do
match
do
|
response
|
json_response
=
JSON
.
parse
(
response
.
body
)
response
.
body
.
include?
(
'You cannot perform write operations'
)
&&
json_response
.
key?
(
'message'
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录