Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
eb05bdc6
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 搜索 >>
提交
eb05bdc6
编写于
8月 28, 2017
作者:
N
Nick Thomas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move the key restriction validation to its own class
上级
b84ca08e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
10 deletion
+33
-10
app/models/application_setting.rb
app/models/application_setting.rb
+2
-8
app/validators/key_restriction_validator.rb
app/validators/key_restriction_validator.rb
+29
-0
lib/api/settings.rb
lib/api/settings.rb
+1
-1
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+1
-1
未找到文件。
app/models/application_setting.rb
浏览文件 @
eb05bdc6
...
...
@@ -15,13 +15,9 @@ class ApplicationSetting < ActiveRecord::Base
# Setting a key restriction to `-1` means that all keys of this type are
# forbidden.
FORBIDDEN_KEY_VALUE
=
-
1
FORBIDDEN_KEY_VALUE
=
KeyRestrictionValidator
::
FORBIDDEN
SUPPORTED_KEY_TYPES
=
%i[rsa dsa ecdsa ed25519]
.
freeze
def
self
.
supported_key_restrictions
(
type
)
[
0
,
*
Gitlab
::
SSHPublicKey
.
supported_sizes
(
type
),
FORBIDDEN_KEY_VALUE
]
end
serialize
:restricted_visibility_levels
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:import_sources
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:disabled_oauth_sign_in_sources
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
...
...
@@ -156,9 +152,7 @@ class ApplicationSetting < ActiveRecord::Base
numericality:
{
greater_than_or_equal_to:
0
}
SUPPORTED_KEY_TYPES
.
each
do
|
type
|
validates
:"
#{
type
}
_key_restriction"
,
presence:
true
,
inclusion:
{
in:
ApplicationSetting
.
supported_key_restrictions
(
type
)
}
validates
:"
#{
type
}
_key_restriction"
,
presence:
true
,
key_restriction:
{
type:
type
}
end
validates_each
:restricted_visibility_levels
do
|
record
,
attr
,
value
|
...
...
app/validators/key_restriction_validator.rb
0 → 100644
浏览文件 @
eb05bdc6
class
KeyRestrictionValidator
<
ActiveModel
::
EachValidator
FORBIDDEN
=
-
1
def
self
.
supported_sizes
(
type
)
Gitlab
::
SSHPublicKey
.
supported_sizes
(
type
)
end
def
self
.
supported_key_restrictions
(
type
)
[
0
,
*
supported_sizes
(
type
),
FORBIDDEN
]
end
def
validate_each
(
record
,
attribute
,
value
)
unless
valid_restriction?
(
value
)
record
.
errors
.
add
(
attribute
,
"must be forbidden, allowed, or one of these sizes:
#{
supported_sizes_message
}
"
)
end
end
private
def
supported_sizes_message
sizes
=
self
.
class
.
supported_sizes
(
options
[
:type
])
sizes
.
to_sentence
(
last_word_connector:
', or '
,
two_words_connector:
' or '
)
end
def
valid_restriction?
(
value
)
choices
=
self
.
class
.
supported_key_restrictions
(
options
[
:type
])
choices
.
include?
(
value
)
end
end
lib/api/settings.rb
浏览文件 @
eb05bdc6
...
...
@@ -125,7 +125,7 @@ module API
ApplicationSetting
::
SUPPORTED_KEY_TYPES
.
each
do
|
type
|
optional
:"
#{
type
}
_key_restriction"
,
type:
Integer
,
values:
ApplicationSetting
.
supported_key_restrictions
(
type
),
values:
KeyRestrictionValidator
.
supported_key_restrictions
(
type
),
desc:
"Restrictions on the complexity of uploaded
#{
type
.
upcase
}
keys. A value of
#{
ApplicationSetting
::
FORBIDDEN_KEY_VALUE
}
disables all
#{
type
.
upcase
}
keys."
end
...
...
spec/models/application_setting_spec.rb
浏览文件 @
eb05bdc6
...
...
@@ -85,7 +85,7 @@ describe ApplicationSetting do
let
(
:field
)
{
:"
#{
type
}
_key_restriction"
}
it
{
is_expected
.
to
validate_presence_of
(
field
)
}
it
{
is_expected
.
to
allow_value
(
*
described_class
.
supported_key_restrictions
(
type
)).
for
(
field
)
}
it
{
is_expected
.
to
allow_value
(
*
KeyRestrictionValidator
.
supported_key_restrictions
(
type
)).
for
(
field
)
}
it
{
is_expected
.
not_to
allow_value
(
128
).
for
(
field
)
}
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录