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
fe6018b3
Commit
fe6018b3
authored
Feb 07, 2022
by
Jonathan Schafer
Committed by
Adam Hegyi
Feb 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace removed files
parent
c78227e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
lib/gitlab/background_migration/remove_vulnerability_finding_links.rb
...ackground_migration/remove_vulnerability_finding_links.rb
+19
-0
spec/lib/gitlab/background_migration/remove_vulnerability_finding_links_spec.rb
...ound_migration/remove_vulnerability_finding_links_spec.rb
+66
-0
No files found.
lib/gitlab/background_migration/remove_vulnerability_finding_links.rb
0 → 100644
View file @
fe6018b3
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# Remove vulnerability finding link records
# The records will be repopulated from the `raw_metadata`
# column of `vulnerability_occurrences` once the unique
# index is in place.
class
RemoveVulnerabilityFindingLinks
include
Gitlab
::
Database
::
DynamicModelHelpers
def
perform
(
start_id
,
stop_id
)
define_batchable_model
(
'vulnerability_finding_links'
,
connection:
ActiveRecord
::
Base
.
connection
)
.
where
(
id:
start_id
..
stop_id
)
.
delete_all
end
end
end
end
spec/lib/gitlab/background_migration/remove_vulnerability_finding_links_spec.rb
0 → 100644
View file @
fe6018b3
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
RemoveVulnerabilityFindingLinks
,
:migration
,
schema:
20211104165220
do
let
(
:vulnerability_findings
)
{
table
(
:vulnerability_occurrences
)
}
let
(
:finding_links
)
{
table
(
:vulnerability_finding_links
)
}
let
(
:namespace
)
{
table
(
:namespaces
).
create!
(
name:
'user'
,
path:
'user'
,
type:
Namespaces
::
UserNamespace
.
sti_name
)
}
let
(
:project
)
{
table
(
:projects
).
create!
(
namespace_id:
namespace
.
id
)
}
let
(
:scanner
)
{
table
(
:vulnerability_scanners
).
create!
(
project_id:
project
.
id
,
external_id:
'scanner'
,
name:
'scanner'
)
}
let
(
:vulnerability_identifier
)
do
table
(
:vulnerability_identifiers
).
create!
(
project_id:
project
.
id
,
external_type:
'vulnerability-identifier'
,
external_id:
'vulnerability-identifier'
,
fingerprint:
'7e394d1b1eb461a7406d7b1e08f057a1cf11287a'
,
name:
'vulnerability identifier'
)
end
# vulnerability findings
let!
(
:findings
)
do
Array
.
new
(
2
)
do
|
id
|
vulnerability_findings
.
create!
(
project_id:
project
.
id
,
name:
'Vulnerability Name'
,
severity:
7
,
confidence:
7
,
report_type:
0
,
project_fingerprint:
'123qweasdzxc'
,
scanner_id:
scanner
.
id
,
primary_identifier_id:
vulnerability_identifier
.
id
,
location_fingerprint:
"location_fingerprint_
#{
id
}
"
,
metadata_version:
'metadata_version'
,
raw_metadata:
'raw_metadata'
,
uuid:
"uuid_
#{
id
}
"
)
end
end
# vulnerability finding links
let!
(
:links
)
do
{
findings
.
first
=>
Array
.
new
(
5
)
{
|
id
|
finding_links
.
create!
(
vulnerability_occurrence_id:
findings
.
first
.
id
,
name:
"Link Name 1"
,
url:
"link_url1_
#{
id
}
.example"
)
},
findings
.
second
=>
Array
.
new
(
5
)
{
|
id
|
finding_links
.
create!
(
vulnerability_occurrence_id:
findings
.
second
.
id
,
name:
"Link Name 2"
,
url:
"link_url2_
#{
id
}
.example"
)
}
}
end
it
'removes vulnerability links'
do
expect
do
subject
.
perform
(
links
[
findings
.
first
].
first
.
id
,
links
[
findings
.
second
].
last
.
id
)
end
.
to
change
{
finding_links
.
count
}.
from
(
10
).
to
(
0
)
expect
(
finding_links
.
all
).
to
be_empty
end
it
'only deletes vulnerability links for the current batch'
do
expected_links
=
[
finding_links
.
where
(
vulnerability_occurrence_id:
findings
.
second
.
id
)].
flatten
expect
do
subject
.
perform
(
links
[
findings
.
first
].
first
.
id
,
links
[
findings
.
first
].
last
.
id
)
end
.
to
change
{
finding_links
.
count
}.
from
(
10
).
to
(
5
)
expect
(
finding_links
.
all
).
to
match_array
(
expected_links
)
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