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
839a34f3
Commit
839a34f3
authored
Sep 30, 2020
by
Michał Zając
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate UUIDv5 for Finding before saving
parent
14053e9f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
ee/app/services/security/store_report_service.rb
ee/app/services/security/store_report_service.rb
+24
-2
ee/spec/services/security/store_report_service_spec.rb
ee/spec/services/security/store_report_service_spec.rb
+8
-0
No files found.
ee/app/services/security/store_report_service.rb
View file @
839a34f3
...
...
@@ -72,10 +72,15 @@ module Security
}
begin
project
vulnerability_finding
=
project
.
vulnerability_findings
.
create_with
(
create_params
)
.
find_or_create_by!
(
find_params
)
.
find_or_initialize_by
(
find_params
)
vulnerability_finding
.
uuid
=
calculcate_uuid_v5
(
vulnerability_finding
,
find_params
)
vulnerability_finding
.
save!
vulnerability_finding
rescue
ActiveRecord
::
RecordNotUnique
project
.
vulnerability_findings
.
find_by!
(
find_params
)
rescue
ActiveRecord
::
RecordInvalid
=>
e
...
...
@@ -83,6 +88,23 @@ module Security
end
end
def
calculcate_uuid_v5
(
vulnerability_finding
,
finding_params
)
uuid_v5_name_components
=
{
report_type:
vulnerability_finding
.
report_type
,
primary_identifier_fingerprint:
vulnerability_finding
.
primary_identifier
&
.
fingerprint
||
finding_params
.
dig
(
:primary_identifier
,
:fingerprint
),
location_fingerprint:
vulnerability_finding
.
location_fingerprint
,
project_id:
project
.
id
}
if
uuid_v5_name_components
.
values
.
any?
(
&
:nil?
)
Gitlab
::
AppLogger
.
warn
(
message:
"One or more UUID name components are nil"
,
components:
uuid_v5_name_components
)
end
name
=
uuid_v5_name_components
.
values
.
join
(
'-'
)
Gitlab
::
Vulnerabilities
::
CalculateFindingUUID
.
call
(
name
)
end
def
update_vulnerability_scanner
(
finding
)
scanner
=
scanners_objects
[
finding
.
scanner
.
key
]
scanner
.
update!
(
finding
.
scanner
.
to_hash
)
...
...
ee/spec/services/security/store_report_service_spec.rb
View file @
839a34f3
...
...
@@ -53,6 +53,10 @@ RSpec.describe Security::StoreReportService, '#execute' do
it
'inserts all vulnerabilties'
do
expect
{
subject
}.
to
change
{
Vulnerability
.
count
}.
by
(
findings
)
end
it
'calculates UUIDv5 for all findings'
do
expect
(
Vulnerabilities
::
Finding
.
pluck
(
:uuid
)).
to
all
(
be_a
(
String
))
end
end
context
'invalid data'
do
...
...
@@ -118,6 +122,10 @@ RSpec.describe Security::StoreReportService, '#execute' do
expect
{
subject
}.
to
change
{
Vulnerabilities
::
Finding
.
count
}.
by
(
32
)
end
it
'calculates UUIDv5 for all findings'
do
expect
(
Vulnerabilities
::
Finding
.
pluck
(
:uuid
)).
to
all
(
be_a
(
String
))
end
it
'inserts all finding pipelines (join model) for this new pipeline'
do
expect
{
subject
}.
to
change
{
Vulnerabilities
::
FindingPipeline
.
where
(
pipeline:
new_pipeline
).
count
}.
by
(
33
)
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