Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
90c586f6
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,体验更适合开发者的 AI 搜索 >>
提交
90c586f6
编写于
9月 01, 2020
作者:
G
GitLab Bot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add latest changes from gitlab-org/security/gitlab@13-1-stable-ee
上级
6528a71a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
97 addition
and
8 deletion
+97
-8
app/services/applications/create_service.rb
app/services/applications/create_service.rb
+10
-1
changelogs/unreleased/security-add-presence-validation-oauth-apps.yml
...nreleased/security-add-presence-validation-oauth-apps.yml
+5
-0
spec/controllers/admin/applications_controller_spec.rb
spec/controllers/admin/applications_controller_spec.rb
+14
-2
spec/controllers/oauth/applications_controller_spec.rb
spec/controllers/oauth/applications_controller_spec.rb
+21
-2
spec/features/admin/admin_manage_applications_spec.rb
spec/features/admin/admin_manage_applications_spec.rb
+17
-1
spec/features/profiles/user_manages_applications_spec.rb
spec/features/profiles/user_manages_applications_spec.rb
+13
-0
spec/services/applications/create_service_spec.rb
spec/services/applications/create_service_spec.rb
+17
-2
未找到文件。
app/services/applications/create_service.rb
浏览文件 @
90c586f6
...
...
@@ -11,7 +11,16 @@ module Applications
# EE would override and use `request` arg
def
execute
(
request
)
Doorkeeper
::
Application
.
create
(
params
)
@application
=
Doorkeeper
::
Application
.
new
(
params
)
unless
params
[
:scopes
].
present?
@application
.
errors
.
add
(
:base
,
_
(
"Scopes can't be blank"
))
return
@application
end
@application
.
save
@application
end
end
end
...
...
changelogs/unreleased/security-add-presence-validation-oauth-apps.yml
0 → 100644
浏览文件 @
90c586f6
---
title
:
Add scope presence validation to OAuth Application creation
merge_request
:
author
:
type
:
security
spec/controllers/admin/applications_controller_spec.rb
浏览文件 @
90c586f6
...
...
@@ -40,7 +40,7 @@ RSpec.describe Admin::ApplicationsController do
describe
'POST #create'
do
it
'creates the application'
do
create_params
=
attributes_for
(
:application
,
trusted:
true
,
confidential:
false
)
create_params
=
attributes_for
(
:application
,
trusted:
true
,
confidential:
false
,
scopes:
[
'api'
]
)
expect
do
post
:create
,
params:
{
doorkeeper_application:
create_params
}
...
...
@@ -63,7 +63,7 @@ RSpec.describe Admin::ApplicationsController do
context
'when the params are for a confidential application'
do
it
'creates a confidential application'
do
create_params
=
attributes_for
(
:application
,
confidential:
true
)
create_params
=
attributes_for
(
:application
,
confidential:
true
,
scopes:
[
'read_user'
]
)
expect
do
post
:create
,
params:
{
doorkeeper_application:
create_params
}
...
...
@@ -75,6 +75,18 @@ RSpec.describe Admin::ApplicationsController do
expect
(
application
).
to
have_attributes
(
create_params
.
except
(
:uid
,
:owner_type
))
end
end
context
'when scopes are not present'
do
it
'renders the application form on errors'
do
create_params
=
attributes_for
(
:application
,
trusted:
true
,
confidential:
false
)
expect
do
post
:create
,
params:
{
doorkeeper_application:
create_params
}
end
.
not_to
change
{
Doorkeeper
::
Application
.
count
}
expect
(
response
).
to
render_template
:new
end
end
end
describe
'PATCH #update'
do
...
...
spec/controllers/oauth/applications_controller_spec.rb
浏览文件 @
90c586f6
...
...
@@ -123,7 +123,8 @@ RSpec.describe Oauth::ApplicationsController do
invalid_uri_params
=
{
doorkeeper_application:
{
name:
'foo'
,
redirect_uri:
'javascript://alert()'
redirect_uri:
'javascript://alert()'
,
scopes:
[
'api'
]
}
}
...
...
@@ -133,6 +134,23 @@ RSpec.describe Oauth::ApplicationsController do
end
end
context
'when scopes are not present'
do
render_views
it
'shows an error for blank scopes'
do
invalid_uri_params
=
{
doorkeeper_application:
{
name:
'foo'
,
redirect_uri:
'http://example.org'
}
}
post
:create
,
params:
invalid_uri_params
expect
(
response
.
body
).
to
include
'Scopes can't be blank'
end
end
it_behaves_like
'redirects to login page when the user is not signed in'
it_behaves_like
'redirects to 2fa setup page when the user requires it'
end
...
...
@@ -156,7 +174,8 @@ RSpec.describe Oauth::ApplicationsController do
{
doorkeeper_application:
{
name:
'foo'
,
redirect_uri:
'http://example.org'
redirect_uri:
'http://example.org'
,
scopes:
[
'api'
]
}
}
end
...
...
spec/features/admin/admin_manage_applications_spec.rb
浏览文件 @
90c586f6
...
...
@@ -7,7 +7,7 @@ RSpec.describe 'admin manage applications' do
sign_in
(
create
(
:admin
))
end
it
do
it
'creates new oauth application'
do
visit
admin_applications_path
click_on
'New application'
...
...
@@ -16,6 +16,7 @@ RSpec.describe 'admin manage applications' do
fill_in
:doorkeeper_application_name
,
with:
'test'
fill_in
:doorkeeper_application_redirect_uri
,
with:
'https://test.com'
check
:doorkeeper_application_trusted
check
:doorkeeper_application_scopes_read_user
click_on
'Submit'
expect
(
page
).
to
have_content
(
'Application: test'
)
expect
(
page
).
to
have_content
(
'Application ID'
)
...
...
@@ -43,4 +44,19 @@ RSpec.describe 'admin manage applications' do
end
expect
(
page
.
find
(
'.oauth-applications'
)).
not_to
have_content
(
'test_changed'
)
end
context
'when scopes are blank'
do
it
'returns an error'
do
visit
admin_applications_path
click_on
'New application'
expect
(
page
).
to
have_content
(
'New application'
)
fill_in
:doorkeeper_application_name
,
with:
'test'
fill_in
:doorkeeper_application_redirect_uri
,
with:
'https://test.com'
click_on
'Submit'
expect
(
page
).
to
have_content
(
"Scopes can't be blank"
)
end
end
end
spec/features/profiles/user_manages_applications_spec.rb
浏览文件 @
90c586f6
...
...
@@ -15,6 +15,7 @@ RSpec.describe 'User manages applications' do
fill_in
:doorkeeper_application_name
,
with:
'test'
fill_in
:doorkeeper_application_redirect_uri
,
with:
'https://test.com'
check
:doorkeeper_application_scopes_read_user
click_on
'Save application'
expect
(
page
).
to
have_content
'Application: test'
...
...
@@ -41,4 +42,16 @@ RSpec.describe 'User manages applications' do
end
expect
(
page
.
find
(
'.oauth-applications'
)).
not_to
have_content
'test_changed'
end
context
'when scopes are blank'
do
it
'returns an error'
do
expect
(
page
).
to
have_content
'Add new application'
fill_in
:doorkeeper_application_name
,
with:
'test'
fill_in
:doorkeeper_application_redirect_uri
,
with:
'https://test.com'
click_on
'Save application'
expect
(
page
).
to
have_content
(
"Scopes can't be blank"
)
end
end
end
spec/services/applications/create_service_spec.rb
浏览文件 @
90c586f6
...
...
@@ -6,9 +6,24 @@ describe ::Applications::CreateService do
include
TestRequestHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
attributes_for
(
:application
)
}
subject
{
described_class
.
new
(
user
,
params
)
}
it
{
expect
{
subject
.
execute
(
test_request
)
}.
to
change
{
Doorkeeper
::
Application
.
count
}.
by
(
1
)
}
context
'when scopes are present'
do
let
(
:params
)
{
attributes_for
(
:application
,
scopes:
[
'read_user'
])
}
it
{
expect
{
subject
.
execute
(
test_request
)
}.
to
change
{
Doorkeeper
::
Application
.
count
}.
by
(
1
)
}
end
context
'when scopes are missing'
do
let
(
:params
)
{
attributes_for
(
:application
)
}
it
{
expect
{
subject
.
execute
(
test_request
)
}.
not_to
change
{
Doorkeeper
::
Application
.
count
}
}
it
'includes blank scopes error message'
do
application
=
subject
.
execute
(
test_request
)
expect
(
application
.
errors
.
full_messages
).
to
include
"Scopes can't be blank"
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录