-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Federico Builes
committed
Jun 6, 2022
1 parent
8c646c1
commit bccacf9
Showing
6 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
allow_licenses: [] | ||
deny_licenses: [] |
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 @@ | ||
fail_on_severity: critical |
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,53 @@ | ||
import {expect, test} from '@jest/globals' | ||
import {Change, Changes} from '../src/schemas' | ||
import {hasInvalidLicenses} from '../src/licenses' | ||
|
||
let npmChange: Change = { | ||
manifest: 'package.json', | ||
change_type: 'added', | ||
ecosystem: 'npm', | ||
name: 'Reeuhq', | ||
version: '1.0.2', | ||
package_url: 'somepurl', | ||
license: 'MIT', | ||
source_repository_url: 'github.com/some-repo', | ||
vulnerabilities: [ | ||
{ | ||
severity: 'critical', | ||
advisory_ghsa_id: 'first-random_string', | ||
advisory_summary: 'very dangerouns', | ||
advisory_url: 'github.com/future-funk' | ||
} | ||
] | ||
} | ||
|
||
let rubyChange: Change = { | ||
change_type: 'added', | ||
manifest: 'Gemfile.lock', | ||
ecosystem: 'rubygems', | ||
name: 'actionsomething', | ||
version: '3.2.0', | ||
package_url: 'somerubypurl', | ||
license: 'BSD', | ||
source_repository_url: 'github.com/some-repo', | ||
vulnerabilities: [ | ||
{ | ||
severity: 'moderate', | ||
advisory_ghsa_id: 'second-random_string', | ||
advisory_summary: 'not so dangerouns', | ||
advisory_url: 'github.com/future-funk' | ||
}, | ||
{ | ||
severity: 'low', | ||
advisory_ghsa_id: 'third-random_string', | ||
advisory_summary: 'dont page me', | ||
advisory_url: 'github.com/future-funk' | ||
} | ||
] | ||
} | ||
|
||
test('hasInvalidLicenses fails if an unallowed license is found', async () => { | ||
const changes: Changes = [npmChange, rubyChange] | ||
const result = hasInvalidLicenses(changes, ['BSD'], []) | ||
expect(result.length).toBe(1) | ||
}) |
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,34 @@ | ||
import {Change, ChangeSchema} from './schemas' | ||
|
||
export function hasInvalidLicenses( | ||
changes: Array<Change>, | ||
allowLicenses: Array<string> | undefined, | ||
failLicenses: Array<string> | undefined | ||
): Array<Change> { | ||
let disallowed: Change[] = [] | ||
|
||
if (allowLicenses === undefined) { | ||
allowLicenses = [] | ||
} | ||
if (failLicenses === undefined) { | ||
failLicenses = [] | ||
} | ||
|
||
for (const change of changes) { | ||
let license = change.license | ||
// TODO: be loud about unknown licenses | ||
if (license === null) { | ||
continue | ||
} | ||
|
||
if (allowLicenses.includes(license)) { | ||
disallowed.push(change) | ||
} | ||
} | ||
|
||
return disallowed | ||
} | ||
|
||
export function printLicensesError(changes: Array<Change>): void { | ||
return | ||
} |
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