Search in sources :

Example 1 with SecHubCodeCallStack

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

the class SerecoProductResultTransformerTest method one_vulnerability_as_code_in_meta_results_in_one_finding.

@Test
public void one_vulnerability_as_code_in_meta_results_in_one_finding() throws Exception {
    /* prepare */
    String converted = createMetaDataWithOneVulnerabilityAsCodeFound();
    /* execute */
    ReportTransformationResult result = transformerToTest.transform(createProductResult(converted));
    /* test */
    SecHubResult sechubResult = result.getResult();
    for (SecHubFinding finding : sechubResult.getFindings()) {
        assertEquals(ScanType.CODE_SCAN, finding.getType());
    }
    AssertSecHubResult.assertSecHubResult(sechubResult).hasFindings(1);
    SecHubFinding finding1 = sechubResult.getFindings().get(0);
    SecHubCodeCallStack code1 = finding1.getCode();
    assertNotNull(code1);
    assertEquals(Integer.valueOf(1), code1.getLine());
    assertEquals(Integer.valueOf(2), code1.getColumn());
    assertEquals("Location1", code1.getLocation());
    assertEquals("source1", code1.getSource());
    assertEquals("relevantPart1", code1.getRelevantPart());
    SecHubCodeCallStack code2 = code1.getCalls();
    assertNotNull(code2);
    assertEquals(Integer.valueOf(3), code2.getLine());
    assertEquals(Integer.valueOf(4), code2.getColumn());
    assertEquals("Location2", code2.getLocation());
    assertEquals("source2", code2.getSource());
    assertEquals("relevantPart2", code2.getRelevantPart());
}
Also used : SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) ReportTransformationResult(com.mercedesbenz.sechub.domain.scan.ReportTransformationResult) AssertSecHubResult(com.mercedesbenz.sechub.domain.scan.AssertSecHubResult) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack) Test(org.junit.Test)

Example 2 with SecHubCodeCallStack

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

the class SerecoProductResultTransformer method convert.

private SecHubCodeCallStack convert(SerecoCodeCallStackElement element) {
    if (element == null) {
        return null;
    }
    SecHubCodeCallStack codeCallStack = new SecHubCodeCallStack();
    codeCallStack.setLine(element.getLine());
    codeCallStack.setColumn(element.getColumn());
    codeCallStack.setLocation(element.getLocation());
    codeCallStack.setSource(element.getSource());
    codeCallStack.setCalls(convert(element.getCalls()));
    codeCallStack.setRelevantPart(element.getRelevantPart());
    return codeCallStack;
}
Also used : SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)

Example 3 with SecHubCodeCallStack

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

the class HtmlCodeScanDescriptionSupport method buildEntries.

public List<HTMLScanResultCodeScanEntry> buildEntries(SecHubFinding finding) {
    if (finding == null) {
        return Collections.emptyList();
    }
    SecHubCodeCallStack code = finding.getCode();
    if (code == null) {
        return Collections.emptyList();
    }
    int callNumber = 1;
    List<HTMLScanResultCodeScanEntry> descriptionList = new ArrayList<>();
    descriptionList.add(createEntry(callNumber++, code));
    SecHubCodeCallStack lastCode = code;
    while (lastCode.getCalls() != null) {
        lastCode = lastCode.getCalls();
        descriptionList.add(createEntry(callNumber++, lastCode));
    }
    return descriptionList;
}
Also used : ArrayList(java.util.ArrayList) SecHubCodeCallStack(com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)

Example 4 with SecHubCodeCallStack

use of com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack 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 5 with SecHubCodeCallStack

use of com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack 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)

Aggregations

SecHubCodeCallStack (com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)10 SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)6 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubResult (com.mercedesbenz.sechub.commons.model.SecHubResult)1 AssertSecHubResult (com.mercedesbenz.sechub.domain.scan.AssertSecHubResult)1 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)1 NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)1 List (java.util.List)1 Map (java.util.Map)1