Skip to content

Commit

Permalink
Merge pull request #170 from snyk/dotkas/SUP-2192/add-target-file-to-…
Browse files Browse the repository at this point in the history
…nuget-results

feat: [SUP-2192] Adding manifest file to vuln card if scanning multi-project
  • Loading branch information
dotkas authored Dec 7, 2023
2 parents 6a578dc + ce935fb commit 4b86151
Show file tree
Hide file tree
Showing 7 changed files with 1,518 additions and 11 deletions.
25 changes: 22 additions & 3 deletions src/lib/snyk-to-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,34 @@ async function generateCodeTemplate(
}

function mergeData(dataArray: any[]): any {
const vulnsArrays = dataArray.map(project => project.vulnerabilities || []);
const vulnsArrays = dataArray.map((project) => {
if (!project.vulnerabilities) {
return [];
}

// Add project data to each of the vulnerabilities to display more
// details on each vulnerability card, in order to properly distinguish
// from which project a vuln is connected, in case of displaying multiple
// projects.
const vulns = project.vulnerabilities.map((vuln) => ({
...vuln,
displayTargetFile: project.displayTargetFile,
path: project.path
}));
return vulns;
});
const aggregateVulnerabilities = [].concat(...vulnsArrays);

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

const paths = dataArray.map(project => ({ path: project.path, packageManager: project.packageManager }));
const paths = dataArray.map(project => ({
path: project.path,
packageManager: project.packageManager,
displayTargetFile: project.displayTargetFile,
}));

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

const OrderedIssuesArray = await processSourceCode(dataArray);

const totalIssues = dataArray[0].runs[0].results.length;
const processedData = {
projects: OrderedIssuesArray,
Expand Down
11 changes: 6 additions & 5 deletions tap-snapshots/test-snyk-to-html.test.ts-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,8 @@ exports[`test/snyk-to-html.test.ts TAP template output displays vulns in descend
<div class="source-panel">
<span>Scanned the following paths:</span>
<ul>
<li class="paths">./java-goof (maven)</li><li class="paths">./goof (npm)</li>
<li class="paths">./java-goof (maven)</li>
<li class="paths">./goof (npm)</li>
</ul>
</div>
Expand Down Expand Up @@ -6541,7 +6542,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html handles -a argument cor
<div class="source-panel">
<span>Scanned the following path:</span>
<ul>
<li class="paths">/path/to/npm-lockfile-with-vulns (npm)</li>
<li class="paths">/path/to/npm-lockfile-with-vulns/package-lock.json (npm)</li>
</ul>
</div>
Expand Down Expand Up @@ -7192,7 +7193,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html handles -s argument cor
<div class="source-panel">
<span>Scanned the following path:</span>
<ul>
<li class="paths">/path/to/npm-lockfile-with-vulns (npm)</li>
<li class="paths">/path/to/npm-lockfile-with-vulns/package-lock.json (npm)</li>
</ul>
</div>
Expand Down Expand Up @@ -8134,7 +8135,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html shows remediation & sum
<div class="source-panel">
<span>Scanned the following path:</span>
<ul>
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns (pip)</li>
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns/requirements.txt (pip)</li>
</ul>
</div>
Expand Down Expand Up @@ -8935,7 +8936,7 @@ exports[`test/snyk-to-html.test.ts TAP test snyk-to-html shows remediation with
<div class="source-panel">
<span>Scanned the following path:</span>
<ul>
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns (pip)</li>
<li class="paths">/Users/lili/www/snyk-fixtures/python-pip-app-with-vulns/requirements.txt (pip)</li>
</ul>
</div>
Expand Down
6 changes: 4 additions & 2 deletions template/test-report.header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
<div class="source-panel">
<span>Scanned the following paths:</span>
<ul>
{{#each paths}}<li class="paths">{{path}} ({{packageManager}})</li>{{/each}}
{{#each paths}}
<li class="paths">{{path}}{{#if displayTargetFile}}/{{displayTargetFile}}{{/if}} ({{packageManager}})</li>
{{/each}}
</ul>
</div>
{{/if}}
{{#if path}}
<div class="source-panel">
<span>Scanned the following path:</span>
<ul>
<li class="paths">{{path}} ({{packageManager}})</li>
<li class="paths">{{path}}{{#if displayTargetFile}}/{{displayTargetFile}}{{/if}} ({{packageManager}})</li>
</ul>
</div>
{{/if}}
Expand Down
5 changes: 5 additions & 0 deletions template/test-report.vuln-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<hr/>

<ul class="card__meta">
{{#if list.[0].displayTargetFile }}
<li class="card__meta__item">
Manifest file: {{list.[0].path}} <span class="list-paths__item__arrow">›</span> {{list.[0].displayTargetFile}}
</li>
{{/if}}
<li class="card__meta__item">
Package Manager: {{metadata.packageManager}}
</li>
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/test-report-container-with-app-vulns.json
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,6 @@
"uniqueCount": 1,
"targetFile": "/bin/gobin",
"projectName": "mymod",
"displayTargetFile": "/bin/gobin",
"path": "vulnerable:latest"
}
]
Expand Down
Loading

0 comments on commit 4b86151

Please sign in to comment.