Commit 39044dd4 authored by Jonathan Schafer's avatar Jonathan Schafer Committed by Igor Drozdov

GraphQL field for vulnerability scanner ID

Update documentation as well
parent 05ef4806
......@@ -375,6 +375,7 @@ Returns [`VulnerabilityConnection`](#vulnerabilityconnection).
| `projectId` | [`[ID!]`](#id) | Filter vulnerabilities by project. |
| `reportType` | [`[VulnerabilityReportType!]`](#vulnerabilityreporttype) | Filter vulnerabilities by report type. |
| `scanner` | [`[String!]`](#string) | Filter vulnerabilities by VulnerabilityScanner.externalId. |
| `scannerId` | [`[Int!]`](#int) | Filter vulnerabilities by scanner ID. |
| `severity` | [`[VulnerabilitySeverity!]`](#vulnerabilityseverity) | Filter vulnerabilities by severity. |
| `sort` | [`VulnerabilitySort`](#vulnerabilitysort) | List vulnerabilities by sort order. |
| `state` | [`[VulnerabilityState!]`](#vulnerabilitystate) | Filter vulnerabilities by state. |
......
......@@ -8,6 +8,7 @@ query instance(
$severity: [VulnerabilitySeverity!]
$reportType: [VulnerabilityReportType!]
$scanner: [String!]
$scannerId: [Int!]
$state: [VulnerabilityState!]
$sort: VulnerabilitySort
$hasIssues: Boolean
......@@ -21,6 +22,7 @@ query instance(
state: $state
projectId: $projectId
scanner: $scanner
scannerId: $scannerId
sort: $sort
hasIssues: $hasIssues
hasResolution: $hasResolution
......
......@@ -67,8 +67,8 @@ module Security
end
def filter_by_scanner_ids
if params[:scanner_ids].present?
@vulnerabilities = vulnerabilities.by_scanner_ids(params[:scanner_ids])
if params[:scanner_id].present?
@vulnerabilities = vulnerabilities.by_scanner_ids(params[:scanner_id])
end
end
......
......@@ -26,6 +26,10 @@ module Resolvers
required: false,
description: 'Filter vulnerabilities by VulnerabilityScanner.externalId.'
argument :scanner_id, [GraphQL::INT_TYPE],
required: false,
description: 'Filter vulnerabilities by scanner ID.'
argument :sort, Types::VulnerabilitySortEnum,
required: false,
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
end
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
is_expected.to contain_exactly(vulnerability1, vulnerability3)
......
......@@ -69,10 +69,18 @@ RSpec.describe Resolvers::VulnerabilitiesResolver do
end
end
context 'when given scanner' do
context 'when given scanner external IDs' do
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)
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