diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2024-07-24 11:39:07 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-26 20:02:47 +0000 |
commit | ebb080570d77aa6a8dbc0bd360a730e7015342ba (patch) | |
tree | 3480700fd95b93fcbbec1ccee1ab9dcf01e89035 /server/sonar-webserver-webapi | |
parent | ba213d1635965f61a599157e8fa95a4d9c42ffe9 (diff) | |
download | sonarqube-ebb080570d77aa6a8dbc0bd360a730e7015342ba.tar.gz sonarqube-ebb080570d77aa6a8dbc0bd360a730e7015342ba.zip |
SONAR-22543 Index new CASA security standard
Diffstat (limited to 'server/sonar-webserver-webapi')
4 files changed, 108 insertions, 5 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java index a6cbbd43ef2..893a8214476 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java @@ -114,6 +114,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.issue.IssueTesting.newCodeReferenceIssue; import static org.sonar.db.issue.IssueTesting.newIssue; import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CASA; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_STIG_ASD_V5R3; @SuppressWarnings("ALL") @@ -171,6 +172,7 @@ public class SearchActionIT { WebService.Param owasAsvs40Param = actionTester.getDef().param(PARAM_OWASP_ASVS_40); WebService.Param owaspTop10Param = actionTester.getDef().param(PARAM_OWASP_TOP_10_2017); WebService.Param stigAsdV5R3 = actionTester.getDef().param(PARAM_STIG_ASD_V5R3); + WebService.Param casa = actionTester.getDef().param(PARAM_CASA); WebService.Param sansTop25Param = actionTester.getDef().param(PARAM_SANS_TOP_25); WebService.Param sonarsourceSecurityParam = actionTester.getDef().param(PARAM_SONARSOURCE_SECURITY); WebService.Param filesParam = actionTester.getDef().param(PARAM_FILES); @@ -191,6 +193,8 @@ public class SearchActionIT { assertThat(owaspTop10Param.isRequired()).isFalse(); assertThat(stigAsdV5R3).isNotNull(); assertThat(stigAsdV5R3.isRequired()).isFalse(); + assertThat(casa).isNotNull(); + assertThat(casa.isRequired()).isFalse(); assertThat(sansTop25Param).isNotNull(); assertThat(sansTop25Param.isRequired()).isFalse(); assertThat(sonarsourceSecurityParam).isNotNull(); @@ -1571,6 +1575,37 @@ public class SearchActionIT { } @Test + public void executeProtobuf_WhenHotspotHasCwe_shoultReturnExpectedHotspotOnCasaParam() { + ProjectData projectData = dbTester.components().insertPublicProject(); + ComponentDto project = projectData.getMainBranchComponent(); + + userSessionRule.registerProjects(projectData.getProjectDto()); + indexPermissions(); + ComponentDto file = dbTester.components().insertComponent(newFileDto(project)); + RuleDto rule1 = newRule(SECURITY_HOTSPOT); + RuleDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(Set.of("cwe:310"))); + RuleDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(Set.of("cwe:639"))); + insertHotspot(project, file, rule1); + insertHotspot(project, file, rule2); + IssueDto hotspot3 = insertHotspot(project, file, rule3); + indexIssues(); + + SearchWsResponse response = newRequest(project).setParam(PARAM_CASA, "4.1.2") + .executeProtobuf(SearchWsResponse.class); + + assertThat(response.getHotspotsList()) + .extracting(SearchWsResponse.Hotspot::getKey) + .containsExactly(hotspot3.getKey()); + + response = newRequest(project).setParam(PARAM_CASA, "4") + .executeProtobuf(SearchWsResponse.class); + + assertThat(response.getHotspotsList()) + .extracting(SearchWsResponse.Hotspot::getKey) + .containsExactly(hotspot3.getKey()); + } + + @Test public void returns_hotspots_with_specified_pciDss_category() { ProjectData projectData = dbTester.components().insertPublicProject(); ComponentDto project = projectData.getMainBranchComponent(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java index 9d9818ec646..516107ac4c8 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java @@ -1767,11 +1767,56 @@ public class SearchActionIT { SearchWsResponse result = ws.newRequest() .setParam("stig-ASD_V5R3", "V-222402") + .setParam(FACETS, "stig-ASD_V5R3") .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()) .extracting(Issue::getKey) .containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey()); + + assertThat(result.getFacets().getFacets(0).getValuesList()) + .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) + .containsExactlyInAnyOrder(tuple("V-222402", 2L), tuple("V-222403", 2L), tuple("V-222404", 2L)); + } + + @Test + public void only_vulnerabilities_are_returned_by_casa() { + ComponentDto project = db.components().insertPublicProject().getMainBranchComponent(); + ComponentDto file = db.components().insertComponent(newFileDto(project)); + Consumer<RuleDto> ruleConsumer = ruleDefinitionDto -> ruleDefinitionDto + .setSecurityStandards(Sets.newHashSet("cwe:20", "cwe:564", "cwe:639", "cwe:326")) + .setSystemTags(Sets.newHashSet("bad-practice", "cwe", "sans-top25-insecure", "sql")); + Consumer<IssueDto> issueConsumer = issueDto -> issueDto.setTags(Sets.newHashSet("bad-practice", "cwe", "sans-top25-insecure", "sql")); + RuleDto hotspotRule = db.rules().insertHotspotRule(ruleConsumer); + db.issues().insertHotspot(hotspotRule, project, file, issueConsumer); + RuleDto issueRule = db.rules().insertIssueRule(ruleConsumer); + IssueDto issueDto1 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); + IssueDto issueDto2 = db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(RuleType.VULNERABILITY)); + db.issues().insertIssue(issueRule, project, file, issueConsumer, issueDto -> issueDto.setType(CODE_SMELL)); + indexPermissionsAndIssues(); + + SearchWsResponse result = ws.newRequest() + .setParam("casa", "4.1.2") + .setParam(FACETS, "casa") + .executeProtobuf(SearchWsResponse.class); + + assertThat(result.getIssuesList()) + .extracting(Issue::getKey) + .containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey()); + + assertThat(result.getFacets().getFacets(0).getValuesList()) + .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) + .containsExactlyInAnyOrder(tuple("4.1.2", 2L), tuple("4.2.1", 2L), tuple("6.2.3", 2L), + tuple("6.2.4", 2L), tuple("6.2.7", 2L), tuple("9.1.2", 2L)); + + result = ws.newRequest() + .setParam("casa", "4") + .executeProtobuf(SearchWsResponse.class); + + assertThat(result.getIssuesList()) + .as("We should be able to search with only the prefix '4'") + .extracting(Issue::getKey) + .containsExactlyInAnyOrder(issueDto1.getKey(), issueDto2.getKey()); } @Test @@ -2108,7 +2153,7 @@ public class SearchActionIT { "additionalFields", "asc", "assigned", "assignees", "author", "components", "branch", "pullRequest", "createdAfter", "createdAt", "createdBefore", "createdInLast", "directories", "facets", "files", "issues", "scopes", "languages", "onComponentOnly", "p", "projects", "ps", "resolutions", "resolved", "rules", "s", "severities", "statuses", "tags", "types", "pciDss-3.2", "pciDss-4.0", "owaspAsvs-4.0", - "owaspAsvsLevel", "owaspTop10", "owaspTop10-2021", "stig-ASD_V5R3", "sansTop25", "cwe", "sonarsourceSecurity", "timeZone", "inNewCodePeriod", "codeVariants", + "owaspAsvsLevel", "owaspTop10", "owaspTop10-2021", "stig-ASD_V5R3", "casa", "sansTop25", "cwe", "sonarsourceSecurity", "timeZone", "inNewCodePeriod", "codeVariants", "cleanCodeAttributeCategories", "impactSeverities", "impactSoftwareQualities", "issueStatuses", "fixedInPullRequest", "prioritizedRule"); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 09b0cefe680..9ccf68d9498 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -111,6 +111,7 @@ public class SearchAction implements HotspotsWsAction { private static final String PARAM_OWASP_TOP_10_2017 = "owaspTop10"; private static final String PARAM_OWASP_TOP_10_2021 = "owaspTop10-2021"; private static final String PARAM_STIG_ASD_V5R3 = "stig-ASD_V5R3"; + private static final String PARAM_CASA = "casa"; /** * @deprecated SansTop25 report is outdated, it has been completely deprecated in version 10.0 and will be removed from version 11.0 */ @@ -153,6 +154,7 @@ public class SearchAction implements HotspotsWsAction { Set<String> owasp2017Top10 = setFromList(request.paramAsStrings(PARAM_OWASP_TOP_10_2017)); Set<String> owasp2021Top10 = setFromList(request.paramAsStrings(PARAM_OWASP_TOP_10_2021)); Set<String> stigAsdV5R3 = setFromList(request.paramAsStrings(PARAM_STIG_ASD_V5R3)); + Set<String> casa = setFromList(request.paramAsStrings(PARAM_CASA)); Set<String> sansTop25 = setFromList(request.paramAsStrings(PARAM_SANS_TOP_25)); Set<String> sonarsourceSecurity = setFromList(request.paramAsStrings(PARAM_SONARSOURCE_SECURITY)); Set<String> cwes = setFromList(request.paramAsStrings(PARAM_CWE)); @@ -162,7 +164,7 @@ public class SearchAction implements HotspotsWsAction { request.mandatoryParamAsInt(PAGE), request.mandatoryParamAsInt(PAGE_SIZE), request.param(PARAM_PROJECT), request.param(PARAM_BRANCH), request.param(PARAM_PULL_REQUEST), hotspotKeys, request.param(PARAM_STATUS), request.param(PARAM_RESOLUTION), request.paramAsBoolean(PARAM_IN_NEW_CODE_PERIOD), request.paramAsBoolean(PARAM_ONLY_MINE), request.paramAsInt(PARAM_OWASP_ASVS_LEVEL), - pciDss32, pciDss40, owaspAsvs40, owasp2017Top10, owasp2021Top10, stigAsdV5R3, sansTop25, sonarsourceSecurity, cwes, files); + pciDss32, pciDss40, owaspAsvs40, owasp2017Top10, owasp2021Top10, stigAsdV5R3, casa, sansTop25, sonarsourceSecurity, cwes, files); } @Override @@ -208,6 +210,9 @@ public class SearchAction implements HotspotsWsAction { if (!wsRequest.getStigAsdV5R3().isEmpty()) { builder.stigAsdR5V3(wsRequest.getStigAsdV5R3()); } + if (!wsRequest.getCasa().isEmpty()) { + builder.casa(wsRequest.getCasa()); + } if (!wsRequest.getSansTop25().isEmpty()) { builder.sansTop25(wsRequest.getSansTop25()); } @@ -230,7 +235,7 @@ public class SearchAction implements HotspotsWsAction { + "When issue indexing is in progress returns 503 service unavailable HTTP code.") .setSince("8.1") .setChangelog( - new Change("10.7", format("Added parameter '%s'", PARAM_STIG_ASD_V5R3)), + new Change("10.7", format("Added parameter '%s' and '%s'", PARAM_STIG_ASD_V5R3, PARAM_CASA)), new Change("10.2", format("Parameter '%s' renamed to '%s'", PARAM_PROJECT_KEY, PARAM_PROJECT)), new Change("10.0", "Parameter 'sansTop25' is deprecated"), new Change("9.6", "Added parameters 'pciDss-3.2' and 'pciDss-4.0"), @@ -315,6 +320,9 @@ public class SearchAction implements HotspotsWsAction { action.createParam(PARAM_STIG_ASD_V5R3) .setDescription("Comma-separated list of STIG V5R3 lowercase categories.") .setSince("10.7"); + action.createParam(PARAM_CASA) + .setDescription("Comma-separated list of CASA categories.") + .setSince("10.7"); action.createParam(PARAM_SANS_TOP_25) .setDescription("Comma-separated list of SANS Top 25 categories.") .setDeprecatedSince("10.0") @@ -624,6 +632,7 @@ public class SearchAction implements HotspotsWsAction { private final Set<String> owaspTop10For2017; private final Set<String> owaspTop10For2021; private final Set<String> stigAsdV5R3; + private final Set<String> casa; private final Set<String> sansTop25; private final Set<String> sonarsourceSecurity; private final Set<String> cwe; @@ -633,7 +642,7 @@ public class SearchAction implements HotspotsWsAction { @Nullable String projectKey, @Nullable String branch, @Nullable String pullRequest, Set<String> hotspotKeys, @Nullable String status, @Nullable String resolution, @Nullable Boolean inNewCodePeriod, @Nullable Boolean onlyMine, @Nullable Integer owaspAsvsLevel, Set<String> pciDss32, Set<String> pciDss40, Set<String> owaspAsvs40, - Set<String> owaspTop10For2017, Set<String> owaspTop10For2021, Set<String> stigAsdV5R3, Set<String> sansTop25, Set<String> sonarsourceSecurity, + Set<String> owaspTop10For2017, Set<String> owaspTop10For2021, Set<String> stigAsdV5R3, Set<String> casa, Set<String> sansTop25, Set<String> sonarsourceSecurity, Set<String> cwe, @Nullable Set<String> files) { this.page = page; this.index = index; @@ -652,6 +661,7 @@ public class SearchAction implements HotspotsWsAction { this.owaspTop10For2017 = owaspTop10For2017; this.owaspTop10For2021 = owaspTop10For2021; this.stigAsdV5R3 = stigAsdV5R3; + this.casa = casa; this.sansTop25 = sansTop25; this.sonarsourceSecurity = sonarsourceSecurity; this.cwe = cwe; @@ -726,6 +736,10 @@ public class SearchAction implements HotspotsWsAction { return stigAsdV5R3; } + public Set<String> getCasa() { + return casa; + } + public Set<String> getSansTop25() { return sansTop25; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index b0fa2213b27..9caf366a7e5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -99,6 +99,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNED; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_AUTHOR; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_BRANCH; +import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CASA; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CLEAN_CODE_ATTRIBUTE_CATEGORIES; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CODE_VARIANTS; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; @@ -166,6 +167,7 @@ public class SearchAction implements IssuesWsAction { PARAM_OWASP_TOP_10, PARAM_OWASP_TOP_10_2021, PARAM_STIG_ASD_V5R3, + PARAM_CASA, PARAM_SANS_TOP_25, PARAM_CWE, PARAM_CREATED_AT, @@ -215,6 +217,8 @@ public class SearchAction implements IssuesWsAction { + "<br/>When issue indexing is in progress returns 503 service unavailable HTTP code.") .setSince("3.6") .setChangelog( + new Change("10.7", format(NEW_FACET_ADDED_MESSAGE, PARAM_CASA)), + new Change("10.7", format(NEW_PARAM_ADDED_MESSAGE, PARAM_CASA)), new Change("10.7", format(NEW_FACET_ADDED_MESSAGE, PARAM_STIG_ASD_V5R3)), new Change("10.7", format(NEW_PARAM_ADDED_MESSAGE, PARAM_STIG_ASD_V5R3)), new Change("10.6", format(NEW_FACET_ADDED_MESSAGE, PARAM_PRIORITIZED_RULE)), @@ -377,7 +381,10 @@ public class SearchAction implements IssuesWsAction { .setPossibleValues("a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"); action.createParam(PARAM_STIG_ASD_V5R3) .setDescription("Comma-separated list of STIG V5R3 categories.") - .setSince("9.4"); + .setSince("10.7"); + action.createParam(PARAM_CASA) + .setDescription("Comma-separated list of CASA categories.") + .setSince("10.7"); action.createParam(PARAM_SANS_TOP_25) .setDescription("Comma-separated list of SANS Top 25 categories.") .setDeprecatedSince("10.0") @@ -602,6 +609,7 @@ public class SearchAction implements IssuesWsAction { addMandatoryValuesToFacet(facets, PARAM_OWASP_TOP_10, request.getOwaspTop10()); addMandatoryValuesToFacet(facets, PARAM_OWASP_TOP_10_2021, request.getOwaspTop10For2021()); addMandatoryValuesToFacet(facets, PARAM_STIG_ASD_V5R3, request.getStigAsdV5R3()); + addMandatoryValuesToFacet(facets, PARAM_CASA, request.getCasa()); addMandatoryValuesToFacet(facets, PARAM_SANS_TOP_25, request.getSansTop25()); addMandatoryValuesToFacet(facets, PARAM_CWE, request.getCwe()); addMandatoryValuesToFacet(facets, PARAM_SONARSOURCE_SECURITY, request.getSonarsourceSecurity()); @@ -690,6 +698,7 @@ public class SearchAction implements IssuesWsAction { .setOwaspTop10(request.paramAsStrings(PARAM_OWASP_TOP_10)) .setOwaspTop10For2021(request.paramAsStrings(PARAM_OWASP_TOP_10_2021)) .setStigAsdV5R3(request.paramAsStrings(PARAM_STIG_ASD_V5R3)) + .setCasa(request.paramAsStrings(PARAM_CASA)) .setSansTop25(request.paramAsStrings(PARAM_SANS_TOP_25)) .setCwe(request.paramAsStrings(PARAM_CWE)) .setSonarsourceSecurity(request.paramAsStrings(PARAM_SONARSOURCE_SECURITY)) |