@docupace/pipeline 1.0.123-xray.2 → 1.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tenable-scan.sh +3 -12
- package/package.json +2 -5
- package/src/changeset/validate.js +0 -10
- package/src/next/util.js +3 -32
- package/.gitignore +0 -103
- package/pnpm-workspace.yaml +0 -3
- package/src/tenable/args.js +0 -157
- package/src/tenable/args.test.js +0 -226
- package/src/tenable/cli.js +0 -24
- package/src/tenable/docker.js +0 -45
- package/src/tenable/fsops.js +0 -15
- package/src/tenable/scan.js +0 -284
- package/src/tenable/scan.test.js +0 -355
- package/src/veracode/args.js +0 -67
- package/src/veracode/args.test.js +0 -137
- package/src/veracode/cli.js +0 -16
- package/src/veracode/fsops.js +0 -7
- package/src/veracode/scan.js +0 -120
- package/src/veracode/scan.test.js +0 -246
- package/src/veracode/veracode.js +0 -33
- package/src/xray/cli.js +0 -37
- package/src/xray/notify.js +0 -107
- package/src/xray/notify.test.js +0 -161
- package/src/xray/report.js +0 -194
- package/src/xray/report.test.js +0 -278
- package/src/xray/slack.js +0 -14
package/src/veracode/args.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// Pure parsing/formatting logic for the Veracode scan step, ported from the
|
|
2
|
-
// veracode-scan step in bitbucket-pipelines.yml. No fs/process calls here so
|
|
3
|
-
// it's unit-testable.
|
|
4
|
-
|
|
5
|
-
// Mirrors `tr -c 'A-Za-z0-9._-' '-'`: every character outside that set is
|
|
6
|
-
// replaced with '-' (no squeezing of consecutive replacements).
|
|
7
|
-
export function slugify(label) {
|
|
8
|
-
return label.replace(/[^A-Za-z0-9._-]/g, '-');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Mirrors `printf '%s' "${BITBUCKET_COMMIT:-local}" | cut -c1-7`.
|
|
12
|
-
export function shortSha(commit = 'local') {
|
|
13
|
-
return (commit || 'local').slice(0, 7);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// One "label:appname:path1,path2,..." entry from VERACODE_TARGETS. Mirrors
|
|
17
|
-
// `cut -d: -f1/-f2/-f3`: only the first three colon-delimited fields matter,
|
|
18
|
-
// and a 4th+ field (e.g. a colon inside a path) is silently dropped rather
|
|
19
|
-
// than folded into the paths field.
|
|
20
|
-
export function parseVeracodeTargets(targetsStr) {
|
|
21
|
-
return (targetsStr || '')
|
|
22
|
-
.split(';')
|
|
23
|
-
.map((t) => t.trim())
|
|
24
|
-
.filter(Boolean)
|
|
25
|
-
.map((raw) => {
|
|
26
|
-
const [rawLabel = '', appname = '', pathsField = ''] = raw.split(':');
|
|
27
|
-
const label = rawLabel || 'app';
|
|
28
|
-
const slug = slugify(label);
|
|
29
|
-
const paths = pathsField.split(',').filter((p) => p.length > 0);
|
|
30
|
-
|
|
31
|
-
if (!appname || paths.length === 0) {
|
|
32
|
-
return { label, slug, appname, paths, skipped: true };
|
|
33
|
-
}
|
|
34
|
-
return { label, slug, appname, paths, skipped: false };
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function buildZipFilename(slug) {
|
|
39
|
-
return `veracode-${slug}.zip`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function buildVersion(sha, label) {
|
|
43
|
-
return `sha-${sha}-${label}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// -createprofile false — the app profile must already exist in the Veracode
|
|
47
|
-
// portal. -autoscan true starts the scan once prescan passes.
|
|
48
|
-
export function buildUploadArgs({ vid, vkey, appname, filepath, version }) {
|
|
49
|
-
return [
|
|
50
|
-
'-vid',
|
|
51
|
-
vid,
|
|
52
|
-
'-vkey',
|
|
53
|
-
vkey,
|
|
54
|
-
'-action',
|
|
55
|
-
'uploadandscan',
|
|
56
|
-
'-appname',
|
|
57
|
-
appname,
|
|
58
|
-
'-createprofile',
|
|
59
|
-
'false',
|
|
60
|
-
'-autoscan',
|
|
61
|
-
'true',
|
|
62
|
-
'-filepath',
|
|
63
|
-
filepath,
|
|
64
|
-
'-version',
|
|
65
|
-
version,
|
|
66
|
-
];
|
|
67
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from '@jest/globals';
|
|
2
|
-
import {
|
|
3
|
-
slugify,
|
|
4
|
-
shortSha,
|
|
5
|
-
parseVeracodeTargets,
|
|
6
|
-
buildZipFilename,
|
|
7
|
-
buildVersion,
|
|
8
|
-
buildUploadArgs,
|
|
9
|
-
} from './args.js';
|
|
10
|
-
|
|
11
|
-
describe('slugify', () => {
|
|
12
|
-
test('replaces every non [A-Za-z0-9._-] character with a dash', () => {
|
|
13
|
-
expect(slugify('my app!')).toBe('my-app-');
|
|
14
|
-
expect(slugify('my/app')).toBe('my-app');
|
|
15
|
-
expect(slugify('already-safe_v1.2')).toBe('already-safe_v1.2');
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('shortSha', () => {
|
|
20
|
-
test('truncates a commit sha to 7 characters', () => {
|
|
21
|
-
expect(shortSha('abcdef1234567')).toBe('abcdef1');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('defaults to "local" when no commit is given', () => {
|
|
25
|
-
expect(shortSha()).toBe('local');
|
|
26
|
-
expect(shortSha('')).toBe('local');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('parseVeracodeTargets', () => {
|
|
31
|
-
test('parses label:appname:path1,path2 entries', () => {
|
|
32
|
-
const targets = parseVeracodeTargets(
|
|
33
|
-
'frontend:my-app-fe:apps/fe,libs/shared;backend:my-app-be:apps/be',
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
expect(targets).toEqual([
|
|
37
|
-
{
|
|
38
|
-
label: 'frontend',
|
|
39
|
-
slug: 'frontend',
|
|
40
|
-
appname: 'my-app-fe',
|
|
41
|
-
paths: ['apps/fe', 'libs/shared'],
|
|
42
|
-
skipped: false,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
label: 'backend',
|
|
46
|
-
slug: 'backend',
|
|
47
|
-
appname: 'my-app-be',
|
|
48
|
-
paths: ['apps/be'],
|
|
49
|
-
skipped: false,
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('defaults an empty label to "app" and slugifies it', () => {
|
|
55
|
-
const [target] = parseVeracodeTargets(':my-app:src');
|
|
56
|
-
expect(target.label).toBe('app');
|
|
57
|
-
expect(target.slug).toBe('app');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('marks a target with no appname as skipped', () => {
|
|
61
|
-
const [target] = parseVeracodeTargets('web::src');
|
|
62
|
-
expect(target).toEqual({
|
|
63
|
-
label: 'web',
|
|
64
|
-
slug: 'web',
|
|
65
|
-
appname: '',
|
|
66
|
-
paths: ['src'],
|
|
67
|
-
skipped: true,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('marks a target with no paths as skipped', () => {
|
|
72
|
-
const [target] = parseVeracodeTargets('web:my-app:');
|
|
73
|
-
expect(target).toEqual({
|
|
74
|
-
label: 'web',
|
|
75
|
-
slug: 'web',
|
|
76
|
-
appname: 'my-app',
|
|
77
|
-
paths: [],
|
|
78
|
-
skipped: true,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('drops a 4th+ colon-delimited field rather than folding it into paths', () => {
|
|
83
|
-
const [target] = parseVeracodeTargets('web:my-app:src:extra');
|
|
84
|
-
expect(target.paths).toEqual(['src']);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('ignores blank entries between semicolons', () => {
|
|
88
|
-
expect(parseVeracodeTargets('web:my-app:src;;')).toHaveLength(1);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('empty string produces no targets', () => {
|
|
92
|
-
expect(parseVeracodeTargets('')).toEqual([]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('buildZipFilename', () => {
|
|
97
|
-
test('builds a "veracode-<slug>.zip" filename', () => {
|
|
98
|
-
expect(buildZipFilename('web')).toBe('veracode-web.zip');
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('buildVersion', () => {
|
|
103
|
-
test('builds "sha-<sha>-<label>", using the raw label rather than its slug', () => {
|
|
104
|
-
expect(buildVersion('abc1234', 'my app')).toBe('sha-abc1234-my app');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('buildUploadArgs', () => {
|
|
109
|
-
test('builds the Veracode wrapper CLI args', () => {
|
|
110
|
-
expect(
|
|
111
|
-
buildUploadArgs({
|
|
112
|
-
vid: 'vid-1',
|
|
113
|
-
vkey: 'vkey-1',
|
|
114
|
-
appname: 'my-app',
|
|
115
|
-
filepath: 'veracode-web.zip',
|
|
116
|
-
version: 'sha-abc1234-web',
|
|
117
|
-
}),
|
|
118
|
-
).toEqual([
|
|
119
|
-
'-vid',
|
|
120
|
-
'vid-1',
|
|
121
|
-
'-vkey',
|
|
122
|
-
'vkey-1',
|
|
123
|
-
'-action',
|
|
124
|
-
'uploadandscan',
|
|
125
|
-
'-appname',
|
|
126
|
-
'my-app',
|
|
127
|
-
'-createprofile',
|
|
128
|
-
'false',
|
|
129
|
-
'-autoscan',
|
|
130
|
-
'true',
|
|
131
|
-
'-filepath',
|
|
132
|
-
'veracode-web.zip',
|
|
133
|
-
'-version',
|
|
134
|
-
'sha-abc1234-web',
|
|
135
|
-
]);
|
|
136
|
-
});
|
|
137
|
-
});
|
package/src/veracode/cli.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { runVeracodeScan } from './scan.js';
|
|
5
|
-
|
|
6
|
-
const program = new Command();
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.command('scan')
|
|
10
|
-
.description('Upload and scan one or more app targets with Veracode')
|
|
11
|
-
.action(async () => {
|
|
12
|
-
const { exitCode } = await runVeracodeScan();
|
|
13
|
-
process.exit(exitCode);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
program.parse(process.argv);
|
package/src/veracode/fsops.js
DELETED
package/src/veracode/scan.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
-
buildUploadArgs,
|
|
4
|
-
buildVersion,
|
|
5
|
-
buildZipFilename,
|
|
6
|
-
parseVeracodeTargets,
|
|
7
|
-
shortSha as computeShortSha,
|
|
8
|
-
} from './args.js';
|
|
9
|
-
import { veracode as defaultVeracode } from './veracode.js';
|
|
10
|
-
import { fsOps as defaultFsOps } from './fsops.js';
|
|
11
|
-
|
|
12
|
-
export const DEFAULT_WRAPPER_JAR = 'veracode-wrapper/VeracodeJavaAPI.jar';
|
|
13
|
-
export const DEFAULT_WRAPPER_URL =
|
|
14
|
-
'https://repo1.maven.org/maven2/com/veracode/vosp/api/wrappers/vosp-api-wrappers-java/26.3.19.0/vosp-api-wrappers-java-26.3.19.0.jar';
|
|
15
|
-
|
|
16
|
-
// Zips one target's paths and submits them as their own uploadandscan call,
|
|
17
|
-
// so one repo with several apps (e.g. a frontend and a backend) gets separate
|
|
18
|
-
// Veracode profiles instead of one scan covering everything.
|
|
19
|
-
export async function scanOne(target, ctx) {
|
|
20
|
-
const { vid, vkey, shortSha, wrapperJar, veracode, fsops, log } = ctx;
|
|
21
|
-
const { label, appname, paths, slug, skipped } = target;
|
|
22
|
-
|
|
23
|
-
if (skipped) {
|
|
24
|
-
log(
|
|
25
|
-
`Target '${label}' is missing an appname or paths in VERACODE_TARGETS — skipping.`,
|
|
26
|
-
);
|
|
27
|
-
return { label, slug, exitCode: 1 };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const zipFile = buildZipFilename(slug);
|
|
31
|
-
fsops.removeSync(zipFile);
|
|
32
|
-
|
|
33
|
-
const zipped = await veracode.zip(zipFile, paths);
|
|
34
|
-
if (!zipped.ok) {
|
|
35
|
-
log(`Failed to zip paths for '${label}' — skipping its Veracode scan.`);
|
|
36
|
-
fsops.removeSync(zipFile);
|
|
37
|
-
return { label, slug, exitCode: 1 };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const version = buildVersion(shortSha, label);
|
|
41
|
-
const args = buildUploadArgs({
|
|
42
|
-
vid,
|
|
43
|
-
vkey,
|
|
44
|
-
appname,
|
|
45
|
-
filepath: zipFile,
|
|
46
|
-
version,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const uploaded = await veracode.uploadAndScan(wrapperJar, args);
|
|
50
|
-
fsops.removeSync(zipFile);
|
|
51
|
-
|
|
52
|
-
if (!uploaded.ok) {
|
|
53
|
-
log(`ERROR: Veracode scan submission failed for '${label}'.`);
|
|
54
|
-
return { label, slug, exitCode: 1 };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return { label, slug, exitCode: 0 };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export async function runVeracodeScan({
|
|
61
|
-
vid = process.env.VERACODE_API_ID || '',
|
|
62
|
-
vkey = process.env.VERACODE_API_KEY || '',
|
|
63
|
-
targetsEnv = process.env.VERACODE_TARGETS || '',
|
|
64
|
-
buildCmd = process.env.VERACODE_BUILD_CMD || '',
|
|
65
|
-
commit = process.env.BITBUCKET_COMMIT || 'local',
|
|
66
|
-
wrapperJar = process.env.VERACODE_WRAPPER_JAR || DEFAULT_WRAPPER_JAR,
|
|
67
|
-
wrapperUrl = process.env.VERACODE_WRAPPER_URL || DEFAULT_WRAPPER_URL,
|
|
68
|
-
veracode = defaultVeracode,
|
|
69
|
-
fsops = defaultFsOps,
|
|
70
|
-
log = console.log,
|
|
71
|
-
} = {}) {
|
|
72
|
-
if (!vid || !vkey) {
|
|
73
|
-
log(
|
|
74
|
-
'ERROR: VERACODE_API_ID / VERACODE_API_KEY not set — cannot run Veracode scan.',
|
|
75
|
-
);
|
|
76
|
-
return { exitCode: 1, results: [] };
|
|
77
|
-
}
|
|
78
|
-
if (!targetsEnv) {
|
|
79
|
-
log('ERROR: VERACODE_TARGETS not set — cannot run Veracode scan.');
|
|
80
|
-
log(
|
|
81
|
-
' Expected: label:appname:path1,path2,...[;label2:appname2:path1,...]',
|
|
82
|
-
);
|
|
83
|
-
return { exitCode: 1, results: [] };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// VERACODE_BUILD_CMD lets a consumer produce whatever build artifacts
|
|
87
|
-
// Veracode's SAST needs (compiled bundles, etc.) without a separate
|
|
88
|
-
// pre-build step in the consumer's own pipeline. Its exit code isn't
|
|
89
|
-
// gated on here, matching the pipeline step it's ported from — a failure
|
|
90
|
-
// will simply surface as a failed upload for every target below.
|
|
91
|
-
if (buildCmd) {
|
|
92
|
-
log('Running VERACODE_BUILD_CMD...');
|
|
93
|
-
await veracode.runBuildCmd(buildCmd);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Cached across builds on self-hosted runners; downloaded once.
|
|
97
|
-
if (!fsops.exists(wrapperJar)) {
|
|
98
|
-
fsops.mkdirp(path.dirname(wrapperJar));
|
|
99
|
-
await veracode.download(wrapperUrl, wrapperJar);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const sha = computeShortSha(commit);
|
|
103
|
-
const results = [];
|
|
104
|
-
for (const target of parseVeracodeTargets(targetsEnv)) {
|
|
105
|
-
results.push(
|
|
106
|
-
await scanOne(target, {
|
|
107
|
-
vid,
|
|
108
|
-
vkey,
|
|
109
|
-
shortSha: sha,
|
|
110
|
-
wrapperJar,
|
|
111
|
-
veracode,
|
|
112
|
-
fsops,
|
|
113
|
-
log,
|
|
114
|
-
}),
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const exitCode = results.some((r) => r.exitCode !== 0) ? 1 : 0;
|
|
119
|
-
return { exitCode, results };
|
|
120
|
-
}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { describe, expect, jest, test } from '@jest/globals';
|
|
2
|
-
import { scanOne, runVeracodeScan, DEFAULT_WRAPPER_JAR } from './scan.js';
|
|
3
|
-
|
|
4
|
-
function makeFakeVeracode(overrides = {}) {
|
|
5
|
-
return {
|
|
6
|
-
download: jest.fn().mockResolvedValue({ ok: true }),
|
|
7
|
-
runBuildCmd: jest.fn().mockResolvedValue({ ok: true }),
|
|
8
|
-
zip: jest.fn().mockResolvedValue({ ok: true }),
|
|
9
|
-
uploadAndScan: jest.fn().mockResolvedValue({ ok: true }),
|
|
10
|
-
...overrides,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function makeFakeFsops(overrides = {}) {
|
|
15
|
-
return {
|
|
16
|
-
exists: jest.fn().mockReturnValue(true),
|
|
17
|
-
mkdirp: jest.fn(),
|
|
18
|
-
removeSync: jest.fn(),
|
|
19
|
-
...overrides,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const baseCtx = (overrides = {}) => ({
|
|
24
|
-
vid: 'vid-1',
|
|
25
|
-
vkey: 'vkey-1',
|
|
26
|
-
shortSha: 'abc1234',
|
|
27
|
-
wrapperJar: DEFAULT_WRAPPER_JAR,
|
|
28
|
-
veracode: makeFakeVeracode(),
|
|
29
|
-
fsops: makeFakeFsops(),
|
|
30
|
-
log: jest.fn(),
|
|
31
|
-
...overrides,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('scanOne', () => {
|
|
35
|
-
test('zips, uploads and cleans up a normal target', async () => {
|
|
36
|
-
const veracode = makeFakeVeracode();
|
|
37
|
-
const fsops = makeFakeFsops();
|
|
38
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
39
|
-
|
|
40
|
-
const result = await scanOne(
|
|
41
|
-
{
|
|
42
|
-
label: 'web',
|
|
43
|
-
slug: 'web',
|
|
44
|
-
appname: 'my-app',
|
|
45
|
-
paths: ['services/web'],
|
|
46
|
-
skipped: false,
|
|
47
|
-
},
|
|
48
|
-
ctx,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 0 });
|
|
52
|
-
expect(veracode.zip).toHaveBeenCalledWith('veracode-web.zip', [
|
|
53
|
-
'services/web',
|
|
54
|
-
]);
|
|
55
|
-
expect(veracode.uploadAndScan).toHaveBeenCalledWith(
|
|
56
|
-
DEFAULT_WRAPPER_JAR,
|
|
57
|
-
expect.arrayContaining([
|
|
58
|
-
'-appname',
|
|
59
|
-
'my-app',
|
|
60
|
-
'-version',
|
|
61
|
-
'sha-abc1234-web',
|
|
62
|
-
]),
|
|
63
|
-
);
|
|
64
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('skips a target missing an appname or paths', async () => {
|
|
68
|
-
const veracode = makeFakeVeracode();
|
|
69
|
-
const ctx = baseCtx({ veracode });
|
|
70
|
-
|
|
71
|
-
const result = await scanOne(
|
|
72
|
-
{ label: 'web', slug: 'web', appname: '', paths: [], skipped: true },
|
|
73
|
-
ctx,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
77
|
-
expect(veracode.zip).not.toHaveBeenCalled();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('returns exitCode 1 and skips upload when zipping fails', async () => {
|
|
81
|
-
const veracode = makeFakeVeracode({
|
|
82
|
-
zip: jest.fn().mockResolvedValue({ ok: false }),
|
|
83
|
-
});
|
|
84
|
-
const fsops = makeFakeFsops();
|
|
85
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
86
|
-
|
|
87
|
-
const result = await scanOne(
|
|
88
|
-
{
|
|
89
|
-
label: 'web',
|
|
90
|
-
slug: 'web',
|
|
91
|
-
appname: 'my-app',
|
|
92
|
-
paths: ['services/web'],
|
|
93
|
-
skipped: false,
|
|
94
|
-
},
|
|
95
|
-
ctx,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
99
|
-
expect(veracode.uploadAndScan).not.toHaveBeenCalled();
|
|
100
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test('returns exitCode 1 when the upload fails, but still cleans up the zip', async () => {
|
|
104
|
-
const veracode = makeFakeVeracode({
|
|
105
|
-
uploadAndScan: jest.fn().mockResolvedValue({ ok: false }),
|
|
106
|
-
});
|
|
107
|
-
const fsops = makeFakeFsops();
|
|
108
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
109
|
-
|
|
110
|
-
const result = await scanOne(
|
|
111
|
-
{
|
|
112
|
-
label: 'web',
|
|
113
|
-
slug: 'web',
|
|
114
|
-
appname: 'my-app',
|
|
115
|
-
paths: ['services/web'],
|
|
116
|
-
skipped: false,
|
|
117
|
-
},
|
|
118
|
-
ctx,
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
122
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
describe('runVeracodeScan', () => {
|
|
127
|
-
test('fails fast when credentials are missing', async () => {
|
|
128
|
-
const log = jest.fn();
|
|
129
|
-
const result = await runVeracodeScan({
|
|
130
|
-
vid: '',
|
|
131
|
-
vkey: '',
|
|
132
|
-
targetsEnv: 'web:my-app:src',
|
|
133
|
-
log,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
expect(result).toEqual({ exitCode: 1, results: [] });
|
|
137
|
-
expect(log).toHaveBeenCalledWith(
|
|
138
|
-
expect.stringContaining('VERACODE_API_ID / VERACODE_API_KEY not set'),
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('fails fast when VERACODE_TARGETS is missing', async () => {
|
|
143
|
-
const log = jest.fn();
|
|
144
|
-
const result = await runVeracodeScan({
|
|
145
|
-
vid: 'vid-1',
|
|
146
|
-
vkey: 'vkey-1',
|
|
147
|
-
targetsEnv: '',
|
|
148
|
-
log,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect(result).toEqual({ exitCode: 1, results: [] });
|
|
152
|
-
expect(log).toHaveBeenCalledWith(
|
|
153
|
-
expect.stringContaining('VERACODE_TARGETS not set'),
|
|
154
|
-
);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('runs VERACODE_BUILD_CMD before packaging when set', async () => {
|
|
158
|
-
const veracode = makeFakeVeracode();
|
|
159
|
-
const fsops = makeFakeFsops();
|
|
160
|
-
|
|
161
|
-
await runVeracodeScan({
|
|
162
|
-
vid: 'vid-1',
|
|
163
|
-
vkey: 'vkey-1',
|
|
164
|
-
targetsEnv: 'web:my-app:src',
|
|
165
|
-
buildCmd: 'npm run build',
|
|
166
|
-
veracode,
|
|
167
|
-
fsops,
|
|
168
|
-
log: jest.fn(),
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(veracode.runBuildCmd).toHaveBeenCalledWith('npm run build');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('downloads the wrapper jar only when not already cached', async () => {
|
|
175
|
-
const veracode = makeFakeVeracode();
|
|
176
|
-
const fsops = makeFakeFsops({ exists: jest.fn().mockReturnValue(false) });
|
|
177
|
-
|
|
178
|
-
await runVeracodeScan({
|
|
179
|
-
vid: 'vid-1',
|
|
180
|
-
vkey: 'vkey-1',
|
|
181
|
-
targetsEnv: 'web:my-app:src',
|
|
182
|
-
veracode,
|
|
183
|
-
fsops,
|
|
184
|
-
log: jest.fn(),
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(veracode.download).toHaveBeenCalledWith(
|
|
188
|
-
expect.stringContaining('vosp-api-wrappers-java'),
|
|
189
|
-
DEFAULT_WRAPPER_JAR,
|
|
190
|
-
);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test('skips the download when the wrapper jar already exists', async () => {
|
|
194
|
-
const veracode = makeFakeVeracode();
|
|
195
|
-
const fsops = makeFakeFsops({ exists: jest.fn().mockReturnValue(true) });
|
|
196
|
-
|
|
197
|
-
await runVeracodeScan({
|
|
198
|
-
vid: 'vid-1',
|
|
199
|
-
vkey: 'vkey-1',
|
|
200
|
-
targetsEnv: 'web:my-app:src',
|
|
201
|
-
veracode,
|
|
202
|
-
fsops,
|
|
203
|
-
log: jest.fn(),
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
expect(veracode.download).not.toHaveBeenCalled();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test('scans every target and reports the worst outcome', async () => {
|
|
210
|
-
const veracode = makeFakeVeracode({
|
|
211
|
-
uploadAndScan: jest
|
|
212
|
-
.fn()
|
|
213
|
-
.mockResolvedValueOnce({ ok: true })
|
|
214
|
-
.mockResolvedValueOnce({ ok: false }),
|
|
215
|
-
});
|
|
216
|
-
const fsops = makeFakeFsops();
|
|
217
|
-
|
|
218
|
-
const result = await runVeracodeScan({
|
|
219
|
-
vid: 'vid-1',
|
|
220
|
-
vkey: 'vkey-1',
|
|
221
|
-
targetsEnv: 'web:my-app:apps/web;worker:my-worker:apps/worker',
|
|
222
|
-
veracode,
|
|
223
|
-
fsops,
|
|
224
|
-
log: jest.fn(),
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
expect(result.results.map((r) => r.label)).toEqual(['web', 'worker']);
|
|
228
|
-
expect(result.exitCode).toBe(1);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('exits 0 when every target scans successfully', async () => {
|
|
232
|
-
const veracode = makeFakeVeracode();
|
|
233
|
-
const fsops = makeFakeFsops();
|
|
234
|
-
|
|
235
|
-
const result = await runVeracodeScan({
|
|
236
|
-
vid: 'vid-1',
|
|
237
|
-
vkey: 'vkey-1',
|
|
238
|
-
targetsEnv: 'web:my-app:apps/web',
|
|
239
|
-
veracode,
|
|
240
|
-
fsops,
|
|
241
|
-
log: jest.fn(),
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
expect(result.exitCode).toBe(0);
|
|
245
|
-
});
|
|
246
|
-
});
|
package/src/veracode/veracode.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
|
|
3
|
-
// Thin wrappers around the external commands the Veracode step shells out to,
|
|
4
|
-
// so scan.js can inject a fake in tests. Every call uses nothrow: a non-zero
|
|
5
|
-
// exit is meaningful data here (a failed build/zip/upload), not an
|
|
6
|
-
// exceptional case.
|
|
7
|
-
export const veracode = {
|
|
8
|
-
async download(url, dest) {
|
|
9
|
-
const result = await $({
|
|
10
|
-
nothrow: true,
|
|
11
|
-
quiet: true,
|
|
12
|
-
})`curl -sSL ${url} -o ${dest}`;
|
|
13
|
-
return { ok: result.exitCode === 0 };
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
// Runs the consumer-supplied VERACODE_BUILD_CMD via `sh -c` so its own
|
|
17
|
-
// shell operators (&&, |, ...) are honored, mirroring the pipeline's
|
|
18
|
-
// `eval "${VERACODE_BUILD_CMD}"`.
|
|
19
|
-
async runBuildCmd(cmd) {
|
|
20
|
-
const result = await $({ nothrow: true })`sh -c ${cmd}`;
|
|
21
|
-
return { ok: result.exitCode === 0 };
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
async zip(zipFile, paths) {
|
|
25
|
-
const result = await $({ nothrow: true })`zip -r ${zipFile} ${paths}`;
|
|
26
|
-
return { ok: result.exitCode === 0 };
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
async uploadAndScan(jarPath, args) {
|
|
30
|
-
const result = await $({ nothrow: true })`java -jar ${jarPath} ${args}`;
|
|
31
|
-
return { ok: result.exitCode === 0 };
|
|
32
|
-
},
|
|
33
|
-
};
|
package/src/xray/cli.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { notify } from './notify.js';
|
|
5
|
-
|
|
6
|
-
const program = new Command();
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.command('notify')
|
|
10
|
-
.description(
|
|
11
|
-
'Post Xray findings to Slack (parent summary + one thread reply per finding)',
|
|
12
|
-
)
|
|
13
|
-
.option(
|
|
14
|
-
'-f, --report-args-file <path>',
|
|
15
|
-
'Path to the "label:file" report-args file',
|
|
16
|
-
)
|
|
17
|
-
.option(
|
|
18
|
-
'-m, --min-severity <severity>',
|
|
19
|
-
'Lowest severity to thread (Critical|High|Medium|Low)',
|
|
20
|
-
)
|
|
21
|
-
.option('-c, --notify-clean', 'Post even when there are zero findings')
|
|
22
|
-
.action(async (options) => {
|
|
23
|
-
try {
|
|
24
|
-
await notify({
|
|
25
|
-
...(options.reportArgsFile && {
|
|
26
|
-
reportArgsFile: options.reportArgsFile,
|
|
27
|
-
}),
|
|
28
|
-
...(options.minSeverity && { minSeverity: options.minSeverity }),
|
|
29
|
-
...(options.notifyClean && { notifyClean: true }),
|
|
30
|
-
});
|
|
31
|
-
} catch (error) {
|
|
32
|
-
console.error(error.message);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
program.parse(process.argv);
|