From 8c43a3758b35d5414186f17265b5910c764b9f0a Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:30:17 +0300 Subject: [PATCH] Fix sorting table results when no JAS scan (#164) --- utils/resultwriter_test.go | 12 ++++++------ utils/severityutils/severity.go | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/utils/resultwriter_test.go b/utils/resultwriter_test.go index 0c9a5a62..5f8652b0 100644 --- a/utils/resultwriter_test.go +++ b/utils/resultwriter_test.go @@ -242,7 +242,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { Summary: "summary-1", IssueId: "XRAY-1", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "High"}, + SeverityDetails: formats.SeverityDetails{Severity: "High", SeverityNumValue: 15}, ImpactedDependencyName: "component-A", }, }, @@ -250,7 +250,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { Summary: "summary-1", IssueId: "XRAY-1", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "High"}, + SeverityDetails: formats.SeverityDetails{Severity: "High", SeverityNumValue: 15}, ImpactedDependencyName: "component-B", }, }, @@ -258,7 +258,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { Summary: "summary-2", IssueId: "XRAY-2", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "Low"}, + SeverityDetails: formats.SeverityDetails{Severity: "Low", SeverityNumValue: 9}, ImpactedDependencyName: "component-B", }, }, @@ -288,7 +288,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { Summary: "summary-1", IssueId: "XRAY-1", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "High"}, + SeverityDetails: formats.SeverityDetails{Severity: "High", SeverityNumValue: 15}, ImpactedDependencyName: "component-A", }, }, @@ -296,7 +296,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { Summary: "summary-1", IssueId: "XRAY-1", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "High"}, + SeverityDetails: formats.SeverityDetails{Severity: "High", SeverityNumValue: 15}, ImpactedDependencyName: "component-B", }, }, @@ -305,7 +305,7 @@ func TestConvertXrayScanToSimpleJson(t *testing.T) { { LicenseKey: "license-1", ImpactedDependencyDetails: formats.ImpactedDependencyDetails{ - SeverityDetails: formats.SeverityDetails{Severity: "Low"}, + SeverityDetails: formats.SeverityDetails{Severity: "Low", SeverityNumValue: 9}, ImpactedDependencyName: "component-B", }, }, diff --git a/utils/severityutils/severity.go b/utils/severityutils/severity.go index 33e72f7e..436279ab 100644 --- a/utils/severityutils/severity.go +++ b/utils/severityutils/severity.go @@ -234,6 +234,10 @@ func ParseToSeverityDetails(severity string, sarifSeverity, pretty bool, applica // -- Getters functions (With default values) -- func GetAsDetails(severity Severity, applicabilityStatus jasutils.ApplicabilityStatus, pretty bool) formats.SeverityDetails { + if applicabilityStatus == jasutils.NotScanned { + // Pass 'NotCovered' as default value to get priority, since 'NotScanned' returns 0 priority for all severities + applicabilityStatus = jasutils.NotCovered + } return GetSeverityDetails(severity, applicabilityStatus).ToDetails(severity, pretty) }