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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
ae99f05b
Commit
ae99f05b
authored
Aug 03, 2017
by
haseeb
Committed by
Rémy Coutable
Aug 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #35133 strip new lines from ssh keys
parent
118dcff0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
8 deletions
+9
-8
app/models/key.rb
app/models/key.rb
+1
-2
spec/models/key_spec.rb
spec/models/key_spec.rb
+8
-6
No files found.
app/models/key.rb
View file @
ae99f05b
...
@@ -16,8 +16,6 @@ class Key < ActiveRecord::Base
...
@@ -16,8 +16,6 @@ class Key < ActiveRecord::Base
presence:
true
,
presence:
true
,
length:
{
maximum:
5000
},
length:
{
maximum:
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
validates
:key
,
format:
{
without:
/\n|\r/
,
message:
'should be a single line'
}
validates
:fingerprint
,
validates
:fingerprint
,
uniqueness:
true
,
uniqueness:
true
,
presence:
{
message:
'cannot be generated'
}
presence:
{
message:
'cannot be generated'
}
...
@@ -31,6 +29,7 @@ class Key < ActiveRecord::Base
...
@@ -31,6 +29,7 @@ class Key < ActiveRecord::Base
after_destroy
:post_destroy_hook
after_destroy
:post_destroy_hook
def
key
=
(
value
)
def
key
=
(
value
)
value
&
.
delete!
(
"
\n\r
"
)
value
.
strip!
unless
value
.
blank?
value
.
strip!
unless
value
.
blank?
write_attribute
(
:key
,
value
)
write_attribute
(
:key
,
value
)
end
end
...
...
spec/models/key_spec.rb
View file @
ae99f05b
...
@@ -94,15 +94,17 @@ describe Key do
...
@@ -94,15 +94,17 @@ describe Key do
expect
(
key
).
not_to
be_valid
expect
(
key
).
not_to
be_valid
end
end
it
'rejects the unfingerprintable key (not a key)'
do
it
'accepts a key with newline charecters after stripping them'
do
expect
(
build
(
:key
,
key:
'ssh-rsa an-invalid-key=='
)).
not_to
be_valid
key
=
build
(
:key
)
key
.
key
=
key
.
key
.
insert
(
100
,
"
\n
"
)
key
.
key
=
key
.
key
.
insert
(
40
,
"
\r\n
"
)
expect
(
key
).
to
be_valid
end
end
it
'rejects the multiple line key'
do
it
'rejects the unfingerprintable key (not a key)'
do
key
=
build
(
:key
)
expect
(
build
(
:key
,
key:
'ssh-rsa an-invalid-key=='
)).
not_to
be_valid
key
.
key
.
tr!
(
' '
,
"
\n
"
)
expect
(
key
).
not_to
be_valid
end
end
end
end
context
'callbacks'
do
context
'callbacks'
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