Commit 069c6420 authored by James Lopez's avatar James Lopez

Merge branch 'sort-vulnerabilities-for-pipeline-dashboard' into 'master'

Sort vulnerabilities for pipeline dashboard

See merge request gitlab-org/gitlab!18863
parents 51c5859c a930de78
---
title: Pipeline vulnerability dashboard sort vulnerabilities by severity then confidence
merge_request: 18863
author:
type: fixed
...@@ -41,7 +41,7 @@ module Security ...@@ -41,7 +41,7 @@ module Security
occurrences.concat(filtered_occurrences) occurrences.concat(filtered_occurrences)
end end
occurrences.sort_by { |x| [x.severity, x.confidence] } occurrences.sort_by { |x| [-x.severity_value, -x.confidence_value] }
end end
private private
......
...@@ -221,6 +221,14 @@ module Vulnerabilities ...@@ -221,6 +221,14 @@ module Vulnerabilities
report_type.hash ^ location.hash ^ first_fingerprint.hash report_type.hash ^ location.hash ^ first_fingerprint.hash
end end
def severity_value
self.class.severities[self.severity]
end
def confidence_value
self.class.confidences[self.confidence]
end
protected protected
def first_fingerprint def first_fingerprint
......
...@@ -54,15 +54,24 @@ describe Security::PipelineVulnerabilitiesFinder do ...@@ -54,15 +54,24 @@ describe Security::PipelineVulnerabilitiesFinder do
context 'by order' do context 'by order' do
let(:params) { { report_type: %w[sast] } } let(:params) { { report_type: %w[sast] } }
let!(:occurrence1) { build(:vulnerabilities_occurrence, confidence: Vulnerabilities::Occurrence::CONFIDENCE_LEVELS[:high], severity: Vulnerabilities::Occurrence::SEVERITY_LEVELS[:high]) } let!(:high_high) { build(:vulnerabilities_occurrence, confidence: :high, severity: :high) }
let!(:occurrence2) { build(:vulnerabilities_occurrence, confidence: Vulnerabilities::Occurrence::CONFIDENCE_LEVELS[:medium], severity: Vulnerabilities::Occurrence::SEVERITY_LEVELS[:critical]) } let!(:critical_medium) { build(:vulnerabilities_occurrence, confidence: :medium, severity: :critical) }
let!(:occurrence3) { build(:vulnerabilities_occurrence, confidence: Vulnerabilities::Occurrence::CONFIDENCE_LEVELS[:high], severity: Vulnerabilities::Occurrence::SEVERITY_LEVELS[:critical]) } let!(:critical_high) { build(:vulnerabilities_occurrence, confidence: :high, severity: :critical) }
let!(:res) { [occurrence3, occurrence2, occurrence1] } let!(:unknown_high) { build(:vulnerabilities_occurrence, confidence: :high, severity: :unknown) }
let!(:unknown_medium) { build(:vulnerabilities_occurrence, confidence: :medium, severity: :unknown) }
let!(:unknown_low) { build(:vulnerabilities_occurrence, confidence: :low, severity: :unknown) }
it 'orders by severity and confidence' do it 'orders by severity and confidence' do
allow_any_instance_of(described_class).to receive(:filter).and_return(res) allow_any_instance_of(described_class).to receive(:filter).and_return([
unknown_low,
expect(subject).to eq([occurrence3, occurrence2, occurrence1]) unknown_medium,
critical_high,
unknown_high,
critical_medium,
high_high
])
expect(subject).to eq([critical_high, critical_medium, high_high, unknown_high, unknown_medium, unknown_low])
end end
end end
......
...@@ -127,7 +127,7 @@ shared_examples 'getting list of vulnerability findings' do ...@@ -127,7 +127,7 @@ shared_examples 'getting list of vulnerability findings' do
# occurrences are implicitly sorted by Security::MergeReportsService, # occurrences are implicitly sorted by Security::MergeReportsService,
# occurrences order differs from what is present in fixture file # occurrences order differs from what is present in fixture file
expect(json_response.first['name']).to eq 'Consider possible security implications associated with Popen module.' expect(json_response.first['name']).to eq 'ECB mode is insecure'
end end
it 'returns vulnerabilities with dependency_scanning report_type' do it 'returns vulnerabilities with dependency_scanning report_type' do
......
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