From a039d3560825afa35f7f4c87c639e0b628635bba Mon Sep 17 00:00:00 2001 From: Valentyn Grygoriev Date: Wed, 16 Aug 2023 16:51:46 +0300 Subject: [PATCH] Fixed some tests and html templates #345 --- .../src/main/resources/reduced-openapi3.json | 98 +++++++------- ...ecHubReportMetaDataSummaryDetailsTest.java | 34 ++--- .../SecHubReportMetaDataSummaryTest.java | 3 + .../ScanReportRestControllerRestDocTest.java | 10 +- .../templates/report/html/details_footer.html | 2 +- .../templates/report/html/scanresult.html | 124 +++++++++--------- .../ScanReportRestControllerMockTest.java | 31 ++--- 7 files changed, 150 insertions(+), 152 deletions(-) diff --git a/sechub-api-java/src/main/resources/reduced-openapi3.json b/sechub-api-java/src/main/resources/reduced-openapi3.json index 9c6c59e04f..f196b8b20d 100644 --- a/sechub-api-java/src/main/resources/reduced-openapi3.json +++ b/sechub-api-java/src/main/resources/reduced-openapi3.json @@ -3185,6 +3185,55 @@ } } }, + "ExecutionProfileFetch": { + "title": "ExecutionProfileFetch", + "type": "object", + "properties": { + "configurations": { + "type": "array", + "items": { + "type": "object", + "properties": { + "productIdentifier": { + "type": "string", + "description": "executed product" + }, + "name": { + "type": "string", + "description": "name of configuration" + }, + "executorVersion": { + "type": "number", + "description": "executor version" + }, + "uuid": { + "type": "string", + "description": "uuid of configuration" + }, + "enabled": { + "type": "boolean", + "description": "enabled state of this config" + } + } + } + }, + "description": { + "type": "string", + "description": "A short description for the profile" + }, + "projectIds": { + "type": "array", + "description": "Projects can be linked by their ids here", + "items": { + "type": "string" + } + }, + "enabled": { + "type": "boolean", + "description": "Enabled state of profile, default is false" + } + } + }, "FalsePositives": { "title": "FalsePositives", "type": "object", @@ -3298,55 +3347,6 @@ } } }, - "ExecutionProfileFetch": { - "title": "ExecutionProfileFetch", - "type": "object", - "properties": { - "configurations": { - "type": "array", - "items": { - "type": "object", - "properties": { - "productIdentifier": { - "type": "string", - "description": "executed product" - }, - "name": { - "type": "string", - "description": "name of configuration" - }, - "executorVersion": { - "type": "number", - "description": "executor version" - }, - "uuid": { - "type": "string", - "description": "uuid of configuration" - }, - "enabled": { - "type": "boolean", - "description": "enabled state of this config" - } - } - } - }, - "description": { - "type": "string", - "description": "A short description for the profile" - }, - "projectIds": { - "type": "array", - "description": "Projects can be linked by their ids here", - "items": { - "type": "string" - } - }, - "enabled": { - "type": "boolean", - "description": "Enabled state of profile, default is false" - } - } - }, "FullScanDataZIP": { "title": "FullScanDataZIP", "type": "object" diff --git a/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryDetailsTest.java b/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryDetailsTest.java index a883f48e46..0b691f41f6 100644 --- a/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryDetailsTest.java +++ b/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryDetailsTest.java @@ -16,6 +16,10 @@ public class SecHubReportMetaDataSummaryDetailsTest { static final int MEDIUM_FINDING_CWEID = 456; static final int LOW_FINDING_CWEID = 789; + static final String HIGH_FINDING_NAME = "Cross Site Scripting (Reflected)"; + static final String MEDIUM_FINDING_NAME = "CSP: Wildcard Directive"; + static final String LOW_FINDING_NAME = "Cookie Without Secure Flag"; + SecHubReportMetaDataSummaryDetails secHubReportMetaDataSummaryDetails; SecHubFinding highFinding; SecHubFinding mediumFinding; @@ -28,17 +32,17 @@ void beforeEach() { highFinding = new SecHubFinding(); highFinding.setCweId(HIGH_FINDING_CWEID); highFinding.setSeverity(Severity.HIGH); - highFinding.setName("Cross Site Scripting (Reflected)"); + highFinding.setName(HIGH_FINDING_NAME); mediumFinding = new SecHubFinding(); mediumFinding.setCweId(MEDIUM_FINDING_CWEID); mediumFinding.setSeverity(Severity.MEDIUM); - mediumFinding.setName("CSP: Wildcard Directive"); + mediumFinding.setName(MEDIUM_FINDING_NAME); lowFinding = new SecHubFinding(); lowFinding.setCweId(LOW_FINDING_CWEID); lowFinding.setSeverity(Severity.LOW); - lowFinding.setName("Cookie Without Secure Flag"); + lowFinding.setName(LOW_FINDING_NAME); } @Test @@ -47,7 +51,7 @@ void new_element_in_high_map_must_be_created() { secHubReportMetaDataSummaryDetails.detailsHelper(highFinding); /* test */ - assertNotNull(secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_CWEID)); + assertNotNull(secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_NAME)); } @Test @@ -56,7 +60,7 @@ void new_element_in_medium_map_must_be_created() { secHubReportMetaDataSummaryDetails.detailsHelper(mediumFinding); /* test */ - assertNotNull(secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_CWEID)); + assertNotNull(secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_NAME)); } @Test @@ -65,18 +69,18 @@ void new_element_in_low_map_must_be_created() { secHubReportMetaDataSummaryDetails.detailsHelper(lowFinding); /* test */ - assertNotNull(secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_CWEID)); + assertNotNull(secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_NAME)); } @Test void instance_variables_of_new_element_in_high_map_initialized_correctly() { /* execute */ secHubReportMetaDataSummaryDetails.detailsHelper(highFinding); - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_NAME); /* test */ assertEquals(HIGH_FINDING_CWEID, severityDetails.getCweId()); - assertEquals("Cross Site Scripting (Reflected)", severityDetails.getName()); + assertEquals(HIGH_FINDING_NAME, severityDetails.getName()); assertEquals(1, severityDetails.getCount()); } @@ -84,11 +88,11 @@ void instance_variables_of_new_element_in_high_map_initialized_correctly() { void instance_variables_of_new_element_in_medium_map_initialized_correctly() { /* execute */ secHubReportMetaDataSummaryDetails.detailsHelper(mediumFinding); - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_NAME); /* test */ assertEquals(MEDIUM_FINDING_CWEID, severityDetails.getCweId()); - assertEquals("CSP: Wildcard Directive", severityDetails.getName()); + assertEquals(MEDIUM_FINDING_NAME, severityDetails.getName()); assertEquals(1, severityDetails.getCount()); } @@ -96,11 +100,11 @@ void instance_variables_of_new_element_in_medium_map_initialized_correctly() { void instance_variables_of_new_element_in_low_map_initialized_correctly() { /* execute */ secHubReportMetaDataSummaryDetails.detailsHelper(lowFinding); - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_NAME); /* test */ assertEquals(LOW_FINDING_CWEID, severityDetails.getCweId()); - assertEquals("Cookie Without Secure Flag", severityDetails.getName()); + assertEquals(LOW_FINDING_NAME, severityDetails.getName()); assertEquals(1, severityDetails.getCount()); } @@ -110,7 +114,7 @@ void if_adding_multiple_similar_findings_into_high_map_counter_contains_correct_ for (int i = 0; i < 101; i++) { secHubReportMetaDataSummaryDetails.detailsHelper(highFinding); } - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.high.get(HIGH_FINDING_NAME); /* test */ assertEquals(101, severityDetails.getCount()); @@ -122,7 +126,7 @@ void if_adding_multiple_similar_findings_into_medium_map_counter_contains_correc for (int i = 0; i < 101; i++) { secHubReportMetaDataSummaryDetails.detailsHelper(mediumFinding); } - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.medium.get(MEDIUM_FINDING_NAME); /* test */ assertEquals(101, severityDetails.getCount()); @@ -134,7 +138,7 @@ void if_adding_multiple_similar_findings_into_low_map_counter_contains_correct_v for (int i = 0; i < 101; i++) { secHubReportMetaDataSummaryDetails.detailsHelper(lowFinding); } - SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_CWEID); + SecHubReportMetaDataSummaryDetails.SeverityDetails severityDetails = secHubReportMetaDataSummaryDetails.low.get(LOW_FINDING_NAME); /* test */ assertEquals(101, severityDetails.getCount()); diff --git a/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryTest.java b/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryTest.java index 26b6347c96..3ac12ba3c9 100644 --- a/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryTest.java +++ b/sechub-commons-model/src/test/java/com/mercedesbenz/sechub/commons/model/SecHubReportMetaDataSummaryTest.java @@ -18,12 +18,15 @@ void beforeEach() { highFinding = new SecHubFinding(); highFinding.setSeverity(Severity.HIGH); + highFinding.setName("Cross Site Scripting (Reflected)"); mediumFinding = new SecHubFinding(); mediumFinding.setSeverity(Severity.MEDIUM); + mediumFinding.setName("CSP: Wildcard Directive"); lowFinding = new SecHubFinding(); lowFinding.setSeverity(Severity.LOW); + lowFinding.setName("Cookie Without Secure Flag"); } @Test diff --git a/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ScanReportRestControllerRestDocTest.java b/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ScanReportRestControllerRestDocTest.java index fa26528402..ca44eb0139 100644 --- a/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ScanReportRestControllerRestDocTest.java +++ b/sechub-doc/src/test/java/com/mercedesbenz/sechub/restdoc/ScanReportRestControllerRestDocTest.java @@ -14,11 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import org.junit.Before; import org.junit.Test; @@ -38,6 +34,7 @@ import com.mercedesbenz.sechub.commons.model.TrafficLight; import com.mercedesbenz.sechub.docgen.util.RestDocFactory; import com.mercedesbenz.sechub.domain.scan.HTMLScanResultReportModelBuilder; +import com.mercedesbenz.sechub.domain.scan.ScanTypeCount; import com.mercedesbenz.sechub.domain.scan.report.DownloadScanReportService; import com.mercedesbenz.sechub.domain.scan.report.DownloadSpdxScanReportService; import com.mercedesbenz.sechub.domain.scan.report.ScanReport; @@ -241,7 +238,8 @@ public void before() throws Exception { map.put("yellowList", new ArrayList<>()); map.put("greenList", new ArrayList<>()); map.put("isWebDesignMode", false); - map.put("metaData", Optional.ofNullable(null)); + map.put("metaData", null); + map.put("scanTypeCountSet", new TreeSet()); when(modelBuilder.build(any())).thenReturn(map); } diff --git a/sechub-scan/src/main/resources/templates/report/html/details_footer.html b/sechub-scan/src/main/resources/templates/report/html/details_footer.html index 213c36e309..69daa8e677 100644 --- a/sechub-scan/src/main/resources/templates/report/html/details_footer.html +++ b/sechub-scan/src/main/resources/templates/report/html/details_footer.html @@ -1,4 +1,4 @@ - +

