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
5973f75c
Commit
5973f75c
authored
Apr 02, 2020
by
Jonathan Schafer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ruby code from view to helper
Includes additional tests
parent
e55f7211
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
17 deletions
+60
-17
ee/app/helpers/vulnerabilities_helper.rb
ee/app/helpers/vulnerabilities_helper.rb
+11
-0
ee/app/views/projects/security/vulnerabilities/show.html.haml
...pp/views/projects/security/vulnerabilities/show.html.haml
+13
-16
ee/spec/helpers/vulnerabilities_helper_spec.rb
ee/spec/helpers/vulnerabilities_helper_spec.rb
+35
-0
locale/gitlab.pot
locale/gitlab.pot
+1
-1
No files found.
ee/app/helpers/vulnerabilities_helper.rb
View file @
5973f75c
...
...
@@ -41,4 +41,15 @@ module VulnerabilitiesHelper
solution:
remediation
?
remediation
[
'summary'
]
:
occurrence
[
:solution
]
)
end
def
vulnerability_file_link
(
vulnerability
)
finding
=
vulnerability
.
finding
location
=
finding
.
location
branch
=
finding
.
pipelines
&
.
last
&
.
sha
||
vulnerability
.
project
.
default_branch
link_text
=
"
#{
location
[
'file'
]
}
:
#{
location
[
'start_line'
]
}
"
offset
=
location
[
'start_line'
]
?
"#L
#{
location
[
'start_line'
]
}
"
:
''
link_path
=
project_blob_path
(
vulnerability
.
project
,
tree_join
(
branch
,
location
[
'file'
]))
+
offset
link_to
link_text
,
link_path
,
target:
'_blank'
,
rel:
'noopener noreferrer'
end
end
ee/app/views/projects/security/vulnerabilities/show.html.haml
View file @
5973f75c
...
...
@@ -3,6 +3,8 @@
-
breadcrumb_title
@vulnerability
.
id
-
page_title
@vulnerability
.
title
-
page_description
@vulnerability
.
description
-
finding
=
@vulnerability
.
finding
-
location
=
finding
.
location
#js-vulnerability-management-app
{
data:
vulnerability_data
(
@vulnerability
,
@pipeline
)
}
...
...
@@ -11,9 +13,8 @@
%h2
.title
=
@vulnerability
.
title
.description
.md
-
location
=
@vulnerability
.
finding
.
location
%h3
=
"Description"
%p
=
@vulnerability
.
finding
.
description
%p
=
finding
.
description
%ul
%li
=
_
(
"Severity: %{severity}"
)
%
{
severity:
@vulnerability
.
severity
}
%li
=
_
(
"Confidence: %{confidence}"
)
%
{
confidence:
@vulnerability
.
confidence
}
...
...
@@ -29,31 +30,27 @@
%h3
=
_
(
'Location'
)
%ul
%li
-
link_text
=
"
#{
location
[
'file'
]
}
:
#{
location
[
'start_line'
]
}
"
-
offset
=
location
[
'start_line'
]
?
"#L
#{
location
[
'start_line'
]
}
"
:
''
-
branch
=
@vulnerability
.
finding
.
pipelines
&
.
last
&
.
sha
||
@vulnerability
.
project
.
default_branch
=
_
(
"File:"
)
%a
{
href:
project_blob_path
(
@project
,
tree_join
(
branch
,
location
[
'file'
]))
+
offset
,
target:
'_blank'
,
rel:
'noopener noreferrer'
}=
link_text
=
vulnerability_file_link
(
@vulnerability
)
-
if
location
[
'class'
]
%li
=
_
(
"Class: "
)
+
location
[
'class'
]
%li
=
_
(
"Class:"
)
=
location
[
'class'
]
-
if
location
[
'method'
]
%li
=
_
(
"Method:"
)
%code
=
location
[
'method'
]
-
if
@vulnerability
.
finding
.
links
.
any?
-
if
finding
.
links
.
any?
%h3
=
_
(
"Links"
)
%ul
-
@vulnerability
.
finding
.
links
.
each
do
|
link
|
%li
%a
{
:href
=>
link
[
"url"
],
target:
"_blank"
,
rel:
'noopener noreferrer'
}=
link
[
"url"
]
-
finding
.
links
.
each
do
|
link
|
%li
=
link_to
link
[
"url"
],
target:
'_blank'
,
rel:
'noopener noreferrer'
-
if
@vulnerability
.
finding
.
identifiers
.
any?
-
if
finding
.
identifiers
.
any?
%h3
=
_
(
"Identifiers"
)
%ul
-
@vulnerability
.
finding
.
identifiers
.
each
do
|
identifier
|
%li
%a
{
:href
=>
identifier
.
url
,
target:
"_blank"
,
rel:
'noopener noreferrer'
}=
identifier
.
name
-
finding
.
identifiers
.
each
do
|
identifier
|
%li
=
link_to
identifier
.
name
,
identifier
.
url
,
target:
'_blank'
,
rel:
'noopener noreferrer'
#js-vulnerability-footer
{
data:
vulnerability_data
(
@vulnerability
,
@pipeline
)
}
ee/spec/helpers/vulnerabilities_helper_spec.rb
View file @
5973f75c
...
...
@@ -121,4 +121,39 @@ describe VulnerabilitiesHelper do
end
end
end
describe
'#vulnerability_file_link'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
)
}
let
(
:finding
)
{
create
(
:vulnerabilities_occurrence
,
pipelines:
[
pipeline
],
project:
project
,
severity: :high
)
}
let
(
:vulnerability
)
{
create
(
:vulnerability
,
findings:
[
finding
],
project:
project
)
}
subject
{
helper
.
vulnerability_file_link
(
vulnerability
)
}
it
'returns a link to the vulnerability file location'
do
expect
(
subject
).
to
include
(
vulnerability
.
finding
.
location
[
'file'
],
"
#{
vulnerability
.
finding
.
location
[
'start_line'
]
}
"
,
vulnerability
.
finding
.
pipelines
&
.
last
&
.
sha
)
end
context
'when vulnerability is not linked to a commit'
do
it
'uses the default branch'
do
vulnerability
.
finding
.
pipelines
=
[]
vulnerability
.
finding
.
save
expect
(
subject
).
to
include
(
vulnerability
.
project
.
default_branch
)
end
end
context
'when vulnerability is not on a specific line'
do
it
'does not include a reference to the line number'
do
vulnerability
.
finding
.
location
[
'start_line'
]
=
nil
vulnerability
.
finding
.
save
expect
(
subject
).
not_to
include
(
'#L'
)
end
end
end
end
locale/gitlab.pot
View file @
5973f75c
...
...
@@ -3953,7 +3953,7 @@ msgstr ""
msgid "Class"
msgstr ""
msgid "Class:
"
msgid "Class:"
msgstr ""
msgid "Classification Label (optional)"
...
...
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