Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
aa0473d0
Commit
aa0473d0
authored
Jul 17, 2013
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate fingerprint uniqueness
parent
656d800f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
15 deletions
+13
-15
app/models/key.rb
app/models/key.rb
+5
-14
spec/models/key_spec.rb
spec/models/key_spec.rb
+8
-1
No files found.
app/models/key.rb
View file @
aa0473d0
...
@@ -21,11 +21,11 @@ class Key < ActiveRecord::Base
...
@@ -21,11 +21,11 @@ class Key < ActiveRecord::Base
attr_accessible
:key
,
:title
attr_accessible
:key
,
:title
before_validation
:strip_white_space
before_validation
:strip_white_space
,
:generate_fingerpint
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
},
uniqueness:
true
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
},
uniqueness:
true
validate
:fingerprintable_key
validate
s
:fingerprint
,
uniqueness:
true
,
presence:
{
message:
'cannot be generated'
}
delegate
:name
,
:email
,
to: :user
,
prefix:
true
delegate
:name
,
:email
,
to: :user
,
prefix:
true
...
@@ -33,15 +33,6 @@ class Key < ActiveRecord::Base
...
@@ -33,15 +33,6 @@ class Key < ActiveRecord::Base
self
.
key
=
key
.
strip
unless
key
.
blank?
self
.
key
=
key
.
strip
unless
key
.
blank?
end
end
def
fingerprintable_key
return
true
unless
key
# Don't test if there is no key.
unless
generate_fingerpint
errors
.
add
(
:key
,
"can't be fingerprinted"
)
false
end
end
# projects that has this key
# projects that has this key
def
projects
def
projects
user
.
authorized_projects
user
.
authorized_projects
...
@@ -54,6 +45,9 @@ class Key < ActiveRecord::Base
...
@@ -54,6 +45,9 @@ class Key < ActiveRecord::Base
private
private
def
generate_fingerpint
def
generate_fingerpint
self
.
fingerprint
=
nil
return
unless
key
.
present?
cmd_status
=
0
cmd_status
=
0
cmd_output
=
''
cmd_output
=
''
Tempfile
.
open
(
'gitlab_key_file'
)
do
|
file
|
Tempfile
.
open
(
'gitlab_key_file'
)
do
|
file
|
...
@@ -66,9 +60,6 @@ class Key < ActiveRecord::Base
...
@@ -66,9 +60,6 @@ class Key < ActiveRecord::Base
cmd_output
.
gsub
/([\d\h]{2}:)+[\d\h]{2}/
do
|
match
|
cmd_output
.
gsub
/([\d\h]{2}:)+[\d\h]{2}/
do
|
match
|
self
.
fingerprint
=
match
self
.
fingerprint
=
match
end
end
true
else
false
end
end
end
end
end
end
spec/models/key_spec.rb
View file @
aa0473d0
...
@@ -42,10 +42,17 @@ describe Key do
...
@@ -42,10 +42,17 @@ describe Key do
build
(
:key
,
user:
user
).
should
be_valid
build
(
:key
,
user:
user
).
should
be_valid
end
end
it
"does not accept
s th
e key twice"
do
it
"does not accept
the exact sam
e key twice"
do
create
(
:key
,
user:
user
)
create
(
:key
,
user:
user
)
build
(
:key
,
user:
user
).
should_not
be_valid
build
(
:key
,
user:
user
).
should_not
be_valid
end
end
it
"does not accept a duplicate key with a different comment"
do
create
(
:key
,
user:
user
)
duplicate
=
build
(
:key
,
user:
user
)
duplicate
.
key
<<
' extra comment'
duplicate
.
should_not
be_valid
end
end
end
context
"validate it is a fingerprintable key"
do
context
"validate it is a fingerprintable key"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment