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
94c29a86
Commit
94c29a86
authored
Apr 01, 2020
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor VulnerabilitesHelper with new serializer
parent
f8238cde
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
20 deletions
+55
-20
ee/app/helpers/vulnerabilities_helper.rb
ee/app/helpers/vulnerabilities_helper.rb
+1
-1
ee/spec/helpers/vulnerabilities_helper_spec.rb
ee/spec/helpers/vulnerabilities_helper_spec.rb
+49
-16
ee/spec/serializers/vulnerability_entity_spec.rb
ee/spec/serializers/vulnerability_entity_spec.rb
+5
-3
No files found.
ee/app/helpers/vulnerabilities_helper.rb
View file @
94c29a86
...
...
@@ -5,7 +5,7 @@ module VulnerabilitiesHelper
return
unless
vulnerability
{
vulnerability_json:
vulnerability
.
to_json
,
vulnerability_json:
VulnerabilitySerializer
.
new
.
represent
(
vulnerability
)
.
to_json
,
project_fingerprint:
vulnerability
.
finding
.
project_fingerprint
,
create_issue_url:
create_vulnerability_feedback_issue_path
(
vulnerability
.
finding
.
project
),
pipeline_json:
vulnerability_pipeline_data
(
pipeline
).
to_json
,
...
...
ee/spec/helpers/vulnerabilities_helper_spec.rb
View file @
94c29a86
...
...
@@ -3,29 +3,65 @@
require
'spec_helper'
describe
VulnerabilitiesHelper
do
let_it_be
(
:user
)
{
build
(
:user
)
}
let_it_be
(
:vulnerability
)
{
create
(
:vulnerability
,
:with_findings
,
title:
"My vulnerability"
)
}
let_it_be
(
:finding
)
{
vulnerability
.
finding
}
let
(
:vulnerability_serializer_hash
)
do
vulnerability
.
slice
(
:id
,
:title
,
:state
,
:severity
,
:confidence
,
:report_type
,
:resolved_on_default_branch
,
:project_default_branch
,
:resolved_by_id
,
:dismissed_by_id
,
:confirmed_by_id
)
end
let
(
:occurrence_serializer_hash
)
do
finding
.
slice
(
:description
,
:identifiers
,
:links
,
:location
,
:name
,
:issue_feedback
,
:project
,
:solution
)
end
before
do
allow
(
helper
).
to
receive
(
:can?
).
and_return
(
true
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
RSpec
.
shared_examples
'vulnerability properties'
do
before
do
vulnerability_serializer_stub
=
instance_double
(
"VulnerabilitySerializer"
)
expect
(
VulnerabilitySerializer
).
to
receive
(
:new
).
and_return
(
vulnerability_serializer_stub
)
expect
(
vulnerability_serializer_stub
).
to
receive
(
:represent
).
with
(
vulnerability
).
and_return
(
vulnerability_serializer_hash
)
occurrence_serializer_stub
=
instance_double
(
"Vulnerabilities::OccurrenceSerializer"
)
expect
(
Vulnerabilities
::
OccurrenceSerializer
).
to
receive
(
:new
).
and_return
(
occurrence_serializer_stub
)
expect
(
occurrence_serializer_stub
).
to
receive
(
:represent
).
with
(
finding
).
and_return
(
occurrence_serializer_hash
)
end
it
'has expected vulnerability properties'
do
expect
(
subject
).
to
include
(
vulnerability_json:
vulnerability
.
to_json
,
vulnerability_json:
kind_of
(
String
)
,
project_fingerprint:
vulnerability
.
finding
.
project_fingerprint
,
create_issue_url:
anything
,
create_issue_url:
kind_of
(
String
)
,
has_mr:
anything
,
vulnerability_feedback_help_path:
anything
,
finding_json:
anything
vulnerability_feedback_help_path:
kind_of
(
String
)
,
finding_json:
kind_of
(
String
)
)
end
end
before
do
allow
(
helper
).
to
receive
(
:can?
).
and_return
(
true
)
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
end
let
(
:user
)
{
build
(
:user
)
}
describe
'#vulnerability_data'
do
let
(
:vulnerability
)
{
create
(
:vulnerability
,
:with_findings
)
}
subject
{
helper
.
vulnerability_data
(
vulnerability
,
pipeline
)
}
describe
'when pipeline exists'
do
...
...
@@ -55,9 +91,6 @@ describe VulnerabilitiesHelper do
end
describe
'#vulnerability_finding_data'
do
let
(
:vulnerability
)
{
create
(
:vulnerability
,
:with_findings
)
}
let
(
:finding
)
{
vulnerability
.
finding
}
subject
{
helper
.
vulnerability_finding_data
(
finding
)
}
it
"returns finding information"
do
...
...
ee/spec/serializers/vulnerability_entity_spec.rb
View file @
94c29a86
...
...
@@ -3,12 +3,11 @@
require
'spec_helper'
describe
VulnerabilityEntity
do
let
(
:entity
)
{
described_class
.
new
(
vulnerability
)
}
let
(
:vulnerability
)
{
create
(
:vulnerability
,
project:
project
,
author:
user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
subject
{
entity
.
as_json
}
subject
{
described_class
.
new
(
vulnerability
)
.
as_json
}
it
'exposes vulnerability-specific elements'
do
expect
(
subject
).
to
match
(
...
...
@@ -19,7 +18,10 @@ describe VulnerabilityEntity do
confidence:
vulnerability
.
confidence
,
report_type:
vulnerability
.
report_type
,
resolved_on_default_branch:
vulnerability
.
resolved_on_default_branch
,
project_default_branch:
vulnerability
.
project_default_branch
project_default_branch:
vulnerability
.
project_default_branch
,
resolved_by_id:
vulnerability
.
resolved_by_id
,
dismissed_by_id:
vulnerability
.
dismissed_by_id
,
confirmed_by_id:
vulnerability
.
confirmed_by_id
)
end
end
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