Files
dependency-review-action/__tests__/licenses.test.ts
T

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-06-06 17:07:26 +02:00
import {expect, test} from '@jest/globals'
import {Change, Changes} from '../src/schemas'
2022-06-08 17:45:42 +02:00
import {getDeniedLicenseChanges} from '../src/licenses'
2022-06-06 17:07:26 +02:00
let npmChange: Change = {
manifest: 'package.json',
change_type: 'added',
ecosystem: 'npm',
name: 'Reeuhq',
version: '1.0.2',
2022-06-13 20:19:01 +02:00
package_url: 'pkg:npm/[email protected]',
2022-06-06 17:07:26 +02:00
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',
2022-06-13 20:19:01 +02:00
package_url: 'pkg:gem/[email protected]',
2022-06-06 17:07:26 +02:00
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'
}
]
}
2022-06-08 17:45:42 +02:00
test('it fails if a license outside the allow list is found', async () => {
2022-06-06 17:07:26 +02:00
const changes: Changes = [npmChange, rubyChange]
2022-06-14 13:54:27 +02:00
const [invalidChanges, _] = getDeniedLicenseChanges(changes, {allow: ['BSD']})
2022-06-08 15:53:14 +02:00
expect(invalidChanges[0]).toBe(npmChange)
2022-06-06 17:07:26 +02:00
})
2022-06-06 18:06:00 +02:00
2022-06-08 17:45:42 +02:00
test('it fails if a license inside the deny list is found', async () => {
2022-06-06 18:06:00 +02:00
const changes: Changes = [npmChange, rubyChange]
2022-06-14 13:54:27 +02:00
const [invalidChanges] = getDeniedLicenseChanges(changes, {deny: ['BSD']})
2022-06-08 15:53:14 +02:00
expect(invalidChanges[0]).toBe(rubyChange)
2022-06-06 18:06:00 +02:00
})
// This is more of a "here's a behavior that might be surprising" than an actual
// thing we want in the system. Please remove this test after refactoring.
test('it fails all license checks when allow is provided an empty array', async () => {
const changes: Changes = [npmChange, rubyChange]
2022-06-14 13:54:27 +02:00
let [invalidChanges, _] = getDeniedLicenseChanges(changes, {
allow: [],
deny: ['BSD']
})
expect(invalidChanges.length).toBe(2)
})