@docupace/pipeline 1.0.123-xray.3 → 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 -147
- package/src/veracode/scan.test.js +0 -293
- package/src/veracode/veracode.js +0 -45
- 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,147 +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
|
-
// Commands the step shells out to on the host, rather than inside a container.
|
|
61
|
-
export const REQUIRED_COMMANDS = ['java', 'zip'];
|
|
62
|
-
|
|
63
|
-
export async function runVeracodeScan({
|
|
64
|
-
vid = process.env.VERACODE_API_ID || '',
|
|
65
|
-
vkey = process.env.VERACODE_API_KEY || '',
|
|
66
|
-
targetsEnv = process.env.VERACODE_TARGETS || '',
|
|
67
|
-
requireCredentials = process.env.VERACODE_REQUIRE_CREDENTIALS === 'true',
|
|
68
|
-
buildCmd = process.env.VERACODE_BUILD_CMD || '',
|
|
69
|
-
commit = process.env.BITBUCKET_COMMIT || 'local',
|
|
70
|
-
wrapperJar = process.env.VERACODE_WRAPPER_JAR || DEFAULT_WRAPPER_JAR,
|
|
71
|
-
wrapperUrl = process.env.VERACODE_WRAPPER_URL || DEFAULT_WRAPPER_URL,
|
|
72
|
-
veracode = defaultVeracode,
|
|
73
|
-
fsops = defaultFsOps,
|
|
74
|
-
log = console.log,
|
|
75
|
-
} = {}) {
|
|
76
|
-
// Absent credentials mean the repo or runner was never set up for Veracode,
|
|
77
|
-
// which is not the same thing as a broken configuration: skip, the way the
|
|
78
|
-
// Tenable step does, so a consumer can add the step before the credentials
|
|
79
|
-
// exist. VERACODE_REQUIRE_CREDENTIALS=true turns it back into a hard failure
|
|
80
|
-
// once a repo expects the scan to run on every build.
|
|
81
|
-
if (!vid || !vkey) {
|
|
82
|
-
if (requireCredentials) {
|
|
83
|
-
log(
|
|
84
|
-
'ERROR: VERACODE_API_ID / VERACODE_API_KEY not set and VERACODE_REQUIRE_CREDENTIALS=true — failing.',
|
|
85
|
-
);
|
|
86
|
-
return { exitCode: 1, skipped: false, results: [] };
|
|
87
|
-
}
|
|
88
|
-
log(
|
|
89
|
-
'VERACODE_API_ID / VERACODE_API_KEY not set — skipping Veracode scan.',
|
|
90
|
-
);
|
|
91
|
-
return { exitCode: 0, skipped: true, results: [] };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Credentials present but no targets is a broken configuration, so this stays
|
|
95
|
-
// a hard failure however the credentials were supplied.
|
|
96
|
-
if (!targetsEnv) {
|
|
97
|
-
log('ERROR: VERACODE_TARGETS not set — cannot run Veracode scan.');
|
|
98
|
-
log(
|
|
99
|
-
' Expected: label:appname:path1,path2,...[;label2:appname2:path1,...]',
|
|
100
|
-
);
|
|
101
|
-
return { exitCode: 1, skipped: false, results: [] };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
for (const cmd of REQUIRED_COMMANDS) {
|
|
105
|
-
if (!(await veracode.commandExists(cmd))) {
|
|
106
|
-
log(
|
|
107
|
-
`ERROR: ${cmd} is not on PATH — the Veracode step packages and uploads with it.`,
|
|
108
|
-
);
|
|
109
|
-
return { exitCode: 1, skipped: false, results: [] };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// VERACODE_BUILD_CMD lets a consumer produce whatever build artifacts
|
|
114
|
-
// Veracode's SAST needs (compiled bundles, etc.) without a separate
|
|
115
|
-
// pre-build step in the consumer's own pipeline. Its exit code isn't
|
|
116
|
-
// gated on here, matching the pipeline step it's ported from — a failure
|
|
117
|
-
// will simply surface as a failed upload for every target below.
|
|
118
|
-
if (buildCmd) {
|
|
119
|
-
log('Running VERACODE_BUILD_CMD...');
|
|
120
|
-
await veracode.runBuildCmd(buildCmd);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Cached across builds on self-hosted runners; downloaded once.
|
|
124
|
-
if (!fsops.exists(wrapperJar)) {
|
|
125
|
-
fsops.mkdirp(path.dirname(wrapperJar));
|
|
126
|
-
await veracode.download(wrapperUrl, wrapperJar);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const sha = computeShortSha(commit);
|
|
130
|
-
const results = [];
|
|
131
|
-
for (const target of parseVeracodeTargets(targetsEnv)) {
|
|
132
|
-
results.push(
|
|
133
|
-
await scanOne(target, {
|
|
134
|
-
vid,
|
|
135
|
-
vkey,
|
|
136
|
-
shortSha: sha,
|
|
137
|
-
wrapperJar,
|
|
138
|
-
veracode,
|
|
139
|
-
fsops,
|
|
140
|
-
log,
|
|
141
|
-
}),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const exitCode = results.some((r) => r.exitCode !== 0) ? 1 : 0;
|
|
146
|
-
return { exitCode, skipped: false, results };
|
|
147
|
-
}
|
|
@@ -1,293 +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
|
-
commandExists: jest.fn().mockResolvedValue(true),
|
|
7
|
-
download: jest.fn().mockResolvedValue({ ok: true }),
|
|
8
|
-
runBuildCmd: jest.fn().mockResolvedValue({ ok: true }),
|
|
9
|
-
zip: jest.fn().mockResolvedValue({ ok: true }),
|
|
10
|
-
uploadAndScan: jest.fn().mockResolvedValue({ ok: true }),
|
|
11
|
-
...overrides,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function makeFakeFsops(overrides = {}) {
|
|
16
|
-
return {
|
|
17
|
-
exists: jest.fn().mockReturnValue(true),
|
|
18
|
-
mkdirp: jest.fn(),
|
|
19
|
-
removeSync: jest.fn(),
|
|
20
|
-
...overrides,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const baseCtx = (overrides = {}) => ({
|
|
25
|
-
vid: 'vid-1',
|
|
26
|
-
vkey: 'vkey-1',
|
|
27
|
-
shortSha: 'abc1234',
|
|
28
|
-
wrapperJar: DEFAULT_WRAPPER_JAR,
|
|
29
|
-
veracode: makeFakeVeracode(),
|
|
30
|
-
fsops: makeFakeFsops(),
|
|
31
|
-
log: jest.fn(),
|
|
32
|
-
...overrides,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('scanOne', () => {
|
|
36
|
-
test('zips, uploads and cleans up a normal target', async () => {
|
|
37
|
-
const veracode = makeFakeVeracode();
|
|
38
|
-
const fsops = makeFakeFsops();
|
|
39
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
40
|
-
|
|
41
|
-
const result = await scanOne(
|
|
42
|
-
{
|
|
43
|
-
label: 'web',
|
|
44
|
-
slug: 'web',
|
|
45
|
-
appname: 'my-app',
|
|
46
|
-
paths: ['services/web'],
|
|
47
|
-
skipped: false,
|
|
48
|
-
},
|
|
49
|
-
ctx,
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 0 });
|
|
53
|
-
expect(veracode.zip).toHaveBeenCalledWith('veracode-web.zip', [
|
|
54
|
-
'services/web',
|
|
55
|
-
]);
|
|
56
|
-
expect(veracode.uploadAndScan).toHaveBeenCalledWith(
|
|
57
|
-
DEFAULT_WRAPPER_JAR,
|
|
58
|
-
expect.arrayContaining([
|
|
59
|
-
'-appname',
|
|
60
|
-
'my-app',
|
|
61
|
-
'-version',
|
|
62
|
-
'sha-abc1234-web',
|
|
63
|
-
]),
|
|
64
|
-
);
|
|
65
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('skips a target missing an appname or paths', async () => {
|
|
69
|
-
const veracode = makeFakeVeracode();
|
|
70
|
-
const ctx = baseCtx({ veracode });
|
|
71
|
-
|
|
72
|
-
const result = await scanOne(
|
|
73
|
-
{ label: 'web', slug: 'web', appname: '', paths: [], skipped: true },
|
|
74
|
-
ctx,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
78
|
-
expect(veracode.zip).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('returns exitCode 1 and skips upload when zipping fails', async () => {
|
|
82
|
-
const veracode = makeFakeVeracode({
|
|
83
|
-
zip: jest.fn().mockResolvedValue({ ok: false }),
|
|
84
|
-
});
|
|
85
|
-
const fsops = makeFakeFsops();
|
|
86
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
87
|
-
|
|
88
|
-
const result = await scanOne(
|
|
89
|
-
{
|
|
90
|
-
label: 'web',
|
|
91
|
-
slug: 'web',
|
|
92
|
-
appname: 'my-app',
|
|
93
|
-
paths: ['services/web'],
|
|
94
|
-
skipped: false,
|
|
95
|
-
},
|
|
96
|
-
ctx,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
100
|
-
expect(veracode.uploadAndScan).not.toHaveBeenCalled();
|
|
101
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('returns exitCode 1 when the upload fails, but still cleans up the zip', async () => {
|
|
105
|
-
const veracode = makeFakeVeracode({
|
|
106
|
-
uploadAndScan: jest.fn().mockResolvedValue({ ok: false }),
|
|
107
|
-
});
|
|
108
|
-
const fsops = makeFakeFsops();
|
|
109
|
-
const ctx = baseCtx({ veracode, fsops });
|
|
110
|
-
|
|
111
|
-
const result = await scanOne(
|
|
112
|
-
{
|
|
113
|
-
label: 'web',
|
|
114
|
-
slug: 'web',
|
|
115
|
-
appname: 'my-app',
|
|
116
|
-
paths: ['services/web'],
|
|
117
|
-
skipped: false,
|
|
118
|
-
},
|
|
119
|
-
ctx,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
expect(result).toEqual({ label: 'web', slug: 'web', exitCode: 1 });
|
|
123
|
-
expect(fsops.removeSync).toHaveBeenCalledWith('veracode-web.zip');
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe('runVeracodeScan', () => {
|
|
128
|
-
test('skips without failing when credentials are missing', async () => {
|
|
129
|
-
const log = jest.fn();
|
|
130
|
-
const veracode = makeFakeVeracode();
|
|
131
|
-
const result = await runVeracodeScan({
|
|
132
|
-
vid: '',
|
|
133
|
-
vkey: '',
|
|
134
|
-
targetsEnv: 'web:my-app:src',
|
|
135
|
-
veracode,
|
|
136
|
-
log,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
expect(result).toEqual({ exitCode: 0, skipped: true, results: [] });
|
|
140
|
-
expect(veracode.zip).not.toHaveBeenCalled();
|
|
141
|
-
expect(log).toHaveBeenCalledWith(
|
|
142
|
-
expect.stringContaining('VERACODE_API_ID / VERACODE_API_KEY not set'),
|
|
143
|
-
);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('fails on missing credentials when VERACODE_REQUIRE_CREDENTIALS is set', async () => {
|
|
147
|
-
const log = jest.fn();
|
|
148
|
-
const result = await runVeracodeScan({
|
|
149
|
-
vid: '',
|
|
150
|
-
vkey: '',
|
|
151
|
-
targetsEnv: 'web:my-app:src',
|
|
152
|
-
requireCredentials: true,
|
|
153
|
-
veracode: makeFakeVeracode(),
|
|
154
|
-
log,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
expect(result).toEqual({ exitCode: 1, skipped: false, results: [] });
|
|
158
|
-
expect(log).toHaveBeenCalledWith(
|
|
159
|
-
expect.stringContaining('VERACODE_REQUIRE_CREDENTIALS=true'),
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('fails fast when VERACODE_TARGETS is missing', async () => {
|
|
164
|
-
const log = jest.fn();
|
|
165
|
-
const result = await runVeracodeScan({
|
|
166
|
-
vid: 'vid-1',
|
|
167
|
-
vkey: 'vkey-1',
|
|
168
|
-
targetsEnv: '',
|
|
169
|
-
veracode: makeFakeVeracode(),
|
|
170
|
-
log,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
expect(result).toEqual({ exitCode: 1, skipped: false, results: [] });
|
|
174
|
-
expect(log).toHaveBeenCalledWith(
|
|
175
|
-
expect.stringContaining('VERACODE_TARGETS not set'),
|
|
176
|
-
);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test.each(['java', 'zip'])(
|
|
180
|
-
'fails before packaging when %s is not on PATH',
|
|
181
|
-
async (missing) => {
|
|
182
|
-
const log = jest.fn();
|
|
183
|
-
const veracode = makeFakeVeracode({
|
|
184
|
-
commandExists: jest.fn(async (cmd) => cmd !== missing),
|
|
185
|
-
});
|
|
186
|
-
const result = await runVeracodeScan({
|
|
187
|
-
vid: 'vid-1',
|
|
188
|
-
vkey: 'vkey-1',
|
|
189
|
-
targetsEnv: 'web:my-app:src',
|
|
190
|
-
veracode,
|
|
191
|
-
fsops: makeFakeFsops(),
|
|
192
|
-
log,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
expect(result).toEqual({ exitCode: 1, skipped: false, results: [] });
|
|
196
|
-
expect(veracode.zip).not.toHaveBeenCalled();
|
|
197
|
-
expect(veracode.download).not.toHaveBeenCalled();
|
|
198
|
-
expect(log).toHaveBeenCalledWith(
|
|
199
|
-
expect.stringContaining(`${missing} is not on PATH`),
|
|
200
|
-
);
|
|
201
|
-
},
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
test('runs VERACODE_BUILD_CMD before packaging when set', async () => {
|
|
205
|
-
const veracode = makeFakeVeracode();
|
|
206
|
-
const fsops = makeFakeFsops();
|
|
207
|
-
|
|
208
|
-
await runVeracodeScan({
|
|
209
|
-
vid: 'vid-1',
|
|
210
|
-
vkey: 'vkey-1',
|
|
211
|
-
targetsEnv: 'web:my-app:src',
|
|
212
|
-
buildCmd: 'npm run build',
|
|
213
|
-
veracode,
|
|
214
|
-
fsops,
|
|
215
|
-
log: jest.fn(),
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(veracode.runBuildCmd).toHaveBeenCalledWith('npm run build');
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('downloads the wrapper jar only when not already cached', async () => {
|
|
222
|
-
const veracode = makeFakeVeracode();
|
|
223
|
-
const fsops = makeFakeFsops({ exists: jest.fn().mockReturnValue(false) });
|
|
224
|
-
|
|
225
|
-
await runVeracodeScan({
|
|
226
|
-
vid: 'vid-1',
|
|
227
|
-
vkey: 'vkey-1',
|
|
228
|
-
targetsEnv: 'web:my-app:src',
|
|
229
|
-
veracode,
|
|
230
|
-
fsops,
|
|
231
|
-
log: jest.fn(),
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
expect(veracode.download).toHaveBeenCalledWith(
|
|
235
|
-
expect.stringContaining('vosp-api-wrappers-java'),
|
|
236
|
-
DEFAULT_WRAPPER_JAR,
|
|
237
|
-
);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
test('skips the download when the wrapper jar already exists', async () => {
|
|
241
|
-
const veracode = makeFakeVeracode();
|
|
242
|
-
const fsops = makeFakeFsops({ exists: jest.fn().mockReturnValue(true) });
|
|
243
|
-
|
|
244
|
-
await runVeracodeScan({
|
|
245
|
-
vid: 'vid-1',
|
|
246
|
-
vkey: 'vkey-1',
|
|
247
|
-
targetsEnv: 'web:my-app:src',
|
|
248
|
-
veracode,
|
|
249
|
-
fsops,
|
|
250
|
-
log: jest.fn(),
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expect(veracode.download).not.toHaveBeenCalled();
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test('scans every target and reports the worst outcome', async () => {
|
|
257
|
-
const veracode = makeFakeVeracode({
|
|
258
|
-
uploadAndScan: jest
|
|
259
|
-
.fn()
|
|
260
|
-
.mockResolvedValueOnce({ ok: true })
|
|
261
|
-
.mockResolvedValueOnce({ ok: false }),
|
|
262
|
-
});
|
|
263
|
-
const fsops = makeFakeFsops();
|
|
264
|
-
|
|
265
|
-
const result = await runVeracodeScan({
|
|
266
|
-
vid: 'vid-1',
|
|
267
|
-
vkey: 'vkey-1',
|
|
268
|
-
targetsEnv: 'web:my-app:apps/web;worker:my-worker:apps/worker',
|
|
269
|
-
veracode,
|
|
270
|
-
fsops,
|
|
271
|
-
log: jest.fn(),
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
expect(result.results.map((r) => r.label)).toEqual(['web', 'worker']);
|
|
275
|
-
expect(result.exitCode).toBe(1);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
test('exits 0 when every target scans successfully', async () => {
|
|
279
|
-
const veracode = makeFakeVeracode();
|
|
280
|
-
const fsops = makeFakeFsops();
|
|
281
|
-
|
|
282
|
-
const result = await runVeracodeScan({
|
|
283
|
-
vid: 'vid-1',
|
|
284
|
-
vkey: 'vkey-1',
|
|
285
|
-
targetsEnv: 'web:my-app:apps/web',
|
|
286
|
-
veracode,
|
|
287
|
-
fsops,
|
|
288
|
-
log: jest.fn(),
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
expect(result.exitCode).toBe(0);
|
|
292
|
-
});
|
|
293
|
-
});
|