Search in sources :

Example 1 with ReportingConfiguration

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

the class SarifReportSupportTest method microsoft_sarif_tutorial_taxonomies_example__result_defaultocnfiguraiton_level.

@Test
void microsoft_sarif_tutorial_taxonomies_example__result_defaultocnfiguraiton_level() 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<Rule> rules = run.getTool().getDriver().getRules();
    Map<String, Rule> sortedMap = new TreeMap<>();
    for (Rule rule : rules) {
        sortedMap.put(rule.getId(), rule);
    }
    Rule rule1 = sortedMap.get("TUT0001");
    assertNotNull(rule1);
    ReportingConfiguration defaultConfig1 = rule1.getDefaultConfiguration();
    assertNotNull(defaultConfig1);
    assertEquals(Level.ERROR, defaultConfig1.getLevel());
    Rule rule2 = sortedMap.get("TUT0002");
    assertNotNull(rule2);
    ReportingConfiguration defaultConfig2 = rule2.getDefaultConfiguration();
    assertNotNull(defaultConfig2);
    assertEquals(Level.WARNING, defaultConfig2.getLevel());
}
Also used : Report(com.mercedesbenz.sechub.sarif.model.Report) Run(com.mercedesbenz.sechub.sarif.model.Run) Rule(com.mercedesbenz.sechub.sarif.model.Rule) TreeMap(java.util.TreeMap) File(java.io.File) ReportingConfiguration(com.mercedesbenz.sechub.sarif.model.ReportingConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with ReportingConfiguration

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

the class SarifReportSupport method resolveLevel.

/**
 * Tries first the result level. If not set, the level will be obtained by
 * default configuration if available. If not found {@link Level#NONE} is
 * returned
 *
 * @param result
 * @param run
 * @return level, never null
 */
public Level resolveLevel(Result result, Run run) {
    Level level = result.getLevel();
    if (level != null) {
        return level;
    }
    Rule rule = fetchRuleForResult(result, run);
    if (rule != null) {
        /* @formatter:off

               first fetch default from rule
               see https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317850

               @formatter:on */
        ReportingConfiguration defaultConfiguration = rule.getDefaultConfiguration();
        if (defaultConfiguration != null) {
            level = defaultConfiguration.getLevel();
        }
    }
    if (level == null) {
        level = Level.NONE;
    }
    return level;
}
Also used : Level(com.mercedesbenz.sechub.sarif.model.Level) Rule(com.mercedesbenz.sechub.sarif.model.Rule) ReportingConfiguration(com.mercedesbenz.sechub.sarif.model.ReportingConfiguration)

Aggregations

ReportingConfiguration (com.mercedesbenz.sechub.sarif.model.ReportingConfiguration)2 Rule (com.mercedesbenz.sechub.sarif.model.Rule)2 Level (com.mercedesbenz.sechub.sarif.model.Level)1 Report (com.mercedesbenz.sechub.sarif.model.Report)1 Run (com.mercedesbenz.sechub.sarif.model.Run)1 File (java.io.File)1 TreeMap (java.util.TreeMap)1 Test (org.junit.jupiter.api.Test)1