Skip to content

Commit 4b86151

Browse files
authored
Merge pull request #170 from snyk/dotkas/SUP-2192/add-target-file-to-nuget-results
feat: [SUP-2192] Adding manifest file to vuln card if scanning multi-project
2 parents 6a578dc + ce935fb commit 4b86151

File tree

7 files changed

+1518
-11
lines changed

7 files changed

+1518
-11
lines changed

src/lib/snyk-to-html.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,34 @@ async function generateCodeTemplate(
256256
}
257257

258258
function mergeData(dataArray: any[]): any {
259-
const vulnsArrays = dataArray.map(project => project.vulnerabilities || []);
259+
const vulnsArrays = dataArray.map((project) => {
260+
if (!project.vulnerabilities) {
261+
return [];
262+
}
263+
264+
// Add project data to each of the vulnerabilities to display more
265+
// details on each vulnerability card, in order to properly distinguish
266+
// from which project a vuln is connected, in case of displaying multiple
267+
// projects.
268+
const vulns = project.vulnerabilities.map((vuln) => ({
269+
...vuln,
270+
displayTargetFile: project.displayTargetFile,
271+
path: project.path
272+
}));
273+
return vulns;
274+
});
260275
const aggregateVulnerabilities = [].concat(...vulnsArrays);
261276

262277
const totalUniqueCount =
263278
dataArray.reduce((acc, item) => acc + item.vulnerabilities.length || 0, 0);
264279
const totalDepCount =
265280
dataArray.reduce((acc, item) => acc + item.dependencyCount || 0, 0);
266281

267-
const paths = dataArray.map(project => ({ path: project.path, packageManager: project.packageManager }));
282+
const paths = dataArray.map(project => ({
283+
path: project.path,
284+
packageManager: project.packageManager,
285+
displayTargetFile: project.displayTargetFile,
286+
}));
268287

269288
return {
270289
vulnerabilities: aggregateVulnerabilities,
@@ -325,7 +344,7 @@ async function processCodeData(
325344
const dataArray = Array.isArray(data) ? data : [data];
326345

327346
const OrderedIssuesArray = await processSourceCode(dataArray);
328-
347+
329348
const totalIssues = dataArray[0].runs[0].results.length;
330349
const processedData = {
331350
projects: OrderedIssuesArray,

tap-snapshots/test-snyk-to-html.test.ts-TAP.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,8 @@ exports[`test/snyk-to-html.test.ts TAP template output displays vulns in descend
21762176
<div class="source-panel">
21772177
<span>Scanned the following paths:</span>
21782178
<ul>
2179-
<li class="paths">./java-goof (maven)</li><li class="paths">./goof (npm)</li>
2179+
<li class="paths">./java-goof (maven)</li>
2180+
<li class="paths">./goof (npm)</li>
21802181
</ul>
21812182
</div>
21822183
@@ -6541,7 +6542,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html handles -a argument cor
65416542
<div class="source-panel">
65426543
<span>Scanned the following path:</span>
65436544
<ul>
6544-
<li class="paths">/path/to/npm-lockfile-with-vulns (npm)</li>
6545+
<li class="paths">/path/to/npm-lockfile-with-vulns/package-lock.json (npm)</li>
65456546
</ul>
65466547
</div>
65476548
@@ -7192,7 +7193,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html handles -s argument cor
71927193
<div class="source-panel">
71937194
<span>Scanned the following path:</span>
71947195
<ul>
7195-
<li class="paths">/path/to/npm-lockfile-with-vulns (npm)</li>
7196+
<li class="paths">/path/to/npm-lockfile-with-vulns/package-lock.json (npm)</li>
71967197
</ul>
71977198
</div>
71987199
@@ -8134,7 +8135,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html shows remediation & sum
81348135
<div class="source-panel">
81358136
<span>Scanned the following path:</span>
81368137
<ul>
8137-
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns (pip)</li>
8138+
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns/requirements.txt (pip)</li>
81388139
</ul>
81398140
</div>
81408141
@@ -8935,7 +8936,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html shows remediation with
89358936
<div class="source-panel">
89368937
<span>Scanned the following path:</span>
89378938
<ul>
8938-
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns (pip)</li>
8939+
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns/requirements.txt (pip)</li>
89398940
</ul>
89408941
</div>
89418942

template/test-report.header.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
<div class="source-panel">
2525
<span>Scanned the following paths:</span>
2626
<ul>
27-
{{#each paths}}<li class="paths">{{path}} ({{packageManager}})</li>{{/each}}
27+
{{#each paths}}
28+
<li class="paths">{{path}}{{#if displayTargetFile}}/{{displayTargetFile}}{{/if}} ({{packageManager}})</li>
29+
{{/each}}
2830
</ul>
2931
</div>
3032
{{/if}}
3133
{{#if path}}
3234
<div class="source-panel">
3335
<span>Scanned the following path:</span>
3436
<ul>
35-
<li class="paths">{{path}} ({{packageManager}})</li>
37+
<li class="paths">{{path}}{{#if displayTargetFile}}/{{displayTargetFile}}{{/if}} ({{packageManager}})</li>
3638
</ul>
3739
</div>
3840
{{/if}}

template/test-report.vuln-card.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<hr/>
1010

1111
<ul class="card__meta">
12+
{{#if list.[0].displayTargetFile }}
13+
<li class="card__meta__item">
14+
Manifest file: {{list.[0].path}} <span class="list-paths__item__arrow">›</span> {{list.[0].displayTargetFile}}
15+
</li>
16+
{{/if}}
1217
<li class="card__meta__item">
1318
Package Manager: {{metadata.packageManager}}
1419
</li>

test/fixtures/test-report-container-with-app-vulns.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@
12761276
"uniqueCount": 1,
12771277
"targetFile": "/bin/gobin",
12781278
"projectName": "mymod",
1279-
"displayTargetFile": "/bin/gobin",
12801279
"path": "vulnerable:latest"
12811280
}
12821281
]

0 commit comments

Comments
 (0)