Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust summary format #416

Merged
merged 15 commits into from Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -100,3 +100,5 @@ Thumbs.db
# Ignore built ts files
__tests__/runner/*
lib/**/*

tmp
7 changes: 4 additions & 3 deletions __tests__/config.test.ts
Expand Up @@ -5,13 +5,13 @@ import * as Utils from '../src/utils'

// GitHub Action inputs come in the form of environment variables
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
function setInput(input: string, value: string) {
function setInput(input: string, value: string): void {
process.env[`INPUT_${input.toUpperCase()}`] = value
}

// We want a clean ENV before each test. We use `delete`
// since we want `undefined` values and not empty strings.
function clearInputs() {
function clearInputs(): void {
const allowedOptions = [
'FAIL-ON-SEVERITY',
'FAIL-ON-SCOPES',
Expand All @@ -26,6 +26,7 @@ function clearInputs() {
'COMMENT-SUMMARY-IN-PR'
]

// eslint-disable-next-line github/array-foreach
allowedOptions.forEach(option => {
delete process.env[`INPUT_${option.toUpperCase()}`]
})
Expand Down Expand Up @@ -238,7 +239,7 @@ test('it supports comma-separated lists', async () => {
'config-file',
'./__tests__/fixtures/inline-license-config-sample.yml'
)
let config = await readConfig()
const config = await readConfig()

expect(config.allow_licenses).toEqual(['MIT', 'GPL-2.0-only'])
})
Expand Down
10 changes: 5 additions & 5 deletions __tests__/filter.test.ts
@@ -1,12 +1,12 @@
import {expect, test} from '@jest/globals'
import {Change, Changes} from '../src/schemas'
import {Change} from '../src/schemas'
import {
filterChangesBySeverity,
filterChangesByScopes,
filterAllowedAdvisories
} from '../src/filter'

let npmChange: Change = {
const npmChange: Change = {
manifest: 'package.json',
change_type: 'added',
ecosystem: 'npm',
Expand All @@ -26,7 +26,7 @@ let npmChange: Change = {
]
}

let rubyChange: Change = {
const rubyChange: Change = {
change_type: 'added',
manifest: 'Gemfile.lock',
ecosystem: 'rubygems',
Expand All @@ -52,7 +52,7 @@ let rubyChange: Change = {
]
}

let noVulnNpmChange: Change = {
const noVulnNpmChange: Change = {
manifest: 'package.json',
change_type: 'added',
ecosystem: 'npm',
Expand Down Expand Up @@ -92,7 +92,7 @@ test('it properly filters changes by scope', async () => {

test('it properly handles undefined advisory IDs', async () => {
const changes = [npmChange, rubyChange, noVulnNpmChange]
let result = filterAllowedAdvisories(undefined, changes)
const result = filterAllowedAdvisories(undefined, changes)
expect(result).toEqual([npmChange, rubyChange, noVulnNpmChange])
})

Expand Down
36 changes: 36 additions & 0 deletions __tests__/fixtures/create-test-change.ts
@@ -0,0 +1,36 @@
import {Change} from '../../src/schemas'
import {createTestVulnerability} from './create-test-vulnerability'

const defaultChange: Change = {
change_type: 'added',
manifest: 'package.json',
ecosystem: 'npm',
name: 'lodash',
version: '4.17.20',
package_url: 'pkg:npm/lodash@4.17.20',
license: 'MIT',
source_repository_url: 'https://github.com/lodash/lodash',
scope: 'runtime',
vulnerabilities: [
createTestVulnerability({
severity: 'high',
advisory_ghsa_id: 'GHSA-35jh-r3h4-6jhm',
advisory_summary: 'Command Injection in lodash',
advisory_url: 'https://github.com/advisories/GHSA-35jh-r3h4-6jhm'
}),
createTestVulnerability({
severity: 'moderate',
advisory_ghsa_id: 'GHSA-29mw-wpgm-hmr9',
advisory_summary:
'Regular Expression Denial of Service (ReDoS) in lodash',
advisory_url: 'https://github.com/advisories/GHSA-29mw-wpgm-hmr9'
})
]
}

const createTestChange = (overwrites: Partial<Change> = {}): Change => ({
...defaultChange,
...overwrites
})

export {createTestChange}
19 changes: 19 additions & 0 deletions __tests__/fixtures/create-test-vulnerability.ts
@@ -0,0 +1,19 @@
import {Change} from '../../src/schemas'

type Vulnerability = Change['vulnerabilities'][0]

const defaultTestVulnerability: Vulnerability = {
severity: 'high',
advisory_ghsa_id: 'GHSA-35jh-r3h4-6jhm',
advisory_summary: 'Command Injection in lodash',
advisory_url: 'https://github.com/advisories/GHSA-35jh-r3h4-6jhm'
}

const createTestVulnerability = (
overwrites: Partial<Vulnerability> = {}
): Vulnerability => ({
...defaultTestVulnerability,
...overwrites
})

export {createTestVulnerability}
7 changes: 5 additions & 2 deletions __tests__/licenses.test.ts
Expand Up @@ -3,7 +3,7 @@ import {Change, Changes} from '../src/schemas'

let getInvalidLicenseChanges: Function

let npmChange: Change = {
const npmChange: Change = {
manifest: 'package.json',
change_type: 'added',
ecosystem: 'npm',
Expand All @@ -23,7 +23,7 @@ let npmChange: Change = {
]
}

let rubyChange: Change = {
const rubyChange: Change = {
change_type: 'added',
manifest: 'Gemfile.lock',
ecosystem: 'rubygems',
Expand Down Expand Up @@ -63,6 +63,7 @@ const mockOctokit = {

jest.mock('octokit', () => {
return {
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
Octokit: class {
constructor() {
return mockOctokit
Expand All @@ -78,6 +79,7 @@ beforeEach(async () => {
// 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'))
})

Expand Down Expand Up @@ -140,6 +142,7 @@ test('it adds all licenses to unresolved if it is unable to determine the validi
throw new Error('Some Error')
})
})
// eslint-disable-next-line @typescript-eslint/no-require-imports
;({getInvalidLicenseChanges} = require('../src/licenses'))
const changes: Changes = [npmChange, rubyChange]
const invalidLicenses = await getInvalidLicenseChanges(changes, {
Expand Down