-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·59 lines (49 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
import xmlbuilder2 from 'xmlbuilder2'
import {format} from "util";
import {parse} from '@jsonlines/core';
import {EOL} from 'os';
let testsuite = xmlbuilder2.create()
.ele('testsuite', {
package: '',
errors: 0,
failures: 0,
tests: 0
}
);
const jsonLinesParser = parse();
process.stdin.pipe(jsonLinesParser);
jsonLinesParser.on('data', (line) => {
if (line.type === "auditSummary") {
const vulns = line.data.vulnerabilities;
testsuite
.att('failures', vulns.info + vulns.low + vulns.moderate + vulns.high + vulns.critical)
.att('tests', line.data.totalDependencies);
return;
}
if (line.type !== "auditAdvisory") {
return;
}
let testcase = testsuite
.ele('testcase', {
name: format(
'%s (%s - %s)',
line.data.advisory.module_name,
line.data.advisory.vulnerable_versions,
line.data.advisory.severity
),
classname: 'packages'
});
let failure = testcase.ele('failure');
failure.txt(
format(
'%s - %s (%s)',
line.data.advisory.cves.join(' '),
line.data.advisory.title,
line.data.advisory.url
)
);
});
jsonLinesParser.on('end', () => {
process.stdout.write(testsuite.up().end({prettyPrint: true}) + EOL)
});