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
3e0173cc
Commit
3e0173cc
authored
Nov 23, 2021
by
Mehmet Emin INAC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not try to auto-complete vulnerabilities if the user is nil
Changelog: fixed EE: true
parent
a02124bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
32 deletions
+41
-32
ee/app/finders/autocomplete/vulnerabilities_autocomplete_finder.rb
...nders/autocomplete/vulnerabilities_autocomplete_finder.rb
+1
-1
ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb
.../autocomplete/vulnerabilities_autocomplete_finder_spec.rb
+40
-31
No files found.
ee/app/finders/autocomplete/vulnerabilities_autocomplete_finder.rb
View file @
3e0173cc
...
...
@@ -20,7 +20,7 @@ module Autocomplete
DEFAULT_AUTOCOMPLETE_LIMIT
=
5
def
execute
return
::
Vulnerability
.
none
unless
vulnerable
.
feature_available?
(
:security_dashboard
)
return
::
Vulnerability
.
none
unless
current_user
&&
vulnerable
.
feature_available?
(
:security_dashboard
)
::
Security
::
VulnerabilitiesFinder
# rubocop: disable CodeReuse/Finder
.
new
(
vulnerable
)
...
...
ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb
View file @
3e0173cc
...
...
@@ -7,64 +7,73 @@ RSpec.describe Autocomplete::VulnerabilitiesAutocompleteFinder do
let_it_be
(
:group
,
refind:
true
)
{
create
(
:group
)
}
let_it_be
(
:project
,
refind:
true
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:vulnerability
)
{
create
(
:vulnerability
,
project:
project
)
}
let
(
:params
)
{
{}
}
let
_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
{}
}
subject
{
described_class
.
new
(
user
,
vulnerable
,
params
).
execute
}
shared_examples
'autocomplete vulnerabilities finder'
do
context
'when user does not have access to project'
do
context
'when the given user is nil'
do
let
(
:user
)
{
nil
}
it
{
is_expected
.
to
be_empty
}
end
context
'when user has access to project'
do
before
do
vulnerable
.
add_developer
(
user
)
end
context
'when the given user is not nil'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
context
'when
security dashboards are not enabled
'
do
context
'when
user does not have access to project
'
do
it
{
is_expected
.
to
be_empty
}
end
context
'when
security dashboards are enabled
'
do
context
'when
user has access to project
'
do
before
do
stub_licensed_features
(
security_dashboard:
true
)
vulnerable
.
add_developer
(
user
)
end
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
context
'when security dashboards are not enabled'
do
it
{
is_expected
.
to
be_empty
}
end
context
'when
multiple vulnerabilities are foun
d'
do
context
'when
security dashboards are enable
d'
do
before
do
create_list
(
:vulnerability
,
10
,
project:
project
)
stub_licensed_features
(
security_dashboard:
true
)
end
it
'returns max 5 items'
do
expect
(
subject
.
count
).
to
eq
(
5
)
end
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
it
'is sorted descending by i
d'
do
expect
(
subject
).
to
be_sorted
(
:id
,
:desc
)
end
end
context
'when multiple vulnerabilities are foun
d'
do
before
do
create_list
(
:vulnerability
,
10
,
project:
project
)
end
context
'when search is provided in para
ms'
do
context
'and it matches ID of vulnerability'
do
let
(
:params
)
{
{
search:
vulnerability
.
id
.
to_s
}
}
it
'returns max 5 ite
ms'
do
expect
(
subject
.
count
).
to
eq
(
5
)
end
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
it
'is sorted descending by id'
do
expect
(
subject
).
to
be_sorted
(
:id
,
:desc
)
end
end
context
'and it matches title of vulnerability'
do
let
(
:params
)
{
{
search:
vulnerability
.
title
}
}
context
'when search is provided in params'
do
context
'and it matches ID of vulnerability'
do
let
(
:params
)
{
{
search:
vulnerability
.
id
.
to_s
}
}
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
end
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
end
context
'and it matches title of vulnerability'
do
let
(
:params
)
{
{
search:
vulnerability
.
title
}
}
it
{
is_expected
.
to
match_array
([
vulnerability
])
}
end
context
'and it does not match neither title or id of vulnerability'
do
let
(
:params
)
{
{
search:
non_existing_record_id
.
to_s
}
}
context
'and it does not match neither title or id of vulnerability'
do
let
(
:params
)
{
{
search:
non_existing_record_id
.
to_s
}
}
it
{
is_expected
.
to
be_empty
}
it
{
is_expected
.
to
be_empty
}
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