Skip to content

Commit

Permalink
The draft summary table in a HTML report #345
Browse files Browse the repository at this point in the history
  • Loading branch information
zigfridus committed Apr 27, 2023
1 parent 1899d25 commit d4d1a83
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
package com.mercedesbenz.sechub.domain.scan;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -14,10 +11,7 @@
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import com.mercedesbenz.sechub.commons.model.SecHubFinding;
import com.mercedesbenz.sechub.commons.model.SecHubResult;
import com.mercedesbenz.sechub.commons.model.SecHubResultTrafficLightFilter;
import com.mercedesbenz.sechub.commons.model.TrafficLight;
import com.mercedesbenz.sechub.commons.model.*;
import com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport;
import com.mercedesbenz.sechub.sharedkernel.MustBeDocumented;

Expand Down Expand Up @@ -53,16 +47,16 @@ public Map<String, Object> build(ScanSecHubReport report) {
}

switch (trafficLight) {
case RED:
styleRed = SHOW_LIGHT;
break;
case YELLOW:
styleYellow = SHOW_LIGHT;
break;
case GREEN:
styleGreen = SHOW_LIGHT;
break;
default:
case RED:
styleRed = SHOW_LIGHT;
break;
case YELLOW:
styleYellow = SHOW_LIGHT;
break;
case GREEN:
styleGreen = SHOW_LIGHT;
break;
default:
}
HtmlCodeScanDescriptionSupport codeScanSupport = new HtmlCodeScanDescriptionSupport();
SecHubResult result = report.getResult();
Expand Down Expand Up @@ -111,6 +105,41 @@ public Map<String, Object> build(ScanSecHubReport report) {
} else {
model.put("jobuuid", "none");
}

Map<ScanType, ScanTypeCount> scanSummaryMap = new HashMap<>();
for (SecHubFinding finding : result.getFindings()) {
ScanType scanType = finding.getType();
ScanTypeCount scanTypeCount;
if (scanSummaryMap.containsKey(scanType)) {
scanTypeCount = scanSummaryMap.get(scanType);
} else {
scanTypeCount = new ScanTypeCount(scanType);
scanSummaryMap.put(scanType, scanTypeCount);
}
incrementScanCount(finding.getSeverity(), scanTypeCount);
}
List<ScanTypeCount> scanTypeCountList = new ArrayList<>();
extractScanTypeCountListFromMap(scanTypeCountList, scanSummaryMap);
model.put("scanTypeCountList", scanTypeCountList);

return model;
}

private void incrementScanCount(Severity severity, ScanTypeCount scanTypeCount) {
if (Severity.HIGH.equals(severity)) {
scanTypeCount.incrementHighSeverityCount();
}
if (Severity.MEDIUM.equals(severity)) {
scanTypeCount.incrementMediumSeverityCount();
}
if (Severity.LOW.equals(severity)) {
scanTypeCount.incrementLowSeverityCount();
}
}

