add tests and docs

This commit is contained in:
Adrien Pessu
2023-08-07 14:04:41 +02:00
parent 6862f6f65f
commit 00f1f5b642
11 changed files with 164 additions and 54 deletions

View File

@@ -75,6 +75,27 @@ const pipChange: Change = {
]
}
const mvnChange: Change = {
change_type: 'added',
manifest: 'pom.xml',
ecosystem: 'maven',
name: 'org.apache.logging.log4j:log4j-core',
version: '2.15.0',
package_url: 'pkg:org.apache.logging.log4j:log4j-core@1.1.1',
license: 'Apache-2.0',
source_repository_url:
'https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core',
scope: 'unknown',
vulnerabilities: [
{
severity: 'critical',
advisory_ghsa_id: 'second-random_string',
advisory_summary: 'not so dangerous',
advisory_url: 'github.com/future-funk'
}
]
}
jest.mock('@actions/core')
const mockOctokit = {
@@ -106,13 +127,36 @@ beforeEach(async () => {
return jest.fn((license: string, _: string): boolean => license === 'BSD')
})
// eslint-disable-next-line @typescript-eslint/no-require-imports
;({getDeniedChanges} = require('../src/denylist'))
;({getDeniedChanges} = require('../src/deny'))
})
test('it adds license outside the allow list to forbidden changes', async () => {
test('it adds packages in the deny packages list', async () => {
const changes: Changes = [npmChange, rubyChange]
const deniedChanges = await getDeniedChanges(changes, ['actionsomething'])
const deniedChanges = await getDeniedChanges(changes, ['actionsomething'], [])
expect(deniedChanges[0]).toBe(rubyChange)
expect(deniedChanges.length).toEqual(1)
})
test('it adds packages in the deny group list', async () => {
const changes: Changes = [mvnChange, rubyChange]
const deniedChanges = await getDeniedChanges(
changes,
[],
['org.apache.logging.log4j']
)
expect(deniedChanges[0]).toBe(mvnChange)
expect(deniedChanges.length).toEqual(1)
})
test('it adds packages outside of the deny lists', async () => {
const changes: Changes = [npmChange, pipChange]
const deniedChanges = await getDeniedChanges(
changes,
['actionsomething'],
['org.apache.logging.log4j']
)
expect(deniedChanges.length).toEqual(0)
})

View File

@@ -24,7 +24,8 @@ const defaultConfig: ConfigurationOptions = {
allow_ghsas: [],
allow_licenses: [],
deny_licenses: [],
deny_list: [],
deny_packages: [],
deny_groups: [],
comment_summary_in_pr: true
}