Search in sources :

Example 1 with Result

use of com.mercedesbenz.sechub.sarif.model.Result in project sechub by mercedes-benz.

the class SarifReportSupportTest method specification_properties_snippet_properties_contains_tags.

@Test
void specification_properties_snippet_properties_contains_tags() throws IOException {
    /* prepare */
    File folder = sarifSpecificationSnippetsFolder;
    /* execute */
    Report report = supportToTest.loadReport(new File(folder, "specification-properties-snippet.sarif.json"));
    /* test */
    List<Result> results = report.getRuns().iterator().next().getResults();
    Result result = results.iterator().next();
    PropertyBag properties = result.getProperties();
    assertNotNull(properties);
    Object tags = properties.get("tags");
    assertEquals(Collections.singleton("openSource"), tags);
}
Also used : Report(com.mercedesbenz.sechub.sarif.model.Report) PropertyBag(com.mercedesbenz.sechub.sarif.model.PropertyBag) File(java.io.File) Result(com.mercedesbenz.sechub.sarif.model.Result) Test(org.junit.jupiter.api.Test)

Example 2 with Result

use of com.mercedesbenz.sechub.sarif.model.Result in project sechub by mercedes-benz.

the class SarifReportSupportTest method microsoft_sarif_tutorial_taxonomies_example__result_messages.

@Test
void microsoft_sarif_tutorial_taxonomies_example__result_messages() throws IOException {
    /* prepare */
    File codeFlowReportFile = new File(sarifTutorialSamplesFolder, "Taxonomies.sarif");
    /* execute */
    Report report = supportToTest.loadReport(codeFlowReportFile);
    /* test */
    List<Run> runs = report.getRuns();
    assertEquals(1, runs.size(), "there must be ONE run!");
    Run run = runs.iterator().next();
    List<Result> results = run.getResults();
    assertEquals(2, results.size(), "there must be two result!");
    Iterator<Result> iterator = results.iterator();
    // sort results by tree map, so we can fetch wanted ones
    Map<String, Result> sortedMap = new TreeMap<>();
    Result result = iterator.next();
    sortedMap.put(result.getRuleId(), result);
    result = iterator.next();
    sortedMap.put(result.getRuleId(), result);
    Result result1 = sortedMap.get("TUT1001");
    assertNotNull(result1);
    assertEquals("TUT1001", result1.getRuleId());
    assertEquals("This result violates a rule that is classified as 'Required'.", result1.getMessage().getText());
    Result result2 = sortedMap.get("TUT1002");
    assertNotNull(result2);
    assertEquals("TUT1002", result2.getRuleId());
    assertEquals("This result violates a rule that is classified as 'Recommended'.", result2.getMessage().getText());
}
Also used : Report(com.mercedesbenz.sechub.sarif.model.Report) Run(com.mercedesbenz.sechub.sarif.model.Run) TreeMap(java.util.TreeMap) File(java.io.File) Result(com.mercedesbenz.sechub.sarif.model.Result) Test(org.junit.jupiter.api.Test)

Example 3 with Result

use of com.mercedesbenz.sechub.sarif.model.Result in project sechub by mercedes-benz.

the class SarifReportSupportTest method microsoft_sarif_tutorial_codeflow_example.

@Test
void microsoft_sarif_tutorial_codeflow_example() throws IOException {
    /* prepare */
    File codeFlowReportFile = new File(sarifTutorialSamplesFolder, "CodeFlows.sarif");
    /* execute */
    Report report = supportToTest.loadReport(codeFlowReportFile);
    /* test */
    List<Run> runs = report.getRuns();
    assertEquals(1, runs.size(), "there must be ONE run!");
    Run run = runs.iterator().next();
    List<Result> results = run.getResults();
    assertEquals(1, results.size(), "there must be ONE result!");
    Result result = results.iterator().next();
    assertEquals("TUT1001", result.getRuleId());
    assertEquals("Use of uninitialized variable.", result.getMessage().getText());
    List<CodeFlow> codeFlows = result.getCodeFlows();
    assertEquals(2, codeFlows.size());
}
Also used : Report(com.mercedesbenz.sechub.sarif.model.Report) Run(com.mercedesbenz.sechub.sarif.model.Run) CodeFlow(com.mercedesbenz.sechub.sarif.model.CodeFlow) File(java.io.File) Result(com.mercedesbenz.sechub.sarif.model.Result) Test(org.junit.jupiter.api.Test)