Description

Description1
diff --git a/sechub-scan/src/main/resources/templates/report/html/scanresult.html b/sechub-scan/src/main/resources/templates/report/html/scanresult.html index bfbd315633..38d4880139 100644 --- a/sechub-scan/src/main/resources/templates/report/html/scanresult.html +++ b/sechub-scan/src/main/resources/templates/report/html/scanresult.html @@ -66,7 +66,7 @@ Scan result Report for Job:job-uuid - + @@ -101,66 +101,68 @@

Summary

-
- CodeScan -
-
-
-
-
-
-
-
-
-
-
- InfraScan -
-
-
-
-
-
-
-
-
-
-
- LicenseScan -
-
-
-
-
-
-
-
-
-
-
- SecretScan -
-
-
-
-
-
-
-
-
-
-
- WebScan -
-
-
-
-
-
-
-
-
-
+
+
+ CodeScan +
+
+
+
+
+
+
+
+
+
+
+ InfraScan +
+
+
+
+
+
+
+
+
+
+
+ LicenseScan +
+
+
+
+
+
+
+
+
+
+
+ SecretScan +
+
+
+
+
+
+
+
+
+
+
+ WebScan +
+
+
+
+
+
+
+
+
+
+

diff --git a/sechub-scan/src/test/java/com/mercedesbenz/sechub/domain/scan/ScanReportRestControllerMockTest.java b/sechub-scan/src/test/java/com/mercedesbenz/sechub/domain/scan/ScanReportRestControllerMockTest.java index e33d083fee..63b3709c5c 100644 --- a/sechub-scan/src/test/java/com/mercedesbenz/sechub/domain/scan/ScanReportRestControllerMockTest.java +++ b/sechub-scan/src/test/java/com/mercedesbenz/sechub/domain/scan/ScanReportRestControllerMockTest.java @@ -9,12 +9,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,17 +25,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; -import com.mercedesbenz.sechub.commons.model.SecHubFinding; -import com.mercedesbenz.sechub.commons.model.TrafficLight; -import com.mercedesbenz.sechub.commons.model.TrafficLightCalculator; +import com.mercedesbenz.sechub.commons.model.*; import com.mercedesbenz.sechub.domain.scan.product.ReportProductExecutionService; -import com.mercedesbenz.sechub.domain.scan.report.CreateScanReportService; -import com.mercedesbenz.sechub.domain.scan.report.DownloadScanReportService; -import com.mercedesbenz.sechub.domain.scan.report.DownloadSpdxScanReportService; -import com.mercedesbenz.sechub.domain.scan.report.ScanReport; -import com.mercedesbenz.sechub.domain.scan.report.ScanReportRepository; -import com.mercedesbenz.sechub.domain.scan.report.ScanReportRestController; -import com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport; +import com.mercedesbenz.sechub.domain.scan.report.*; import com.mercedesbenz.sechub.test.TestPortProvider; @ExtendWith(SpringExtension.class) @@ -130,11 +117,14 @@ void get_html_report_with_cwe_id() throws Exception { Integer cweId = Integer.valueOf(77); - SecHubFinding finding = new SecHubFinding(); + HTMLSecHubFinding finding = new HTMLSecHubFinding(); finding.setCweId(cweId); + finding.setSeverity(Severity.HIGH); + finding.setType(ScanType.CODE_SCAN); + finding.setDescription("Potential file inclusion via variable"); - reportModelBuilderResult.put("redList", Arrays.asList(finding)); - reportModelBuilderResult.put("codeScanEntries", new ArrayList<>()); + reportModelBuilderResult.put("reportHelper", HTMLReportHelper.DEFAULT); + reportModelBuilderResult.put("redHTMLSecHubFindingList", Arrays.asList(finding)); when(modelBuilder.build(any())).thenReturn(reportModelBuilderResult); @@ -264,8 +254,9 @@ void beforeEach() throws Exception { reportModelBuilderResult.put("yellowList", new ArrayList<>()); reportModelBuilderResult.put("greenList", new ArrayList<>()); reportModelBuilderResult.put("isWebDesignMode", false); - reportModelBuilderResult.put("metaData", Optional.ofNullable(null)); + reportModelBuilderResult.put("metaData", null); reportModelBuilderResult.put("codeScanSupport", new HtmlCodeScanDescriptionSupport()); + reportModelBuilderResult.put("scanTypeCountSet", new TreeSet()); when(modelBuilder.build(any())).thenReturn(reportModelBuilderResult); }