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
b5336ba1
Commit
b5336ba1
authored
Jun 04, 2021
by
Jonathan Schafer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add vulnerability scanner ID filter in GraphQL
Filter added for scannerId Changelog: changed EE: true
parent
a9a7f192
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
7 deletions
+48
-7
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+3
-0
ee/app/assets/javascripts/security_dashboard/graphql/queries/vulnerability_severities_count.query.graphql
...phql/queries/vulnerability_severities_count.query.graphql
+4
-0
ee/app/graphql/resolvers/vulnerabilities_base_resolver.rb
ee/app/graphql/resolvers/vulnerabilities_base_resolver.rb
+6
-0
ee/app/graphql/resolvers/vulnerabilities_resolver.rb
ee/app/graphql/resolvers/vulnerabilities_resolver.rb
+0
-6
ee/app/graphql/resolvers/vulnerability_severities_count_resolver.rb
...phql/resolvers/vulnerability_severities_count_resolver.rb
+6
-0
ee/spec/graphql/resolvers/vulnerability_severities_count_resolver_spec.rb
...resolvers/vulnerability_severities_count_resolver_spec.rb
+8
-0
ee/spec/requests/api/graphql/project/vulnerability_severities_count_spec.rb
...pi/graphql/project/vulnerability_severities_count_spec.rb
+21
-1
No files found.
doc/api/graphql/reference/index.md
View file @
b5336ba1
...
...
@@ -9483,6 +9483,7 @@ Returns [`VulnerabilitySeveritiesCount`](#vulnerabilityseveritiescount).
|
<a
id=
"groupvulnerabilityseveritiescountprojectid"
></a>
`projectId`
|
[
`[ID!]`
](
#id
)
| Filter vulnerabilities by project. |
|
<a
id=
"groupvulnerabilityseveritiescountreporttype"
></a>
`reportType`
|
[
`[VulnerabilityReportType!]`
](
#vulnerabilityreporttype
)
| Filter vulnerabilities by report type. |
|
<a
id=
"groupvulnerabilityseveritiescountscanner"
></a>
`scanner`
|
[
`[String!]`
](
#string
)
| Filter vulnerabilities by scanner. |
|
<a
id=
"groupvulnerabilityseveritiescountscannerid"
></a>
`scannerId`
|
[
`[VulnerabilitiesScannerID!]`
](
#vulnerabilitiesscannerid
)
| Filter vulnerabilities by scanner ID. |
|
<a
id=
"groupvulnerabilityseveritiescountseverity"
></a>
`severity`
|
[
`[VulnerabilitySeverity!]`
](
#vulnerabilityseverity
)
| Filter vulnerabilities by severity. |
|
<a
id=
"groupvulnerabilityseveritiescountstate"
></a>
`state`
|
[
`[VulnerabilityState!]`
](
#vulnerabilitystate
)
| Filter vulnerabilities by state. |
...
...
@@ -9651,6 +9652,7 @@ Returns [`VulnerabilitySeveritiesCount`](#vulnerabilityseveritiescount).
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountprojectid"
></a>
`projectId`
|
[
`[ID!]`
](
#id
)
| Filter vulnerabilities by project. |
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountreporttype"
></a>
`reportType`
|
[
`[VulnerabilityReportType!]`
](
#vulnerabilityreporttype
)
| Filter vulnerabilities by report type. |
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountscanner"
></a>
`scanner`
|
[
`[String!]`
](
#string
)
| Filter vulnerabilities by scanner. |
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountscannerid"
></a>
`scannerId`
|
[
`[VulnerabilitiesScannerID!]`
](
#vulnerabilitiesscannerid
)
| Filter vulnerabilities by scanner ID. |
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountseverity"
></a>
`severity`
|
[
`[VulnerabilitySeverity!]`
](
#vulnerabilityseverity
)
| Filter vulnerabilities by severity. |
|
<a
id=
"instancesecuritydashboardvulnerabilityseveritiescountstate"
></a>
`state`
|
[
`[VulnerabilityState!]`
](
#vulnerabilitystate
)
| Filter vulnerabilities by state. |
...
...
@@ -11887,6 +11889,7 @@ Returns [`VulnerabilitySeveritiesCount`](#vulnerabilityseveritiescount).
|
<a
id=
"projectvulnerabilityseveritiescountprojectid"
></a>
`projectId`
|
[
`[ID!]`
](
#id
)
| Filter vulnerabilities by project. |
|
<a
id=
"projectvulnerabilityseveritiescountreporttype"
></a>
`reportType`
|
[
`[VulnerabilityReportType!]`
](
#vulnerabilityreporttype
)
| Filter vulnerabilities by report type. |
|
<a
id=
"projectvulnerabilityseveritiescountscanner"
></a>
`scanner`
|
[
`[String!]`
](
#string
)
| Filter vulnerabilities by scanner. |
|
<a
id=
"projectvulnerabilityseveritiescountscannerid"
></a>
`scannerId`
|
[
`[VulnerabilitiesScannerID!]`
](
#vulnerabilitiesscannerid
)
| Filter vulnerabilities by scanner ID. |
|
<a
id=
"projectvulnerabilityseveritiescountseverity"
></a>
`severity`
|
[
`[VulnerabilitySeverity!]`
](
#vulnerabilityseverity
)
| Filter vulnerabilities by severity. |
|
<a
id=
"projectvulnerabilityseveritiescountstate"
></a>
`state`
|
[
`[VulnerabilityState!]`
](
#vulnerabilitystate
)
| Filter vulnerabilities by state. |
...
...
ee/app/assets/javascripts/security_dashboard/graphql/queries/vulnerability_severities_count.query.graphql
View file @
b5336ba1
...
...
@@ -7,6 +7,7 @@ query vulnerabilitySeveritiesCount(
$reportType
:
[
VulnerabilityReportType
!]
$scanner
:
[
String
!]
$state
:
[
VulnerabilityState
!]
$scannerId
:
[
VulnerabilitiesScannerID
!]
$isGroup
:
Boolean
=
false
$isProject
:
Boolean
=
false
$isInstance
:
Boolean
=
false
...
...
@@ -18,6 +19,7 @@ query vulnerabilitySeveritiesCount(
reportType
:
$reportType
scanner
:
$scanner
state
:
$state
scannerId
:
$scannerId
)
{
...
VulnerabilitySeveritiesCount
}
...
...
@@ -29,6 +31,7 @@ query vulnerabilitySeveritiesCount(
reportType
:
$reportType
scanner
:
$scanner
state
:
$state
scannerId
:
$scannerId
)
{
...
VulnerabilitySeveritiesCount
}
...
...
@@ -39,6 +42,7 @@ query vulnerabilitySeveritiesCount(
reportType
:
$reportType
scanner
:
$scanner
state
:
$state
scannerId
:
$scannerId
)
{
...
VulnerabilitySeveritiesCount
}
...
...
ee/app/graphql/resolvers/vulnerabilities_base_resolver.rb
View file @
b5336ba1
...
...
@@ -35,5 +35,11 @@ module Resolvers
# dashboard
object
.
nil?
&&
current_user
.
present?
end
def
resolve_gids
(
gids
,
gid_class
)
gids
.
map
do
|
gid
|
Types
::
GlobalIDType
[
gid_class
].
coerce_isolated_input
(
gid
).
model_id
end
end
end
end
ee/app/graphql/resolvers/vulnerabilities_resolver.rb
View file @
b5336ba1
...
...
@@ -55,12 +55,6 @@ module Resolvers
private
def
resolve_gids
(
gids
,
gid_class
)
gids
.
map
do
|
gid
|
Types
::
GlobalIDType
[
gid_class
].
coerce_isolated_input
(
gid
).
model_id
end
end
def
vulnerabilities
(
params
)
Security
::
VulnerabilitiesFinder
.
new
(
vulnerable
,
params
).
execute
end
...
...
ee/app/graphql/resolvers/vulnerability_severities_count_resolver.rb
View file @
b5336ba1
...
...
@@ -29,9 +29,15 @@ module Resolvers
required:
false
,
description:
'Filter vulnerabilities by scanner.'
argument
:scanner_id
,
[
::
Types
::
GlobalIDType
[
::
Vulnerabilities
::
Scanner
]],
required:
false
,
description:
'Filter vulnerabilities by scanner ID.'
def
resolve
(
**
args
)
return
Vulnerability
.
none
unless
vulnerable
args
[
:scanner_id
]
=
resolve_gids
(
args
[
:scanner_id
],
::
Vulnerabilities
::
Scanner
)
if
args
[
:scanner_id
]
Hash
.
new
(
0
)
.
merge
(
vulnerabilities
(
args
).
grouped_by_severity
.
count
)
end
...
...
ee/spec/graphql/resolvers/vulnerability_severities_count_resolver_spec.rb
View file @
b5336ba1
...
...
@@ -63,6 +63,14 @@ RSpec.describe Resolvers::VulnerabilitySeveritiesCountResolver do
end
end
context
'when given scanner ID'
do
let
(
:filters
)
{
{
scanner_id:
[
GitlabSchema
.
id_from_object
(
high_vulnerability
.
finding
.
scanner
)]
}
}
it
'only returns count for vulnerabilities with scanner ID'
do
is_expected
.
to
eq
(
'high'
=>
1
)
end
end
context
'when given report types'
do
let
(
:filters
)
{
{
report_type:
%i[dast sast]
}
}
...
...
ee/spec/requests/api/graphql/project/vulnerability_severities_count_spec.rb
View file @
b5336ba1
...
...
@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec
.
describe
'Query.project(fullPath).vulnerabilitySeveritiesCount'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:vulnerability
)
{
create
(
:vulnerability
,
:high
,
project:
project
)
}
let_it_be
(
:vulnerability
)
{
create
(
:vulnerability
,
:high
,
:with_finding
,
project:
project
)
}
let_it_be
(
:query
)
do
%(
...
...
@@ -32,4 +32,24 @@ RSpec.describe 'Query.project(fullPath).vulnerabilitySeveritiesCount' do
expect
(
high_count
).
to
eq
(
1
)
end
context
'with scannerId filter'
do
let
(
:query
)
do
%(
query {
project(fullPath: "#{project.full_path}") {
vulnerabilitySeveritiesCount(scannerId: "#{GitlabSchema.id_from_object(vulnerability.finding.scanner)}") {
high
}
}
}
)
end
it
'counts vulnerabilities with issues'
do
high_count
=
subject
.
dig
(
'data'
,
'project'
,
'vulnerabilitySeveritiesCount'
,
'high'
)
expect
(
high_count
).
to
eq
(
1
)
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