-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a filter for vulns that are on the allowlist
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import {expect, test} from '@jest/globals' | ||
import {Change, Changes} from '../src/schemas' | ||
import {filterChangesBySeverity, filterChangesByScopes} from '../src/filter' | ||
import { | ||
filterChangesBySeverity, | ||
filterChangesByScopes, | ||
filterOutAllowedAdvisories | ||
} from '../src/filter' | ||
|
||
let npmChange: Change = { | ||
manifest: 'package.json', | ||
|
@@ -48,6 +52,19 @@ let rubyChange: Change = { | |
] | ||
} | ||
|
||
let noVulnNpmChange: Change = { | ||
manifest: 'package.json', | ||
change_type: 'added', | ||
ecosystem: 'npm', | ||
name: 'helpful', | ||
version: '1.0.0', | ||
package_url: 'pkg:npm/[email protected]', | ||
license: 'MIT', | ||
source_repository_url: 'github.com/some-repo', | ||
scope: 'runtime', | ||
vulnerabilities: [] | ||
} | ||
|
||
test('it properly filters changes by severity', async () => { | ||
const changes = [npmChange, rubyChange] | ||
let result = filterChangesBySeverity('high', changes) | ||
|
@@ -72,3 +89,29 @@ test('it properly filters changes by scope', async () => { | |
result = filterChangesByScopes(['runtime', 'development'], changes) | ||
expect(result).toEqual([npmChange, rubyChange]) | ||
}) | ||
|
||
test('it properly filters changes with allowed vulnerabilities', async () => { | ||
const changes = [npmChange, rubyChange, noVulnNpmChange] | ||
|
||
let result = filterOutAllowedAdvisories(['notrealGHSAID'], changes) | ||
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange]) | ||
|
||
result = filterOutAllowedAdvisories(['first-random_string'], changes) | ||
expect(result).toEqual([rubyChange, noVulnNpmChange]) | ||
|
||
result = filterOutAllowedAdvisories( | ||
['second-random_string', 'third-random_string'], | ||
changes | ||
) | ||
expect(result).toEqual([npmChange, noVulnNpmChange]) | ||
|
||
result = filterOutAllowedAdvisories( | ||
['first-random_string', 'second-random_string', 'third-random_string'], | ||
changes | ||
) | ||
expect(result).toEqual([noVulnNpmChange]) | ||
|
||
// if we have a change with multiple vulnerabilities but only one is allowed, we still should not filter out that change | ||
result = filterOutAllowedAdvisories(['second-random_string'], changes) | ||
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange]) | ||
}) |
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