Search in sources :

Example 11 with SecHubFinding

use of com.mercedesbenz.sechub.commons.model.SecHubFinding in project sechub by mercedes-benz.

the class ScanReportRestControllerMockTest method get_html_report_with_cwe_id.

@Test
@WithMockUser
public void get_html_report_with_cwe_id() throws Exception {
    /* prepare */
    Integer cweId = Integer.valueOf(77);
    SecHubFinding finding = new SecHubFinding();
    finding.setCweId(cweId);
    Map<String, Object> map = new HashMap<>();
    map.put("jobuuid", randomUUID);
    map.put("styleRed", "theRedStyle");
    map.put("styleGreen", "display:none");
    map.put("styleYellow", "display:none");
    map.put("redList", Arrays.asList(finding));
    map.put("yellowList", new ArrayList<>());
    map.put("greenList", new ArrayList<>());
    map.put("isWebDesignMode", false);
    map.put("codeScanSupport", new HtmlCodeScanDescriptionSupport());
    map.put("codeScanEntries", new ArrayList<>());
    when(modelBuilder.build(any())).thenReturn(map);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(https(PORT_USED).buildGetJobReportUrl(PROJECT1_ID, randomUUID)).accept(MediaType.TEXT_HTML).contentType(MediaType.APPLICATION_JSON_VALUE)).andDo(print()).andExpect(status().isOk()).andExpect(content().contentType("text/html;charset=UTF-8")).andExpect(content().encoding("UTF-8")).andExpect(content().string(containsString(randomUUID.toString()))).andExpect(content().string(containsString("CWE-" + cweId.toString()))).andExpect(content().string(containsString("href=\"https://cwe.mitre.org/data/definitions/" + cweId.toString() + ".html\"")));
/* @formatter:on */
}
Also used : HashMap(java.util.HashMap) SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 12 with SecHubFinding

use of com.mercedesbenz.sechub.commons.model.SecHubFinding in project sechub by mercedes-benz.

the class HtmlCodeScanDescriptionSupportTest method build_entries__creates_html_scan_entries_with_correct_callnumbers.

@Test
void build_entries__creates_html_scan_entries_with_correct_callnumbers() {
    /* prepare */
    SecHubFinding finding = new SecHubFinding();
    SecHubCodeCallStack code1 = new SecHubCodeCallStack();
    SecHubCodeCallStack code2 = new SecHubCodeCallStack();
    SecHubCodeCallStack code3 = new SecHubCodeCallStack();
    SecHubCodeCallStack code4 = new SecHubCodeCallStack();
    finding.setCode(code1);
    code1.setCalls(code2);
    code2.setCalls(code3);
    code3.setCalls(code4);
    /* execute */
    List<HTMLScanResultCodeScanEntry> fourElementsResult = descriptionSupport.buildEntries(finding);
    /* test */
    assertEquals(4, fourElementsResult.size());
    assertEquals(1, fourElementsResult.get(0).getCallNumber());
    assertEquals(2, fourElementsResult.get(1).getCallNumber());
    assertEquals(3, fourElementsResult.get(2).getCallNumber());
    assertEquals(4, fourElementsResult.get(3).getCallNumber());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack) Test(org.junit.jupiter.api.Test)

Example 13 with SecHubFinding

use of com.mercedesbenz.sechub.commons.model.SecHubFinding in project sechub by mercedes-benz.

the class HtmlCodeScanDescriptionSupportTest method build_entries__creates_html_scan_entries_with_correct_linenumbers.

@Test
void build_entries__creates_html_scan_entries_with_correct_linenumbers() {
    /* prepare */
    SecHubFinding finding = new SecHubFinding();
    SecHubCodeCallStack code1 = new SecHubCodeCallStack();
    code1.setLine(0);
    SecHubCodeCallStack code2 = new SecHubCodeCallStack();
    code2.setLine(1);
    SecHubCodeCallStack code3 = new SecHubCodeCallStack();
    code3.setLine(2);
    SecHubCodeCallStack code4 = new SecHubCodeCallStack();
    code4.setLine(3);
    finding.setCode(code1);
    code1.setCalls(code2);
    code2.setCalls(code3);
    code3.setCalls(code4);
    /* execute */
    List<HTMLScanResultCodeScanEntry> fourElementsResult = descriptionSupport.buildEntries(finding);
    /* test */
    assertEquals(4, fourElementsResult.size());
    assertEquals(code1.getLine(), fourElementsResult.get(0).getLine());
    assertEquals(code2.getLine(), fourElementsResult.get(1).getLine());
    assertEquals(code3.getLine(), fourElementsResult.get(2).getLine());
    assertEquals(code4.getLine(), fourElementsResult.get(3).getLine());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack) Test(org.junit.jupiter.api.Test)

Example 14 with SecHubFinding

use of com.mercedesbenz.sechub.commons.model.SecHubFinding in project sechub by mercedes-benz.

the class HtmlCodeScanDescriptionSupportTest method test_is_code_scan_with_non_code_scan_finding.

@Test
void test_is_code_scan_with_non_code_scan_finding() {
    /* prepare */
    SecHubFinding finding = new SecHubFinding();
    /* test */
    assertFalse(descriptionSupport.isCodeScan(finding));
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) Test(org.junit.jupiter.api.Test)

Example 15 with SecHubFinding

use of com.mercedesbenz.sechub.commons.model.SecHubFinding in project sechub by mercedes-benz.

the class AssertReport method assertFindings.

private List<SecHubFinding> assertFindings(SecHubReport report) {
    assertNotNull("Report may not be null", report);
    SecHubResult result = report.getResult();
    assertNotNull(result);
    List<SecHubFinding> findings = result.getFindings();
    assertNotNull(findings);
    return findings;
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult)

Aggregations

SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)29 Test (org.junit.jupiter.api.Test)12 SecHubResult (com.mercedesbenz.sechub.commons.model.SecHubResult)8 SecHubCodeCallStack (com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)6 Test (org.junit.Test)6 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)3 SecHubReportModel (com.mercedesbenz.sechub.commons.model.SecHubReportModel)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 UUID (java.util.UUID)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubMessage (com.mercedesbenz.sechub.commons.model.SecHubMessage)1 Severity (com.mercedesbenz.sechub.commons.model.Severity)1 TrafficLight (com.mercedesbenz.sechub.commons.model.TrafficLight)1 SecHubReportWeb (com.mercedesbenz.sechub.commons.model.web.SecHubReportWeb)1 SecHubReportWebEvidence (com.mercedesbenz.sechub.commons.model.web.SecHubReportWebEvidence)1 SecHubReportWebRequest (com.mercedesbenz.sechub.commons.model.web.SecHubReportWebRequest)1 SecHubReportWebResponse (com.mercedesbenz.sechub.commons.model.web.SecHubReportWebResponse)1 AssertSecHubResult (com.mercedesbenz.sechub.domain.scan.AssertSecHubResult)1