Skeleton for license validation.
This commit is contained in:
@@ -16,3 +16,16 @@ test('returns a default config when the config file was not found', async () =>
|
||||
expect(options.fail_on_severity).toEqual('low')
|
||||
expect(options.allow_licenses).toEqual([])
|
||||
})
|
||||
|
||||
test('it reads config files with empty options', async () => {
|
||||
let options = readConfigFile('./__tests__/fixtures/no-licenses-config.yml')
|
||||
expect(options.fail_on_severity).toEqual('critical')
|
||||
expect(options.allow_licenses).toEqual(undefined)
|
||||
expect(options.deny_licenses).toEqual(undefined)
|
||||
})
|
||||
|
||||
test('it raises an error if both an allow and denylist are specified', async () => {
|
||||
expect(() =>
|
||||
readConfigFile('./__tests__/fixtures/conflictive-config.yml')
|
||||
).toThrow()
|
||||
})
|
||||
|
||||
2
__tests__/fixtures/conflictive-config.yml
Normal file
2
__tests__/fixtures/conflictive-config.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
allow_licenses: []
|
||||
deny_licenses: []
|
||||
1
__tests__/fixtures/no-licenses-config.yml
Normal file
1
__tests__/fixtures/no-licenses-config.yml
Normal file
@@ -0,0 +1 @@
|
||||
fail_on_severity: critical
|
||||
53
__tests__/licenses.test.ts
Normal file
53
__tests__/licenses.test.ts
Normal file
@@ -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)
|
||||
})
|
||||
Reference in New Issue
Block a user