Skip to content
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

Issue #618 Change order of filtering to get correct list of vulnerabilities #622

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/filter.test.ts
Expand Up @@ -121,3 +121,17 @@ test('it properly filters changes with allowed vulnerabilities', async () => {
result = filterAllowedAdvisories(['second-random_string'], changes)
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
})

test('it properly filters by severity and also allowed vulnerabilities', async () => {
const changes = [rubyChange]

// filter by severity first then by allowed advisory
let tempResult = filterChangesBySeverity('moderate', changes)
let result = filterAllowedAdvisories(['second-random_string'], tempResult)
expect(result).toEqual([])

//filter by allowed advisory first then by severity (yields different output)
tempResult = filterAllowedAdvisories(['second-random_string'], changes)
result = filterChangesBySeverity('moderate', tempResult)
expect(result).not.toEqual([])
})
9 changes: 5 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/main.ts
Expand Up @@ -82,23 +82,22 @@ async function run(): Promise<void> {

const minSeverity = config.fail_on_severity
const scopedChanges = filterChangesByScopes(config.fail_on_scopes, changes)
const filteredChanges = filterAllowedAdvisories(
config.allow_ghsas,
scopedChanges
)

const vulnerableChanges = filterChangesBySeverity(
const filteredChanges = filterChangesBySeverity(
minSeverity,
filteredChanges
scopedChanges
).filter(
change =>
change.change_type === 'added' &&
change.vulnerabilities !== undefined &&
change.vulnerabilities.length > 0
)

const vulnerableChanges = filterAllowedAdvisories(
config.allow_ghsas,
filteredChanges
)
const invalidLicenseChanges = await getInvalidLicenseChanges(
filteredChanges,
scopedChanges,
{
allow: config.allow_licenses,
deny: config.deny_licenses,
Expand All @@ -108,9 +107,10 @@ async function run(): Promise<void> {

core.debug(`Filtered Changes: ${JSON.stringify(filteredChanges)}`)
core.debug(`Config Deny Packages: ${JSON.stringify(config)}`)
core.debug(`Vulnerable Changes: ${JSON.stringify(vulnerableChanges)}`)

const deniedChanges = await getDeniedChanges(
filteredChanges,
scopedChanges,
config.deny_packages,
config.deny_groups
)
Expand Down