Commit 6e5f5388 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch...

Merge branch '293843-expand-filtering-functionality-of-vulnerabilities-graphql-endpoint-to-support-vendor-graphql' into 'master'

GraphQL field for Scanner ID

See merge request gitlab-org/gitlab!56041
parents d059cc34 39044dd4
...@@ -376,6 +376,7 @@ Returns [`VulnerabilityConnection`](#vulnerabilityconnection). ...@@ -376,6 +376,7 @@ Returns [`VulnerabilityConnection`](#vulnerabilityconnection).
| `projectId` | [`[ID!]`](#id) | Filter vulnerabilities by project. | | `projectId` | [`[ID!]`](#id) | Filter vulnerabilities by project. |
| `reportType` | [`[VulnerabilityReportType!]`](#vulnerabilityreporttype) | Filter vulnerabilities by report type. | | `reportType` | [`[VulnerabilityReportType!]`](#vulnerabilityreporttype) | Filter vulnerabilities by report type. |
| `scanner` | [`[String!]`](#string) | Filter vulnerabilities by VulnerabilityScanner.externalId. | | `scanner` | [`[String!]`](#string) | Filter vulnerabilities by VulnerabilityScanner.externalId. |
| `scannerId` | [`[Int!]`](#int) | Filter vulnerabilities by scanner ID. |
| `severity` | [`[VulnerabilitySeverity!]`](#vulnerabilityseverity) | Filter vulnerabilities by severity. | | `severity` | [`[VulnerabilitySeverity!]`](#vulnerabilityseverity) | Filter vulnerabilities by severity. |
| `sort` | [`VulnerabilitySort`](#vulnerabilitysort) | List vulnerabilities by sort order. | | `sort` | [`VulnerabilitySort`](#vulnerabilitysort) | List vulnerabilities by sort order. |
| `state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerabilities by state. | | `state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerabilities by state. |
......
...@@ -8,6 +8,7 @@ query instance( ...@@ -8,6 +8,7 @@ query instance(
$severity: [VulnerabilitySeverity!] $severity: [VulnerabilitySeverity!]
$reportType: [VulnerabilityReportType!] $reportType: [VulnerabilityReportType!]
$scanner: [String!] $scanner: [String!]
$scannerId: [Int!]
$state: [VulnerabilityState!] $state: [VulnerabilityState!]
$sort: VulnerabilitySort $sort: VulnerabilitySort
$hasIssues: Boolean $hasIssues: Boolean
...@@ -21,6 +22,7 @@ query instance( ...@@ -21,6 +22,7 @@ query instance(
state: $state state: $state
projectId: $projectId projectId: $projectId
scanner: $scanner scanner: $scanner
scannerId: $scannerId
sort: $sort sort: $sort
hasIssues: $hasIssues hasIssues: $hasIssues
hasResolution: $hasResolution hasResolution: $hasResolution
......
...@@ -67,8 +67,8 @@ module Security ...@@ -67,8 +67,8 @@ module Security
end end
def filter_by_scanner_ids def filter_by_scanner_ids
if params[:scanner_ids].present? if params[:scanner_id].present?
@vulnerabilities = vulnerabilities.by_scanner_ids(params[:scanner_ids]) @vulnerabilities = vulnerabilities.by_scanner_ids(params[:scanner_id])
end end
end end
......
...@@ -26,6 +26,10 @@ module Resolvers ...@@ -26,6 +26,10 @@ module Resolvers
required: false, required: false,
description: 'Filter vulnerabilities by VulnerabilityScanner.externalId.' description: 'Filter vulnerabilities by VulnerabilityScanner.externalId.'
argument :scanner_id, [GraphQL::INT_TYPE],
required: false,
description: 'Filter vulnerabilities by scanner ID.'
argument :sort, Types::VulnerabilitySortEnum, argument :sort, Types::VulnerabilitySortEnum,
required: false, required: false,
default_value: 'severity_desc', default_value: 'severity_desc',
......
---
title: Add GraphQL field for vulnerability scanner ID
merge_request: 56041
author:
type: changed
...@@ -67,7 +67,7 @@ RSpec.describe Security::VulnerabilitiesFinder do ...@@ -67,7 +67,7 @@ RSpec.describe Security::VulnerabilitiesFinder do
end end
context 'when filtered by scanner_id' do context 'when filtered by scanner_id' do
let(:filters) { { scanner_ids: [vulnerability1.finding_scanner_id, vulnerability3.finding_scanner_id] } } let(:filters) { { scanner_id: [vulnerability1.finding_scanner_id, vulnerability3.finding_scanner_id] } }
it 'only returns vulnerabilities matching the given scanner IDs' do it 'only returns vulnerabilities matching the given scanner IDs' do
is_expected.to contain_exactly(vulnerability1, vulnerability3) is_expected.to contain_exactly(vulnerability1, vulnerability3)
......
...@@ -69,10 +69,18 @@ RSpec.describe Resolvers::VulnerabilitiesResolver do ...@@ -69,10 +69,18 @@ RSpec.describe Resolvers::VulnerabilitiesResolver do
end end
end end
context 'when given scanner' do context 'when given scanner external IDs' do
let(:params) { { scanner: [high_vulnerability.finding_scanner_external_id] } } let(:params) { { scanner: [high_vulnerability.finding_scanner_external_id] } }
it 'only returns vulnerabilities of the given scanner' do it 'only returns vulnerabilities of the given scanner external IDs' do
is_expected.to contain_exactly(high_vulnerability)
end
end
context 'when given scanner ID' do
let(:params) { { scanner_id: [high_vulnerability.finding_scanner_id] } }
it 'only returns vulnerabilities of the given scanner IDs' do
is_expected.to contain_exactly(high_vulnerability) is_expected.to contain_exactly(high_vulnerability)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment