"78", "190", "22", "476", "287", "434", "732", "94", "522",
"611", "798", "502", "269", "400", "306", "862"));
- public static final Map<String, List<String>> CWES_BY_CWE_TOP_25 = ImmutableMap.of(
+ // https://cwe.mitre.org/top25/archive/2021/2021_cwe_top25.html
+ public static final List<String> CWE_TOP25_2021 =
+ Collections.unmodifiableList(asList("119", "79", "20", "200", "125", "89", "416", "190", "352",
+ "22", "78", "787", "287", "476", "732", "434", "611", "94",
+ "798", "400", "772", "426", "502", "269", "295"));
+
+ public static final Map<String, List<String>> CWES_BY_CWE_TOP_25 = Map.of(
"2019", CWE_TOP25_2019,
- "2020", CWE_TOP25_2020);
+ "2020", CWE_TOP25_2020,
+ "2021", CWE_TOP25_2021);
public enum VulnerabilityProbability {
HIGH(3),
List<SecurityStandardCategoryStatistics> cweTop25Reports = underTest.getCweTop25Reports(project.uuid(), false);
- SecurityStandardCategoryStatistics cwe2019 = cweTop25Reports.get(0);
+ List<String> listOfYears = cweTop25Reports.stream()
+ .map(SecurityStandardCategoryStatistics::getCategory)
+ .collect(toList());
+
+ assertThat(listOfYears).contains("2019", "2020", "2021");
+
+ SecurityStandardCategoryStatistics cwe2019 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2019"))
+ .findAny().get();
assertThat(cwe2019.getChildren()).hasSize(25);
assertThat(findRuleInCweByYear(cwe2019, "119")).isNotNull()
.extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
assertThat(findRuleInCweByYear(cwe2019, "862")).isNull();
assertThat(findRuleInCweByYear(cwe2019, "999")).isNull();
- SecurityStandardCategoryStatistics cwe2020 = cweTop25Reports.get(1);
+ SecurityStandardCategoryStatistics cwe2020 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2020"))
+ .findAny().get();
assertThat(cwe2020.getChildren()).hasSize(25);
assertThat(findRuleInCweByYear(cwe2020, "119")).isNotNull()
.extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
.containsExactlyInAnyOrder(1L, 0L, 0L);
assertThat(findRuleInCweByYear(cwe2020, "999")).isNull();
+
+ SecurityStandardCategoryStatistics cwe2021 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2021"))
+ .findAny().get();
+ assertThat(cwe2021.getChildren()).hasSize(25);
+ assertThat(findRuleInCweByYear(cwe2021, "119")).isNotNull()
+ .extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
+ SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+ SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
+ .containsExactlyInAnyOrder(1L, 0L, 0L);
+ assertThat(findRuleInCweByYear(cwe2021, "89")).isNotNull()
+ .extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
+ SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+ SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
+ .containsExactlyInAnyOrder(0L, 1L, 0L);
+ assertThat(findRuleInCweByYear(cwe2021, "862")).isNull();
+ assertThat(findRuleInCweByYear(cwe2021, "999")).isNull();
}
@Test
List<SecurityStandardCategoryStatistics> cweTop25Reports = underTest.getCweTop25Reports(application.uuid(), true);
- SecurityStandardCategoryStatistics cwe2019 = cweTop25Reports.get(0);
+ List<String> listOfYears = cweTop25Reports.stream()
+ .map(SecurityStandardCategoryStatistics::getCategory)
+ .collect(toList());
+
+ assertThat(listOfYears).contains("2019", "2020", "2021");
+
+ SecurityStandardCategoryStatistics cwe2019 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2019"))
+ .findAny().get();
assertThat(cwe2019.getChildren()).hasSize(25);
assertThat(findRuleInCweByYear(cwe2019, "119")).isNotNull()
.extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
assertThat(findRuleInCweByYear(cwe2019, "862")).isNull();
assertThat(findRuleInCweByYear(cwe2019, "999")).isNull();
- SecurityStandardCategoryStatistics cwe2020 = cweTop25Reports.get(1);
+ SecurityStandardCategoryStatistics cwe2020 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2020"))
+ .findAny().get();
assertThat(cwe2020.getChildren()).hasSize(25);
assertThat(findRuleInCweByYear(cwe2020, "119")).isNotNull()
.extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
.containsExactlyInAnyOrder(1L, 0L, 0L);
assertThat(findRuleInCweByYear(cwe2020, "999")).isNull();
+
+ SecurityStandardCategoryStatistics cwe2021 = cweTop25Reports.stream()
+ .filter(s -> s.getCategory().equals("2021"))
+ .findAny().get();
+ assertThat(cwe2021.getChildren()).hasSize(25);
+ assertThat(findRuleInCweByYear(cwe2021, "119")).isNotNull()
+ .extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
+ SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+ SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
+ .containsExactlyInAnyOrder(2L, 0L, 0L);
+ assertThat(findRuleInCweByYear(cwe2021, "89")).isNotNull()
+ .extracting(SecurityStandardCategoryStatistics::getVulnerabilities,
+ SecurityStandardCategoryStatistics::getToReviewSecurityHotspots,
+ SecurityStandardCategoryStatistics::getReviewedSecurityHotspots)
+ .containsExactlyInAnyOrder(0L, 1L, 0L);
+ assertThat(findRuleInCweByYear(cwe2021, "862")).isNull();
+ assertThat(findRuleInCweByYear(cwe2021, "999")).isNull();
}
private SecurityStandardCategoryStatistics findRuleInCweByYear(SecurityStandardCategoryStatistics statistics, String cweId) {