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);
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations