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
5a98e0ce
Commit
5a98e0ce
authored
Oct 29, 2020
by
Michał Zając
Committed by
Mark Chao
Nov 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compute UUID before creating or updating Finding
Additional, minor changes: * Remove debugging logs * Update specs
parent
573a263c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
ee/app/services/security/store_report_service.rb
ee/app/services/security/store_report_service.rb
+4
-7
ee/lib/gitlab/ci/reports/security/finding.rb
ee/lib/gitlab/ci/reports/security/finding.rb
+0
-2
ee/spec/services/security/store_report_service_spec.rb
ee/spec/services/security/store_report_service_spec.rb
+14
-1
No files found.
ee/app/services/security/store_report_service.rb
View file @
5a98e0ce
...
...
@@ -48,6 +48,7 @@ module Security
end
vulnerability_params
=
finding
.
to_hash
.
except
(
:compare_key
,
:identifiers
,
:location
,
:scanner
,
:scan
,
:links
)
vulnerability_params
[
:uuid
]
=
calculcate_uuid_v5
(
finding
)
vulnerability_finding
=
create_or_find_vulnerability_finding
(
finding
,
vulnerability_params
)
update_vulnerability_scanner
(
finding
)
...
...
@@ -81,8 +82,6 @@ module Security
.
create_with
(
create_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
...
...
@@ -92,11 +91,11 @@ module Security
end
end
def
calculcate_uuid_v5
(
vulnerability_finding
,
finding_params
)
def
calculcate_uuid_v5
(
vulnerability_finding
)
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
,
primary_identifier_fingerprint:
vulnerability_finding
.
primary_
fingerprint
,
location_fingerprint:
vulnerability_finding
.
location
.
fingerprint
,
project_id:
project
.
id
}
...
...
@@ -106,8 +105,6 @@ module Security
name
=
uuid_v5_name_components
.
values
.
join
(
'-'
)
Gitlab
::
AppLogger
.
debug
(
message:
"Generating UUIDv5 with name:
#{
name
}
"
)
if
Gitlab
.
dev_env_or_com?
Gitlab
::
Vulnerabilities
::
CalculateFindingUUID
.
call
(
name
)
end
...
...
ee/lib/gitlab/ci/reports/security/finding.rb
View file @
5a98e0ce
...
...
@@ -97,8 +97,6 @@ module Gitlab
end
end
protected
def
primary_fingerprint
primary_identifier
&
.
fingerprint
end
...
...
ee/spec/services/security/store_report_service_spec.rb
View file @
5a98e0ce
...
...
@@ -2,6 +2,17 @@
require
'spec_helper'
UUID_REGEXP
=
Regexp
.
new
(
"^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-"
\
"([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$"
).
freeze
def
is_uuid_v5?
(
uuid_string
)
raise
TypeError
unless
uuid_string
.
is_a?
(
String
)
uuid_components
=
uuid_string
.
downcase
.
scan
(
UUID_REGEXP
).
first
time_hi_and_version
=
uuid_components
[
2
].
to_i
(
16
)
(
time_hi_and_version
>>
12
)
==
5
end
RSpec
.
describe
Security
::
StoreReportService
,
'#execute'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:artifact
)
{
create
(
:ee_ci_job_artifact
,
trait
)
}
...
...
@@ -57,7 +68,9 @@ RSpec.describe Security::StoreReportService, '#execute' do
end
it
'calculates UUIDv5 for all findings'
do
expect
(
Vulnerabilities
::
Finding
.
pluck
(
:uuid
)).
to
all
(
be_a
(
String
))
uuids
=
Vulnerabilities
::
Finding
.
pluck
(
:uuid
)
expect
(
uuids
).
to
all
(
be_a
(
String
))
expect
(
uuids
.
all?
{
|
uuid
|
is_uuid_v5?
(
uuid
)
}).
to
be_truthy
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