Skip to content

Commit cce6700

Browse files
SIGINT-1763: Ability to upload and scan with Polaris (#223)
1 parent ec86791 commit cce6700

File tree

10 files changed

+228
-42
lines changed

10 files changed

+228
-42
lines changed

action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ inputs:
9292
polaris_upload_sarif_report:
9393
description: 'Flag to enable/disable uploading of Polaris SARIF report to GitHub Advanced Security'
9494
required: false
95+
polaris_assessment_mode:
96+
description: 'The test mode type of this scan'
97+
required: false
98+
project_directory:
99+
description: 'The project source directory. Defaults to repository root directory. Set this to specify a custom folder that is other than repository root'
100+
required: false
101+
project_source_archive:
102+
description: 'The zipped source file path. It overrides the project directory setting'
103+
required: false
104+
project_source_preserveSymLinks:
105+
description: 'Flag indicating whether to preserve symlinks in the source zip'
106+
required: false
107+
project_source_excludes:
108+
description: 'A list of git ignore pattern strings that indicate the files need to be excluded from the zip file'
109+
required: false
95110
synopsys_bridge_install_directory:
96111
description: 'Synopsys Bridge Install Directory'
97112
required: false

dist/index.js

Lines changed: 78 additions & 39 deletions
Large diffs are not rendered by default.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/application-constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export const POLARIS_REPORTS_SARIF_SEVERITIES_KEY = 'polaris_reports_sarif_sever
6868
export const POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES_KEY = 'polaris_reports_sarif_groupSCAIssues'
6969
export const POLARIS_REPORTS_SARIF_ISSUE_TYPES_KEY = 'polaris_reports_sarif_issue_types'
7070
export const POLARIS_UPLOAD_SARIF_REPORT_KEY = 'polaris_upload_sarif_report'
71+
export const POLARIS_ASSESSMENT_MODE_KEY = 'polaris_assessment_mode'
72+
export const PROJECT_SOURCE_ARCHIVE_KEY = 'project_source_archive'
73+
export const PROJECT_SOURCE_PRESERVESYMLINKS_KEY = 'project_source_preserveSymLinks'
74+
export const PROJECT_SOURCE_EXCLUDES_KEY = 'project_source_excludes'
75+
export const PROJECT_DIRECTORY_KEY = 'project_directory'
7176

7277
// Blackduck
7378
export const BLACKDUCK_URL_KEY = 'blackduck_url'

src/synopsys-action/input-data/blackduck.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum BLACKDUCK_SCAN_FAILURE_SEVERITIES {
1414

1515
export interface Blackduck {
1616
blackduck: BlackduckData
17+
project?: ProjectData
1718
github?: GithubData
1819
network?: NetworkAirGap
1920
}
@@ -28,6 +29,10 @@ export interface BlackduckData {
2829
reports?: Reports
2930
}
3031

32+
export interface ProjectData {
33+
directory?: string
34+
}
35+
3136
export interface Branch {
3237
name: string
3338
}

src/synopsys-action/input-data/coverity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Coverity {
1010
export interface ProjectData {
1111
repository?: {name: string}
1212
branch?: {name: string}
13+
directory?: string
1314
}
1415

1516
export interface AutomationData {

src/synopsys-action/input-data/polaris.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Reports} from './reports'
33

44
export interface Polaris {
55
polaris: PolarisData
6+
project?: ProjectData
67
github?: GithubData
78
}
89

@@ -19,6 +20,15 @@ export interface PolarisData {
1920
reports?: Reports
2021
}
2122

23+
export interface ProjectData {
24+
directory?: string
25+
source?: {
26+
archive?: string
27+
preserveSymLinks?: boolean
28+
excludes?: string[]
29+
}
30+
}
31+
2232
export interface PrComment {
2333
enabled?: boolean
2434
severities?: string[]

src/synopsys-action/inputs.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const POLARIS_REPORTS_SARIF_SEVERITIES = getInput(constants.POLARIS_REPOR
2626
export const POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES = getInput(constants.POLARIS_REPORTS_SARIF_GROUP_SCA_ISSUES_KEY)?.trim() || ''
2727
export const POLARIS_REPORTS_SARIF_ISSUE_TYPES = getInput(constants.POLARIS_REPORTS_SARIF_ISSUE_TYPES_KEY)?.trim() || ''
2828
export const POLARIS_UPLOAD_SARIF_REPORT = getInput(constants.POLARIS_UPLOAD_SARIF_REPORT_KEY)?.trim() || ''
29+
export const POLARIS_ASSESSMENT_MODE = getInput(constants.POLARIS_ASSESSMENT_MODE_KEY)?.trim() || ''
30+
export const PROJECT_DIRECTORY = getInput(constants.PROJECT_DIRECTORY_KEY)?.trim() || ''
31+
export const PROJECT_SOURCE_ARCHIVE = getInput(constants.PROJECT_SOURCE_ARCHIVE_KEY)?.trim() || ''
32+
export const PROJECT_SOURCE_PRESERVESYMLINKS = getInput(constants.PROJECT_SOURCE_PRESERVESYMLINKS_KEY)?.trim() || ''
33+
export const PROJECT_SOURCE_EXCLUDES = getInput(constants.PROJECT_SOURCE_EXCLUDES_KEY)?.trim() || ''
2934

3035
// Coverity related inputs
3136
export const COVERITY_URL = getInput(constants.COVERITY_URL_KEY)?.trim() || ''

src/synopsys-action/tools-parameter.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ export class SynopsysToolsParameter {
6464
serverUrl: inputs.POLARIS_SERVER_URL,
6565
application: {name: applicationName},
6666
project: {name: projectName},
67-
assessment: {types: assessmentTypeArray}
67+
assessment: {
68+
types: assessmentTypeArray,
69+
...(inputs.POLARIS_ASSESSMENT_MODE && {
70+
mode: inputs.POLARIS_ASSESSMENT_MODE
71+
})
72+
}
6873
}
6974
}
7075
}
@@ -82,6 +87,32 @@ export class SynopsysToolsParameter {
8287
}
8388
}
8489
}
90+
91+
if (inputs.PROJECT_DIRECTORY || inputs.PROJECT_SOURCE_ARCHIVE || inputs.PROJECT_SOURCE_EXCLUDES || inputs.PROJECT_SOURCE_PRESERVESYMLINKS) {
92+
polData.data.project = {}
93+
94+
if (inputs.PROJECT_DIRECTORY) {
95+
polData.data.project.directory = inputs.PROJECT_DIRECTORY
96+
}
97+
98+
if (inputs.PROJECT_SOURCE_ARCHIVE || inputs.PROJECT_SOURCE_EXCLUDES || inputs.PROJECT_SOURCE_PRESERVESYMLINKS) {
99+
polData.data.project.source = {}
100+
101+
if (inputs.PROJECT_SOURCE_ARCHIVE) {
102+
polData.data.project.source.archive = inputs.PROJECT_SOURCE_ARCHIVE
103+
}
104+
105+
if (inputs.PROJECT_SOURCE_PRESERVESYMLINKS) {
106+
polData.data.project.source.preserveSymLinks = parseToBoolean(inputs.PROJECT_SOURCE_PRESERVESYMLINKS)
107+
}
108+
109+
if (inputs.PROJECT_SOURCE_EXCLUDES) {
110+
const sourceExcludesList: string[] = inputs.PROJECT_SOURCE_EXCLUDES.split(',').map(sourceExclude => sourceExclude.trim())
111+
polData.data.project.source.excludes = sourceExcludesList
112+
}
113+
}
114+
}
115+
85116
const isPrEvent = isPullRequestEvent()
86117
if (parseToBoolean(inputs.POLARIS_PRCOMMENT_ENABLED)) {
87118
if (isPrEvent) {
@@ -224,7 +255,7 @@ export class SynopsysToolsParameter {
224255
covData.data.coverity.connect.policy = {view: inputs.COVERITY_POLICY_VIEW}
225256
}
226257

227-
if (inputs.COVERITY_REPOSITORY_NAME || inputs.COVERITY_BRANCH_NAME) {
258+
if (inputs.COVERITY_REPOSITORY_NAME || inputs.COVERITY_BRANCH_NAME || inputs.PROJECT_DIRECTORY) {
228259
covData.data.project = {
229260
...(inputs.COVERITY_REPOSITORY_NAME && {
230261
repository: {
@@ -235,6 +266,9 @@ export class SynopsysToolsParameter {
235266
branch: {
236267
name: inputs.COVERITY_BRANCH_NAME
237268
}
269+
}),
270+
...(inputs.PROJECT_DIRECTORY && {
271+
directory: inputs.PROJECT_DIRECTORY
238272
})
239273
}
240274
}
@@ -330,6 +364,12 @@ export class SynopsysToolsParameter {
330364
}
331365
}
332366

367+
if (inputs.PROJECT_DIRECTORY) {
368+
blackduckData.data.project = {
369+
directory: inputs.PROJECT_DIRECTORY
370+
}
371+
}
372+
333373
const isPrEvent = isPullRequestEvent()
334374
if (parseToBoolean(inputs.BLACKDUCK_PRCOMMENT_ENABLED)) {
335375
if (isPrEvent) {

test/unit/synopsys-action/tools-parameter.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,72 @@ test('Test getFormattedCommandForBlackduck with sarif params', () => {
722722
expect(resp).toContain('--stage blackduck')
723723
})
724724

725+
it('should pass polaris source upload fields to bridge', () => {
726+
Object.defineProperty(inputs, 'POLARIS_SERVER_URL', {value: 'server_url'})
727+
Object.defineProperty(inputs, 'POLARIS_ACCESS_TOKEN', {value: 'access_token'})
728+
Object.defineProperty(inputs, 'POLARIS_APPLICATION_NAME', {value: 'POLARIS_APPLICATION_NAME'})
729+
Object.defineProperty(inputs, 'POLARIS_PROJECT_NAME', {value: 'POLARIS_PROJECT_NAME'})
730+
Object.defineProperty(inputs, 'POLARIS_ASSESSMENT_TYPES', {value: 'SCA, SAST'})
731+
Object.defineProperty(inputs, 'POLARIS_BRANCH_NAME', {value: 'feature1'})
732+
Object.defineProperty(inputs, 'POLARIS_ASSESSMENT_MODE', {value: 'assessment_mode'})
733+
Object.defineProperty(inputs, 'PROJECT_DIRECTORY', {value: 'polaris_project_directory'})
734+
Object.defineProperty(inputs, 'PROJECT_SOURCE_ARCHIVE', {value: 'source_archive'})
735+
Object.defineProperty(inputs, 'PROJECT_SOURCE_PRESERVESYMLINKS', {value: true})
736+
Object.defineProperty(inputs, 'PROJECT_SOURCE_EXCLUDES', {value: 'source_exclude1, source_exclude2'})
737+
const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
738+
const resp = stp.getFormattedCommandForPolaris('synopsys-action')
739+
740+
const jsonString = fs.readFileSync(tempPath.concat(polaris_input_file), 'utf-8')
741+
const jsonData = JSON.parse(jsonString)
742+
expect(resp).not.toBeNull()
743+
expect(resp).toContain('--stage polaris')
744+
expect(jsonData.data.polaris.serverUrl).toContain('server_url')
745+
expect(jsonData.data.polaris.accesstoken).toContain('access_token')
746+
expect(jsonData.data.polaris.application.name).toContain('POLARIS_APPLICATION_NAME')
747+
expect(jsonData.data.polaris.project.name).toContain('POLARIS_PROJECT_NAME')
748+
expect(jsonData.data.polaris.branch.name).toContain('feature1')
749+
expect(jsonData.data.polaris.assessment.mode).toContain('assessment_mode')
750+
expect(jsonData.data.polaris.assessment.types).toEqual(['SCA', 'SAST'])
751+
expect(jsonData.data.project.directory).toContain('polaris_project_directory')
752+
expect(jsonData.data.project.source.archive).toContain('source_archive')
753+
expect(jsonData.data.project.source.preserveSymLinks).toBe(true)
754+
expect(jsonData.data.project.source.excludes).toEqual(['source_exclude1', 'source_exclude2'])
755+
})
756+
757+
it('should pass black duck fields and project directory field to bridge', () => {
758+
Object.defineProperty(inputs, 'BLACKDUCK_URL', {value: 'BLACKDUCK_URL'})
759+
Object.defineProperty(inputs, 'BLACKDUCK_API_TOKEN', {value: 'BLACKDUCK_API_TOKEN'})
760+
Object.defineProperty(inputs, 'PROJECT_DIRECTORY', {value: 'BLACKDUCK_PROJECT_DIRECTORY'})
761+
762+
const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
763+
const resp = stp.getFormattedCommandForBlackduck()
764+
765+
const jsonString = fs.readFileSync(tempPath.concat(blackduck_input_file), 'utf-8')
766+
const jsonData = JSON.parse(jsonString)
767+
expect(resp).not.toBeNull()
768+
expect(resp).toContain('--stage blackduck')
769+
expect(jsonData.data.blackduck.url).toBe('BLACKDUCK_URL')
770+
expect(jsonData.data.blackduck.token).toBe('BLACKDUCK_API_TOKEN')
771+
expect(jsonData.data.project.directory).toBe('BLACKDUCK_PROJECT_DIRECTORY')
772+
})
773+
774+
it('should pass coverity fields and project directory field to bridge', () => {
775+
Object.defineProperty(inputs, 'COVERITY_URL', {value: 'COVERITY_URL'})
776+
Object.defineProperty(inputs, 'COVERITY_USER', {value: 'COVERITY_USER'})
777+
Object.defineProperty(inputs, 'COVERITY_PASSPHRASE', {value: 'COVERITY_PASSPHRASE'})
778+
779+
const stp: SynopsysToolsParameter = new SynopsysToolsParameter(tempPath)
780+
const resp = stp.getFormattedCommandForCoverity('synopsys-action')
781+
782+
const jsonString = fs.readFileSync(tempPath.concat(coverity_input_file), 'utf-8')
783+
const jsonData = JSON.parse(jsonString)
784+
expect(resp).not.toBeNull()
785+
expect(resp).toContain('--stage connect')
786+
expect(jsonData.data.coverity.connect.url).toBe('COVERITY_URL')
787+
expect(jsonData.data.coverity.connect.user.name).toBe('COVERITY_USER')
788+
expect(jsonData.data.coverity.connect.user.password).toBe('COVERITY_PASSPHRASE')
789+
})
790+
725791
process.env['GITHUB_SERVER_URL'] = 'https://custom.com'
726792
describe('test black duck values passed correctly to bridge for workflow simplification', () => {
727793
it('should pass black duck pr comment fields to bridge in pr context', () => {

0 commit comments

Comments
 (0)