Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vulnerabilities): set, maintain and expose vulnerabilitySeverity…
… for templated fields (#21939)
- Loading branch information
Showing
9 changed files
with
264 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { getHighestVulnerabilitySeverity } from './utils'; | ||
|
||
describe('util/vulnerability/utils', () => { | ||
it('parent CRITICAL vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'CRITICAL', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('CRITICAL'); | ||
}); | ||
|
||
it('child CRITICAL vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'CRITICAL', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('CRITICAL'); | ||
}); | ||
|
||
it('parent HIGH vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'HIGH', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('HIGH'); | ||
}); | ||
|
||
it('child HIGH vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'HIGH', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('HIGH'); | ||
}); | ||
|
||
it('parent MODERATE vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'LOW', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('MODERATE'); | ||
}); | ||
|
||
it('child MODERATE vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'LOW', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'MODERATE', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('MODERATE'); | ||
}); | ||
|
||
it('parent LOW vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: 'LOW', | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: undefined, | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('LOW'); | ||
}); | ||
|
||
it('child LOW vulnerability severity rating is maintained', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: undefined, | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: 'LOW', | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBe('LOW'); | ||
}); | ||
|
||
it('handled undefined parent and child vulnerability severity', () => { | ||
const parentConfig = { | ||
vulnerabilitySeverity: undefined, | ||
}; | ||
|
||
const childConfig = { | ||
vulnerabilitySeverity: undefined, | ||
}; | ||
|
||
const severity = getHighestVulnerabilitySeverity(parentConfig, childConfig); | ||
|
||
expect(severity).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const severityOrder: Record<string, number> = { | ||
LOW: 1, | ||
MODERATE: 2, | ||
HIGH: 3, | ||
CRITICAL: 4, | ||
}; | ||
|
||
export function getHighestVulnerabilitySeverity< | ||
T extends Record<string, any>, | ||
TChild extends Record<string, any> | undefined | ||
>(parent: T, child: TChild): string { | ||
const parentVulSeverity = parent.vulnerabilitySeverity?.toUpperCase(); | ||
const childVulSeverity = child?.vulnerabilitySeverity?.toUpperCase(); | ||
|
||
if (childVulSeverity === undefined) { | ||
return parentVulSeverity; | ||
} | ||
|
||
if (parentVulSeverity === undefined) { | ||
return childVulSeverity; | ||
} | ||
|
||
return severityOrder[parentVulSeverity] >= severityOrder[childVulSeverity] | ||
? parentVulSeverity | ||
: childVulSeverity; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.