private void extractScanTypeCountListFromMap(List<ScanTypeCount> scanTypeCountList, Map<ScanType, ScanTypeCount> scanSummary) {
for (ScanTypeCount scanTypeCount : scanSummary.values()) {
scanTypeCountList.add(scanTypeCount);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.domain.scan;

import com.mercedesbenz.sechub.commons.model.ScanType;

public class ScanTypeCount {

private ScanType scanType;
private int highSeverityCount;
private int mediumSeverityCount;
private int lowSeverityCount;

ScanTypeCount(ScanType scanType){
this.scanType = scanType;
highSeverityCount = 0;
mediumSeverityCount = 0;
lowSeverityCount = 0;
}

public ScanType getScanType() {
return scanType;
}

public void setScanType(ScanType scanType) {
this.scanType = scanType;
}

public int getHighSeverityCount() {
return highSeverityCount;
}

public void setHighSeverityCount(int highSeverityCount) {
this.highSeverityCount = highSeverityCount;
}

public int getMediumSeverityCount() {
return mediumSeverityCount;
}

public void setMediumSeverityCount(int mediumSeverityCount) {
this.mediumSeverityCount = mediumSeverityCount;
}

public int getLowSeverityCount() {
return lowSeverityCount;
}

public void setLowSeverityCount(int lowSeverityCount) {
this.lowSeverityCount = lowSeverityCount;
}

public void incrementHighSeverityCount(){
this.highSeverityCount++;
}

public void incrementMediumSeverityCount(){
this.mediumSeverityCount++;
}

public void incrementLowSeverityCount(){
this.lowSeverityCount++;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,40 @@
display:flex;
}

.summaryHeadline {
font-family: monospace;
}

.summaryTable {
width: 20%;
padding-bottom: 16px;
padding-top: 10px;
border-collapse: separate;
border: solid #cccccc 1px;
border-radius: 16px;
border-spacing: 0px;
}

.summaryTable th {
padding: 8px;
vertical-align: center;
text-align: center;
}

.summaryTable td {
padding: 8px;
font-family: monospace;
vertical-align: center;
text-align: center;
}

.summaryTable td:nth-child(2) {
border-left: 1px solid #cccccc;
}

.summaryTable td:nth-child(3) {
border-left: 1px solid #cccccc;
}
</style>

<th:block th:fragment="findingCells">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset="UTF-8">
<title>SecHub scan result</title>
<!--/*
Remark: This comments will be removed at thymeleaf parsing time - means not in HTML output...
<!--/*
Remark: This comments will be removed at thymeleaf parsing time - means not in HTML output...
Important: If you change scanresult.css please always start HTMLReportCSSFragementGenerator to
synch to the fragment part. Details see HTMLReportCSSFragementGenerator.java
*/-->
<link th:if="${isWebDesignMode}" th:href="${includedCSSRef}"
rel="stylesheet" type="text/css" href="scanresult.css">
Expand All @@ -28,7 +28,6 @@
</div>
</div>
<div class="main">

<div class="header">
<table>
<tr>
Expand Down Expand Up @@ -81,46 +80,26 @@
</table>
</div>
<div class="content">
<div>
<div th:if="!${scanTypeCountList.isEmpty()}">
<h2 class='summaryHeadline'>Summary</h2>
<table class='summaryTable'>
<thead>
<tr>
<th></th>
<th>Code Scan</th>
<th>Secret Scan</th>
<th>Total</th>
<th>Red</th>
<th>Yellow</th>
<th>Green</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Total</strong></td>
<td><strong><span th:text="*{#lists.size(redList) + #lists.size(yellowList) + #lists.size(greenList)}">[Total number of Elements]</span></strong></td>
<td><strong></strong></td>
</tr>
<tr>
<td>Red</td>
<td>
<span th:if="!${redList.isEmpty()}"><a href="#redFindingsBlock" th:text="${#lists.size(redList)}"></a></span>
<span th:unless="!${redList.isEmpty()}" th:text="0"></span>
</td>
<td></td>
</tr>
<tr>
<td>Yellow</td>
<td>
<span th:if="!${yellowList.isEmpty()}"><a href="#yellowFindingsBlock" th:text="${#lists.size(yellowList)}"></a></span>
<span th:unless="!${yellowList.isEmpty()}" th:text="0"></span>
</td>
<td></td>
</tr>
<tr>
<td>Green</td>
<td>
<span th:if="!${greenList.isEmpty()}"><a href="#greenFindingsBlock" th:text="${#lists.size(greenList)}"></a></span>
<span th:unless="!${greenList.isEmpty()}" th:text="0"></span>
</td>
<td></td>
</tr>
<tr th:each="scanTypeCount : ${scanTypeCountList}">
<td th:text="${scanTypeCount.scanType}" />
<td><strong><span th:text="${scanTypeCount.highSeverityCount + scanTypeCount.mediumSeverityCount + scanTypeCount.lowSeverityCount}"/></strong></td>
<td th:text="${scanTypeCount.highSeverityCount}" />
<td th:text="${scanTypeCount.mediumSeverityCount}" />
<td th:text="${scanTypeCount.lowSeverityCount}" />
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -243,8 +222,6 @@ <h2 class='messagesHeadline'>Messages</h2>
</tbody>
</table>
</div>
</div>
</div>

</body>
</html>

0 comments on commit d4d1a83

Please sign in to comment.