Example 4 with Result

use of com.mercedesbenz.sechub.sarif.model.Result in project sechub by mercedes-benz.

the class SarifReportSupportTest method specification_properties_snippet_properties_contains_opensource_key_and_map_value.

@Test
void specification_properties_snippet_properties_contains_opensource_key_and_map_value() throws IOException {
    /* prepare */
    File folder = sarifSpecificationSnippetsFolder;
    /* execute */
    Report report = supportToTest.loadReport(new File(folder, "specification-properties-snippet.sarif.json"));
    /* test */
    List<Result> results = report.getRuns().iterator().next().getResults();
    Result result = results.iterator().next();
    PropertyBag properties = result.getProperties();
    assertNotNull(properties);
    openSourceData = properties.get("openSource");
    if (openSourceData instanceof Map) {
        @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) openSourceData;
        String informationUri = (String) map.get("informationUri");
        assertEquals("http://www.example.com/procedures/usingOpenSource.html", informationUri);
    } else {
        fail("expected map but found:" + openSourceData);
    }
}
Also used : Report(com.mercedesbenz.sechub.sarif.model.Report) PropertyBag(com.mercedesbenz.sechub.sarif.model.PropertyBag) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap) Result(com.mercedesbenz.sechub.sarif.model.Result) Test(org.junit.jupiter.api.Test)

Example 5 with Result

use of com.mercedesbenz.sechub.sarif.model.Result in project sechub by mercedes-benz.

the class SarifReportSupportTest method brakeman_sarif_example_with_tags__tags_can_be_fetched.

@Test
void brakeman_sarif_example_with_tags__tags_can_be_fetched() throws IOException {
    /* prepare */
    File codeFlowReportFile = new File(sarifBrakemanFolder, "sarif_2_1_0__brakeman_testfile_with_tags.sarif.json");
    /* execute */
    Report report = supportToTest.loadReport(codeFlowReportFile);
    /* test */
    List<Run> runs = report.getRuns();
    assertEquals(1, runs.size(), "there must be ONE run!");
    Run run = runs.iterator().next();
    List<Result> results = run.getResults();
    assertEquals(32, results.size(), "there must be 32 results!");
    Result result = results.iterator().next();
    Rule rule = supportToTest.fetchRuleForResult(result, run);
    Set<String> tags = rule.getProperties().fetchTags();
    assertNotNull(tags);
    Set<String> expected = new LinkedHashSet<>();
    expected.add("ContentTag");
    expected.add("Tag2");
    expected.add("Tag3");
    assertEquals(expected, tags);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Report(com.mercedesbenz.sechub.sarif.model.Report) Run(com.mercedesbenz.sechub.sarif.model.Run) Rule(com.mercedesbenz.sechub.sarif.model.Rule) File(java.io.File) Result(com.mercedesbenz.sechub.sarif.model.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Report (com.mercedesbenz.sechub.sarif.model.Report)7 Result (com.mercedesbenz.sechub.sarif.model.Result)7 File (java.io.File)6 Test (org.junit.jupiter.api.Test)6 PropertyBag (com.mercedesbenz.sechub.sarif.model.PropertyBag)4 Run (com.mercedesbenz.sechub.sarif.model.Run)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 CodeFlow (com.mercedesbenz.sechub.sarif.model.CodeFlow)2 Rule (com.mercedesbenz.sechub.sarif.model.Rule)2 SimpleStringUtils (com.mercedesbenz.sechub.commons.core.util.SimpleStringUtils)1 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SarifReportSupport (com.mercedesbenz.sechub.sarif.SarifReportSupport)1 ArtifactContent (com.mercedesbenz.sechub.sarif.model.ArtifactContent)1 ArtifactLocation (com.mercedesbenz.sechub.sarif.model.ArtifactLocation)1 Level (com.mercedesbenz.sechub.sarif.model.Level)1 Location (com.mercedesbenz.sechub.sarif.model.Location)1 Message (com.mercedesbenz.sechub.sarif.model.Message)1 PhysicalLocation (com.mercedesbenz.sechub.sarif.model.PhysicalLocation)1 Region (com.mercedesbenz.sechub.sarif.model.Region)1