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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
e5e299a8
Commit
e5e299a8
authored
Oct 25, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor code quality improvements to host key code
parent
11a214ed
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
20 deletions
+22
-20
app/models/ssh_host_key.rb
app/models/ssh_host_key.rb
+10
-10
spec/controllers/projects/mirrors_controller_spec.rb
spec/controllers/projects/mirrors_controller_spec.rb
+6
-4
spec/models/ssh_host_key_spec.rb
spec/models/ssh_host_key_spec.rb
+6
-6
No files found.
app/models/ssh_host_key.rb
View file @
e5e299a8
...
@@ -20,15 +20,16 @@ class SshHostKey
...
@@ -20,15 +20,16 @@ class SshHostKey
self
.
reactive_cache_key
=
->
(
key
)
{
[
key
.
class
.
to_s
,
key
.
id
]
}
self
.
reactive_cache_key
=
->
(
key
)
{
[
key
.
class
.
to_s
,
key
.
id
]
}
# Do not refresh the data in the background - it is not expected to change
# Do not refresh the data in the background - it is not expected to change.
# This is achieved by making the lifetime shorter than the refresh interval.
self
.
reactive_cache_refresh_interval
=
15
.
minutes
self
.
reactive_cache_refresh_interval
=
15
.
minutes
self
.
reactive_cache_lifetime
=
10
.
minutes
self
.
reactive_cache_lifetime
=
10
.
minutes
def
self
.
find_by
(
opts
=
{})
def
self
.
find_by
(
opts
=
{})
id
=
opts
.
fetch
(
:id
,
""
)
return
nil
unless
opts
.
key?
(
:id
)
project_id
,
url
=
id
.
split
(
':'
,
2
)
project
=
Project
.
where
(
id:
project_id
).
includes
(
:import_data
).
first
project_id
,
url
=
opts
[
:id
].
split
(
':'
,
2
)
project
=
Project
.
find_by
(
id:
project_id
)
project
.
presence
&&
new
(
project:
project
,
url:
url
)
project
.
presence
&&
new
(
project:
project
,
url:
url
)
end
end
...
@@ -96,13 +97,13 @@ class SshHostKey
...
@@ -96,13 +97,13 @@ class SshHostKey
# ssh-keyscan returns an exit code 0 in several error conditions, such as an
# ssh-keyscan returns an exit code 0 in several error conditions, such as an
# unknown hostname, so check both STDERR and the exit code
# unknown hostname, so check both STDERR and the exit code
if
!
status
.
success?
||
errors
.
present?
if
status
.
success?
&&
!
errors
.
present?
{
known_hosts:
known_hosts
}
else
Rails
.
logger
.
debug
(
"Failed to detect SSH host keys for
#{
id
}
:
#{
errors
}
"
)
Rails
.
logger
.
debug
(
"Failed to detect SSH host keys for
#{
id
}
:
#{
errors
}
"
)
return
{
error:
'Failed to detect SSH host keys'
}
{
error:
'Failed to detect SSH host keys'
}
end
end
{
known_hosts:
known_hosts
}
end
end
private
private
...
@@ -112,8 +113,7 @@ class SshHostKey
...
@@ -112,8 +113,7 @@ class SshHostKey
data
data
.
to_s
.
to_s
.
each_line
.
each_line
.
map
{
|
line
|
line
unless
line
.
start_with?
(
'#'
)
||
line
.
chomp
.
empty?
}
.
reject
{
|
line
|
line
.
start_with?
(
'#'
)
||
line
.
chomp
.
empty?
}
.
compact
.
uniq
.
uniq
.
sort
.
sort
.
join
.
join
...
...
spec/controllers/projects/mirrors_controller_spec.rb
View file @
e5e299a8
...
@@ -72,10 +72,12 @@ describe Projects::MirrorsController do
...
@@ -72,10 +72,12 @@ describe Projects::MirrorsController do
end
end
context
'invalid URLs'
do
context
'invalid URLs'
do
where
(
url:
%w[INVALID git@example.com:foo/bar.git ssh://git@example.com:foo/bar.git]
)
%w[
INVALID
with_them
do
git@example.com:foo/bar.git
it
'returns an error with a 400 response'
do
ssh://git@example.com:foo/bar.git
]
.
each
do
|
url
|
it
"returns an error with a 400 response for URL
#{
url
.
inspect
}
"
do
do_get
(
project
,
url
)
do_get
(
project
,
url
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
expect
(
response
).
to
have_gitlab_http_status
(
400
)
...
...
spec/models/ssh_host_key_spec.rb
View file @
e5e299a8
...
@@ -85,7 +85,7 @@ describe SshHostKey do
...
@@ -85,7 +85,7 @@ describe SshHostKey do
end
end
describe
'#host_keys_changed?'
do
describe
'#host_keys_changed?'
do
where
(
:
a
,
:
b
,
:result
)
do
where
(
:
known_hosts_a
,
:known_hosts_
b
,
:result
)
do
known_hosts
|
extra
|
true
known_hosts
|
extra
|
true
known_hosts
|
"foo
\n
"
|
true
known_hosts
|
"foo
\n
"
|
true
known_hosts
|
''
|
true
known_hosts
|
''
|
true
...
@@ -99,15 +99,15 @@ describe SshHostKey do
...
@@ -99,15 +99,15 @@ describe SshHostKey do
end
end
with_them
do
with_them
do
let
(
:compare_host_keys
)
{
b
}
let
(
:compare_host_keys
)
{
known_hosts_
b
}
subject
{
ssh_host_key
.
host_keys_changed?
}
subject
{
ssh_host_key
.
host_keys_changed?
}
context
'(normal)'
do
context
'(normal)'
do
let
(
:compare_host_keys
)
{
b
}
let
(
:compare_host_keys
)
{
known_hosts_
b
}
before
do
before
do
expect
(
ssh_host_key
).
to
receive
(
:known_hosts
).
and_return
(
a
)
expect
(
ssh_host_key
).
to
receive
(
:known_hosts
).
and_return
(
known_hosts_
a
)
end
end
it
{
is_expected
.
to
eq
(
result
)
}
it
{
is_expected
.
to
eq
(
result
)
}
...
@@ -115,10 +115,10 @@ describe SshHostKey do
...
@@ -115,10 +115,10 @@ describe SshHostKey do
# Comparisons should be symmetrical, so test the reverse too
# Comparisons should be symmetrical, so test the reverse too
context
'(reversed)'
do
context
'(reversed)'
do
let
(
:compare_host_keys
)
{
a
}
let
(
:compare_host_keys
)
{
known_hosts_
a
}
before
do
before
do
expect
(
ssh_host_key
).
to
receive
(
:known_hosts
).
and_return
(
b
)
expect
(
ssh_host_key
).
to
receive
(
:known_hosts
).
and_return
(
known_hosts_
b
)
end
end
it
{
is_expected
.
to
eq
(
result
)
}
it
{
is_expected
.
to
eq
(
result
)
}
...
...
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