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
e580999f
Commit
e580999f
authored
Dec 17, 2021
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip updating vulnerability statistics if there are no new records
Changelog: fixed EE: true
parent
ba14ce92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
11 deletions
+38
-11
ee/app/services/security/ingestion/tasks/ingest_vulnerability_statistics.rb
...curity/ingestion/tasks/ingest_vulnerability_statistics.rb
+2
-0
ee/spec/services/security/ingestion/tasks/ingest_vulnerability_statistics_spec.rb
...y/ingestion/tasks/ingest_vulnerability_statistics_spec.rb
+36
-11
No files found.
ee/app/services/security/ingestion/tasks/ingest_vulnerability_statistics.rb
View file @
e580999f
...
...
@@ -24,6 +24,8 @@ module Security
SQL
def
execute
return
unless
severity_counts
.
present?
connection
.
execute
(
upsert_sql
)
end
...
...
ee/spec/services/security/ingestion/tasks/ingest_vulnerability_statistics_spec.rb
View file @
e580999f
...
...
@@ -12,30 +12,55 @@ RSpec.describe Security::Ingestion::Tasks::IngestVulnerabilityStatistics do
let_it_be
(
:finding_map_1
)
{
create
(
:finding_map
,
:new_record
,
security_finding:
security_finding_1
)
}
let_it_be
(
:finding_map_2
)
{
create
(
:finding_map
,
:new_record
,
security_finding:
security_finding_2
)
}
let_it_be
(
:finding_map_3
)
{
create
(
:finding_map
,
:with_finding
,
security_finding:
security_finding_3
)
}
let_it_be
(
:finding_maps
)
{
[
finding_map_1
,
finding_map_2
,
finding_map_3
]
}
subject
(
:ingest_statistics
)
{
described_class
.
new
(
pipeline
,
finding_maps
).
execute
}
context
'when there is no statistics record for the project'
do
it
'creates a new Vulnerabilities::Statistic record'
do
expect
{
ingest_statistics
}.
to
change
{
Vulnerabilities
::
Statistic
.
where
(
project:
project
).
count
}.
by
(
1
)
context
'when there are no new vulnerabilities'
do
let
(
:finding_maps
)
{
[
finding_map_3
]
}
it
'does not create a new Vulnerabilities::Statistic record'
do
expect
{
ingest_statistics
}.
not_to
change
{
Vulnerabilities
::
Statistic
.
where
(
project:
project
).
count
}
end
end
it
'sets the correct attributes for the recently created record'
do
ingest_statistics
context
'when there are new vulnerabilities'
do
let
(
:finding_maps
)
{
[
finding_map_1
,
finding_map_2
,
finding_map_3
]
}
it
'creates a new Vulnerabilities::Statistic record'
do
expect
{
ingest_statistics
}.
to
change
{
Vulnerabilities
::
Statistic
.
where
(
project:
project
).
count
}.
by
(
1
)
end
expect
(
project
.
vulnerability_statistic
).
to
have_attributes
(
critical:
1
,
high:
0
,
unknown:
0
,
medium:
1
,
low:
0
,
letter_grade:
'f'
)
it
'sets the correct attributes for the recently created record'
do
ingest_statistics
expect
(
project
.
vulnerability_statistic
).
to
have_attributes
(
critical:
1
,
high:
0
,
unknown:
0
,
medium:
1
,
low:
0
,
letter_grade:
'f'
)
end
end
end
context
'when there is already a statistics record for the project'
do
let_it_be
(
:vulnerability_statistic
)
{
create
(
:vulnerability_statistic
,
:grade_c
,
project:
project
)
}
it
'does not create a new record and updates the existing one'
do
expect
{
ingest_statistics
}.
to
change
{
vulnerability_statistic
.
reload
.
letter_grade
}.
from
(
'c'
).
to
(
'f'
)
.
and
change
{
vulnerability_statistic
.
reload
.
critical
}.
from
(
0
).
to
(
1
)
.
and
change
{
vulnerability_statistic
.
reload
.
medium
}.
from
(
1
).
to
(
2
)
.
and
not_change
{
Vulnerabilities
::
Statistic
.
count
}
context
'when there are no new vulnerabilities'
do
let
(
:finding_maps
)
{
[
finding_map_3
]
}
it
'does not create a new record and does not change the existing record'
do
expect
{
ingest_statistics
}.
to
not_change
{
vulnerability_statistic
.
reload
.
letter_grade
}
.
and
not_change
{
vulnerability_statistic
.
reload
.
low
}
.
and
not_change
{
Vulnerabilities
::
Statistic
.
count
}
end
end
context
'when there are new vulnerabilities'
do
let
(
:finding_maps
)
{
[
finding_map_1
,
finding_map_2
,
finding_map_3
]
}
it
'does not create a new record and updates the existing one'
do
expect
{
ingest_statistics
}.
to
change
{
vulnerability_statistic
.
reload
.
letter_grade
}.
from
(
'c'
).
to
(
'f'
)
.
and
change
{
vulnerability_statistic
.
reload
.
critical
}.
from
(
0
).
to
(
1
)
.
and
change
{
vulnerability_statistic
.
reload
.
medium
}.
from
(
1
).
to
(
2
)
.
and
not_change
{
Vulnerabilities
::
Statistic
.
count
}
end
end
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