Skip to content

Commit

Permalink
fix(pipelines): Handle invalid response on acs image scan tab gracefu…
Browse files Browse the repository at this point in the history
…lly (#26)
  • Loading branch information
karthikjeeyar authored Apr 9, 2024
1 parent 28bfcb4 commit 6718cd3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-bugs-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aonic-ui/pipelines": patch
---

Handle the invalid data for acs image scan tab
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const ImageScanSummary: React.FC = () => {
const { acsImageScanResult } = useACSContext();

const getResultsSummary = (data: ACSImageScanResult) => ({
Critical: data.result.summary.CRITICAL,
Important: data.result.summary.IMPORTANT,
Moderate: data.result.summary.MODERATE,
Low: data.result.summary.LOW,
Critical: data.result?.summary?.CRITICAL ?? 0,
Important: data.result?.summary?.IMPORTANT ?? 0,
Moderate: data.result?.summary?.MODERATE ?? 0,
Low: data.result?.summary?.LOW ?? 0,
});

const resultSummary = React.useMemo(
Expand Down Expand Up @@ -96,7 +96,7 @@ const ImageScanSummary: React.FC = () => {
<SummaryTextAndCount
text={getCVEScanResults(
ACS_SCAN_RESULTS.Vulnerabilites,
acsImageScanResult.result.summary,
acsImageScanResult.result?.summary,
)}
/>
</FlexItem>
Expand All @@ -105,7 +105,7 @@ const ImageScanSummary: React.FC = () => {
<SummaryTextAndCount
text={getCVEScanResults(
ACS_SCAN_RESULTS.Components,
acsImageScanResult.result.summary,
acsImageScanResult.result?.summary,
)}
/>
</FlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ describe('ACS filter utils', () => {
});

describe('filterVulnerabilities', () => {
test('should return empty array for invalid data', () => {
const invalidACSImageScanData = {
result: {
summary: acsImageScanResult.result.summary,
},
} as ACSImageScanResult;

expect(
filterVulnerabilities(invalidACSImageScanData, {
statusFilters: [ACS_STATUS.Fixable],
}),
).toHaveLength(0);

expect(
filterVulnerabilities({} as ACSImageScanResult, {
statusFilters: [ACS_STATUS.Fixable],
}),
).toHaveLength(0);
});
test('should filter vulnerabilities by status', () => {
expect(
filterVulnerabilities(acsImageScanResult, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const filterVulnerabilities = (
componentFilters = [],
severityFilters = [],
} = filters;
return !isEmpty(acsImageScanResult)
? acsImageScanResult?.result?.vulnerabilities?.filter(
return !isEmpty(acsImageScanResult) && !!acsImageScanResult?.result?.vulnerabilities
? acsImageScanResult.result.vulnerabilities?.filter(
(vul: Vulnerability) =>
filterByStatus(vul, statusFilters) &&
filterData(vul, cveIdFilters, 'cveId') &&
Expand Down

0 comments on commit 6718cd3

Please sign in to comment.