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
08e047a5
Commit
08e047a5
authored
Oct 30, 2020
by
Mehmet Emin INAC
Committed by
James Lopez
Oct 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement fallback for Vulnerability#dismissed_at
parent
412ad465
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
7 deletions
+118
-7
ee/app/models/ee/vulnerability.rb
ee/app/models/ee/vulnerability.rb
+20
-1
ee/spec/models/ee/vulnerability_spec.rb
ee/spec/models/ee/vulnerability_spec.rb
+98
-6
No files found.
ee/app/models/ee/vulnerability.rb
View file @
08e047a5
...
...
@@ -2,6 +2,7 @@
module
EE
module
Vulnerability
include
::
Gitlab
::
Utils
::
StrongMemoize
extend
ActiveSupport
::
Concern
prepended
do
...
...
@@ -134,8 +135,17 @@ module EE
findings
.
first
end
# TODO: Remove this attribute reader overrides with #262112
def
dismissed_at
return
unless
dismissed?
super
||
fallback_dismissal_feedback
&
.
created_at
end
def
dismissed_by_id
super
||
finding
&
.
dismissal_feedback
&
.
author_id
return
unless
dismissed?
super
||
fallback_dismissal_feedback
&
.
author_id
end
def
resource_parent
...
...
@@ -165,6 +175,15 @@ module EE
def
user_notes_count_service
@user_notes_count_service
||=
::
Vulnerabilities
::
UserNotesCountService
.
new
(
self
)
# rubocop: disable CodeReuse/ServiceClass
end
# TODO: Remove this with #262112
def
fallback_dismissal_feedback
strong_memoize
(
:fallback_dismissal_feedback
)
do
::
Gitlab
::
AppJsonLogger
.
warn
(
message:
'Fallback dismissal_feedback has been called!'
,
vulnerability_id:
id
)
finding
&
.
dismissal_feedback
end
end
end
class_methods
do
...
...
ee/spec/models/ee/vulnerability_spec.rb
View file @
08e047a5
...
...
@@ -555,6 +555,74 @@ RSpec.describe Vulnerability do
end
end
describe
'#dismissed_at'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:finding
)
do
create
(
:vulnerabilities_finding
,
report_type: :dependency_scanning
,
project:
project
)
end
let
(
:vulnerability
)
{
create
(
:vulnerability
,
findings:
[
finding
])
}
let
(
:feedback_created_at
)
{
-
2
.
days
.
from_now
}
let!
(
:dismissal_feedback
)
do
create
(
:vulnerability_feedback
,
:dependency_scanning
,
:dismissal
,
project:
project
,
project_fingerprint:
finding
.
project_fingerprint
,
created_at:
feedback_created_at
)
end
subject
(
:dismissed_at
)
{
vulnerability
.
dismissed_at
}
around
do
|
example
|
freeze_time
{
example
.
run
}
end
context
'when the vulnerability is not dismissed'
do
before
do
vulnerability
.
update_attribute
(
:dismissed_at
,
Time
.
current
)
end
it
{
is_expected
.
to
be_nil
}
end
context
'when the vulnerability is dismissed'
do
before
do
vulnerability
.
dismissed!
end
context
'when the `dismissed_at` exists'
do
let
(
:vulnerability_dismissed_at
)
{
-
1
.
day
.
from_now
}
before
do
vulnerability
.
update_attribute
(
:dismissed_at
,
vulnerability_dismissed_at
)
end
it
{
is_expected
.
to
eq
(
vulnerability_dismissed_at
)
}
end
context
'when the `dismissed_at` does not exist'
do
before
do
allow
(
::
Gitlab
::
AppJsonLogger
).
to
receive
(
:warn
)
end
it
{
is_expected
.
to
eq
(
feedback_created_at
)
}
it
'puts a warning log'
do
dismissed_at
expect
(
::
Gitlab
::
AppJsonLogger
).
to
have_received
(
:warn
)
end
end
end
end
describe
'#dismissed_by_id'
do
let_it_be
(
:user_1
)
{
create
(
:user
)
}
let_it_be
(
:user_2
)
{
create
(
:user
)
}
...
...
@@ -579,18 +647,42 @@ RSpec.describe Vulnerability do
let
(
:vulnerability
)
{
create
(
:vulnerability
,
findings:
[
occurrence
])
}
subject
{
vulnerability
.
dismissed_by_id
}
subject
(
:dismissed_by_id
)
{
vulnerability
.
dismissed_by_id
}
context
'when the
`dismissed_by_id` exists
'
do
context
'when the
vulnerability is not dismissed
'
do
before
do
vulnerability
.
update_attribute
(
:dismissed_by_id
,
user_
2
.
id
)
vulnerability
.
update_attribute
(
:dismissed_by_id
,
user_
1
.
id
)
end
it
{
is_expected
.
to
eq
(
user_2
.
id
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when the `dismissed_by_id` does not exist'
do
it
{
is_expected
.
to
eq
(
user_1
.
id
)
}
context
'when the vulnerability is dismissed'
do
before
do
vulnerability
.
dismissed!
end
context
'when the `dismissed_by_id` exists'
do
before
do
vulnerability
.
update_attribute
(
:dismissed_by_id
,
user_2
.
id
)
end
it
{
is_expected
.
to
eq
(
user_2
.
id
)
}
end
context
'when the `dismissed_by_id` does not exist'
do
before
do
allow
(
::
Gitlab
::
AppJsonLogger
).
to
receive
(
:warn
)
end
it
{
is_expected
.
to
eq
(
user_1
.
id
)
}
it
'puts a warning log'
do
dismissed_by_id
expect
(
::
Gitlab
::
AppJsonLogger
).
to
have_received
(
:warn
)
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