-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #719 from actions/change-spdx-parser
Update SPDX Expression Parsing
- Loading branch information
Showing
17 changed files
with
871 additions
and
298 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
fail_on_severity: critical | ||
allow_licenses: | ||
- 'BSD' | ||
- 'GPL 2' | ||
- 'BSD-3-Clause' | ||
- 'GPL-2.0' |
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,7 +1,6 @@ | ||
import {expect, jest, test} from '@jest/globals' | ||
import {Change, Changes} from '../src/schemas' | ||
|
||
let getInvalidLicenseChanges: Function | ||
import {getInvalidLicenseChanges} from '../src/licenses' | ||
|
||
const npmChange: Change = { | ||
manifest: 'package.json', | ||
|
@@ -30,7 +29,7 @@ const rubyChange: Change = { | |
name: 'actionsomething', | ||
version: '3.2.0', | ||
package_url: 'pkg:gem/[email protected]', | ||
license: 'BSD', | ||
license: 'BSD-3-Clause', | ||
source_repository_url: 'github.com/some-repo', | ||
scope: 'runtime', | ||
vulnerabilities: [ | ||
|
@@ -100,29 +99,32 @@ jest.mock('octokit', () => { | |
|
||
beforeEach(async () => { | ||
jest.resetModules() | ||
jest.doMock('spdx-satisfies', () => { | ||
// mock spdx-satisfies return value | ||
// true for BSD, false for all others | ||
return jest.fn((license: string, _: string): boolean => license === 'BSD') | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
;({getInvalidLicenseChanges} = require('../src/licenses')) | ||
}) | ||
|
||
test('it adds license outside the allow list to forbidden changes', async () => { | ||
const changes: Changes = [npmChange, rubyChange] | ||
const changes: Changes = [ | ||
npmChange, // MIT license | ||
rubyChange // BSD license | ||
] | ||
|
||
const {forbidden} = await getInvalidLicenseChanges(changes, { | ||
allow: ['BSD'] | ||
allow: ['BSD-3-Clause'] | ||
}) | ||
|
||
expect(forbidden[0]).toBe(npmChange) | ||
expect(forbidden.length).toEqual(1) | ||
}) | ||
|
||
test('it adds license inside the deny list to forbidden changes', async () => { | ||
const changes: Changes = [npmChange, rubyChange] | ||
const changes: Changes = [ | ||
npmChange, // MIT license | ||
rubyChange // BSD license | ||
] | ||
|
||
const {forbidden} = await getInvalidLicenseChanges(changes, { | ||
deny: ['BSD'] | ||
deny: ['BSD-3-Clause'] | ||
}) | ||
|
||
expect(forbidden[0]).toBe(rubyChange) | ||
expect(forbidden.length).toEqual(1) | ||
}) | ||
|
@@ -133,7 +135,7 @@ test('it does not add license outside the allow list to forbidden changes if it | |
{...rubyChange, change_type: 'removed'} | ||
] | ||
const {forbidden} = await getInvalidLicenseChanges(changes, { | ||
allow: ['BSD'] | ||
allow: ['BSD-3-Clause'] | ||
}) | ||
expect(forbidden).toStrictEqual([]) | ||
}) | ||
|
@@ -144,7 +146,7 @@ test('it does not add license inside the deny list to forbidden changes if it is | |
{...rubyChange, change_type: 'removed'} | ||
] | ||
const {forbidden} = await getInvalidLicenseChanges(changes, { | ||
deny: ['BSD'] | ||
deny: ['BSD-3-Clause'] | ||
}) | ||
expect(forbidden).toStrictEqual([]) | ||
}) | ||
|
@@ -156,23 +158,18 @@ test('it adds license outside the allow list to forbidden changes if it is in bo | |
{...rubyChange, change_type: 'removed'} | ||
] | ||
const {forbidden} = await getInvalidLicenseChanges(changes, { | ||
allow: ['BSD'] | ||
allow: ['BSD-3-Clause'] | ||
}) | ||
expect(forbidden).toStrictEqual([npmChange]) | ||
}) | ||
|
||
test('it adds all licenses to unresolved if it is unable to determine the validity', async () => { | ||
jest.resetModules() // reset module set in before | ||
jest.doMock('spdx-satisfies', () => { | ||
return jest.fn((_first: string, _second: string) => { | ||
throw new Error('Some Error') | ||
}) | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
;({getInvalidLicenseChanges} = require('../src/licenses')) | ||
const changes: Changes = [npmChange, rubyChange] | ||
const changes: Changes = [ | ||
{...npmChange, license: 'Foo'}, | ||
{...rubyChange, license: 'Bar'} | ||
] | ||
const invalidLicenses = await getInvalidLicenseChanges(changes, { | ||
allow: ['BSD'] | ||
allow: ['Apache-2.0'] | ||
}) | ||
expect(invalidLicenses.forbidden.length).toEqual(0) | ||
expect(invalidLicenses.unlicensed.length).toEqual(0) | ||
|
@@ -182,7 +179,7 @@ test('it adds all licenses to unresolved if it is unable to determine the validi | |
test('it does not filter out changes that are on the exclusions list', async () => { | ||
const changes: Changes = [pipChange, npmChange, rubyChange] | ||
const licensesConfig = { | ||
allow: ['BSD'], | ||
allow: ['BSD-3-Clause'], | ||
licenseExclusions: ['pkg:pypi/[email protected]', 'pkg:npm/[email protected]'] | ||
} | ||
const invalidLicenses = await getInvalidLicenseChanges( | ||
|
@@ -198,7 +195,7 @@ test('it does not fail when the packages dont have a valid PURL', async () => { | |
|
||
const changes: Changes = [emptyPurlChange, npmChange, rubyChange] | ||
const licensesConfig = { | ||
allow: ['BSD'], | ||
allow: ['BSD-3-Clause'], | ||
licenseExclusions: ['pkg:pypi/[email protected]', 'pkg:npm/[email protected]'] | ||
} | ||
|
||
|
@@ -212,16 +209,18 @@ test('it does not fail when the packages dont have a valid PURL', async () => { | |
test('it does filters out changes if they are not on the exclusions list', async () => { | ||
const changes: Changes = [pipChange, npmChange, rubyChange] | ||
const licensesConfig = { | ||
allow: ['BSD'], | ||
allow: ['BSD-3-Clause'], | ||
licenseExclusions: [ | ||
'pkg:pypi/[email protected]', | ||
'pkg:npm/[email protected]' | ||
] | ||
} | ||
|
||
const invalidLicenses = await getInvalidLicenseChanges( | ||
changes, | ||
licensesConfig | ||
) | ||
|
||
expect(invalidLicenses.forbidden.length).toEqual(2) | ||
expect(invalidLicenses.forbidden[0]).toBe(pipChange) | ||
expect(invalidLicenses.forbidden[1]).toBe(npmChange) | ||
|
Oops, something went wrong.