-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(vulnerabilities): set, maintain and expose vulnerabilitySeverity for templated fields #21939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6e1a216
feat: optional flag to include severity in commitMessageSuffix
setchy 70bdb9d
fix: update snapshot
setchy 6424cc1
Update configuration-options.md
setchy c34ebaa
fix: lint issues
setchy dabd57c
refactor: make vulnerabilitySeverity a type
setchy 39ba098
refactor: calculate and pass the maximum severity within package rule…
setchy 767e6cb
tests: update snapshot
setchy 375a2d1
Merge branch 'main' into feature/osv-severity
setchy f544ee8
remove unused config option
setchy a006bb4
tests: add test cases for calculating highest severity
setchy 0c56e73
refactor: extract severity calculation logic
setchy 80366c9
refactor: extract severity calculation logic
setchy 1b0ef96
refactor: extract severity calculation logic
setchy 7628b00
refactor: more finesse, less crowbar
setchy 5f2e565
Merge branch 'main' into feature/osv-severity
setchy c745a7b
remove empty line
setchy d63b65d
tests: remove beforeEach
setchy 27026ad
refactor: use object
setchy 3b6bc84
tests: remove dynamic import
setchy ce104e5
refactor: update types to match lib/config/utils.ts
setchy 8f09aa4
refactor: incorporate feedback from @JamieMagee
setchy c34d3f2
docs: update wording
setchy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,126 @@ | ||
| import { setHighestVulnerabilitySeverity } from './utils'; | ||
|
|
||
| let config: Record<string, any>; | ||
| let parentConfig: Record<string, any>; | ||
| let childConfig: Record<string, any>; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| config = { | ||
| vulnerabilitySeverity: undefined, | ||
| }; | ||
| }); | ||
|
|
||
|
setchy marked this conversation as resolved.
Outdated
|
||
| describe('util/vulnerability/utils', () => { | ||
| it('parent CRITICAL vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'CRITICAL', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('CRITICAL'); | ||
| }); | ||
|
|
||
| it('child CRITICAL vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'CRITICAL', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('CRITICAL'); | ||
| }); | ||
|
|
||
| it('parent HIGH vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'HIGH', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('HIGH'); | ||
| }); | ||
|
|
||
| it('child HIGH vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'HIGH', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('HIGH'); | ||
| }); | ||
|
|
||
| it('parent MODERATE vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'LOW', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('MODERATE'); | ||
| }); | ||
|
|
||
| it('child MODERATE vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'LOW', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'MODERATE', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('MODERATE'); | ||
| }); | ||
|
|
||
| it('parent LOW vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: 'LOW', | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: undefined, | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('LOW'); | ||
| }); | ||
|
|
||
| it('child LOW vulnerability severity rating is maintained', () => { | ||
| parentConfig = { | ||
| vulnerabilitySeverity: undefined, | ||
| }; | ||
|
|
||
| childConfig = { | ||
| vulnerabilitySeverity: 'LOW', | ||
| }; | ||
|
|
||
| setHighestVulnerabilitySeverity(config, parentConfig, childConfig); | ||
|
|
||
| expect(config.vulnerabilitySeverity).toBe('LOW'); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,31 @@ | ||
| export function setHighestVulnerabilitySeverity( | ||
| config: Record<string, any>, | ||
| parent: Record<string, any>, | ||
| child: Record<string, any> | ||
|
setchy marked this conversation as resolved.
Outdated
|
||
| ): void { | ||
| let mostSevere: string | undefined; | ||
|
|
||
| const parentVulSeverity = parent.vulnerabilitySeverity?.toUpperCase(); | ||
|
|
||
| const childVulSeverity = child.vulnerabilitySeverity?.toUpperCase(); | ||
|
|
||
| if (!parentVulSeverity && childVulSeverity) { | ||
| mostSevere = childVulSeverity; | ||
| } else if (parentVulSeverity && !childVulSeverity) { | ||
| mostSevere = parentVulSeverity; | ||
| } else if (parentVulSeverity === 'CRITICAL') { | ||
| mostSevere = 'CRITICAL'; | ||
| } else if (parentVulSeverity === 'HIGH' && childVulSeverity !== 'CRITICAL') { | ||
| mostSevere = 'HIGH'; | ||
| } else if ( | ||
| parentVulSeverity === 'MODERATE' && | ||
| childVulSeverity !== 'CRITICAL' && | ||
| childVulSeverity !== 'HIGH' | ||
| ) { | ||
| mostSevere = 'MODERATE'; | ||
| } else { | ||
| mostSevere = childVulSeverity; | ||
| } | ||
|
setchy marked this conversation as resolved.
Outdated
|
||
|
|
||
| config.vulnerabilitySeverity = mostSevere; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.