Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f3ce02b5
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 搜索 >>
提交
f3ce02b5
编写于
9月 21, 2012
作者:
S
Sytse Sijbrandij
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reject ssh keys that break gitolite.
Failing test. Working check.
上级
8f9a450e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
6 deletion
+35
-6
app/models/key.rb
app/models/key.rb
+16
-1
spec/factories.rb
spec/factories.rb
+7
-5
spec/models/key_spec.rb
spec/models/key_spec.rb
+12
-0
未找到文件。
app/models/key.rb
浏览文件 @
f3ce02b5
...
@@ -18,7 +18,7 @@ class Key < ActiveRecord::Base
...
@@ -18,7 +18,7 @@ class Key < ActiveRecord::Base
before_save
:set_identifier
before_save
:set_identifier
before_validation
:strip_white_space
before_validation
:strip_white_space
delegate
:name
,
:email
,
to: :user
,
prefix:
true
delegate
:name
,
:email
,
to: :user
,
prefix:
true
validate
:unique_key
validate
:unique_key
,
:fingerprintable_key
def
strip_white_space
def
strip_white_space
self
.
key
=
self
.
key
.
strip
unless
self
.
key
.
blank?
self
.
key
=
self
.
key
.
strip
unless
self
.
key
.
blank?
...
@@ -32,6 +32,21 @@ class Key < ActiveRecord::Base
...
@@ -32,6 +32,21 @@ class Key < ActiveRecord::Base
end
end
end
end
def
fingerprintable_key
return
true
unless
key
# Don't test if there is no key.
# `ssh-keygen -lf /dev/stdin <<< "#{key}"` errors with: redirection unexpected
file
=
Tempfile
.
new
(
'key_file'
)
begin
file
.
puts
key
file
.
rewind
fingerprint_output
=
`ssh-keygen -lf
#{
file
.
path
}
2>&1`
# Catch stderr.
ensure
file
.
close
file
.
unlink
# deletes the temp file
end
errors
.
add
(
:key
,
"can't be fingerprinted"
)
if
fingerprint_output
.
match
(
"failed"
)
end
def
set_identifier
def
set_identifier
if
is_deploy_key
if
is_deploy_key
self
.
identifier
=
"deploy_"
+
Digest
::
MD5
.
hexdigest
(
key
)
self
.
identifier
=
"deploy_"
+
Digest
::
MD5
.
hexdigest
(
key
)
...
...
spec/factories.rb
浏览文件 @
f3ce02b5
...
@@ -83,11 +83,7 @@ FactoryGirl.define do
...
@@ -83,11 +83,7 @@ FactoryGirl.define do
factory
:key
do
factory
:key
do
title
title
key
do
key
do
"""
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=
"""
end
end
factory
:deploy_key
do
factory
:deploy_key
do
...
@@ -97,6 +93,12 @@ FactoryGirl.define do
...
@@ -97,6 +93,12 @@ FactoryGirl.define do
factory
:personal_key
do
factory
:personal_key
do
user
user
end
end
factory
:key_with_a_space_in_the_middle
do
key
do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
end
end
end
end
factory
:milestone
do
factory
:milestone
do
...
...
spec/models/key_spec.rb
浏览文件 @
f3ce02b5
...
@@ -46,4 +46,16 @@ describe Key do
...
@@ -46,4 +46,16 @@ describe Key do
end
end
end
end
end
end
context
"validate it is a fingerprintable key"
do
let
(
:user
)
{
Factory
.
create
(
:user
)
}
it
"accepts the fingerprintable key"
do
build
(
:key
,
user:
user
).
should
be_valid
end
it
"rejects the unfingerprintable key"
do
build
(
:key_with_a_space_in_the_middle
).
should_not
be_valid
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录