Browse Source

SONAR-21259 allowing number of issues that will be fixed to be greater than 500 in api/issues/search

tags/10.4.0.87286
lukasz-jarocki-sonarsource 5 months ago
parent
commit
c40c7ea750

+ 6
- 0
server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java View File

@@ -26,6 +26,9 @@ import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;

public class SearchRequest {
private List<String> additionalFields;
private Boolean asc;
@@ -227,6 +230,9 @@ public class SearchRequest {
}

public SearchRequest setIssues(@Nullable List<String> issues) {
if (issues != null) {
checkArgument(issues.size() <= MAX_PAGE_SIZE, "Number of issue keys must be less than " + MAX_PAGE_SIZE + " (got " + issues.size() + ")");
}
this.issues = issues;
return this;
}

+ 10
- 0
server/sonar-server-common/src/test/java/org/sonar/server/issue/SearchRequestTest.java View File

@@ -25,6 +25,7 @@ import org.junit.Test;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class SearchRequestTest {

@@ -104,4 +105,13 @@ public class SearchRequestTest {

assertThat(underTest.getScopes()).isNull();
}

@Test
public void setIssues_whenSizeOfTheListIsGreaterThan500_throwException() {
List<String> issues = asList(new String[501]);
SearchRequest underTest = new SearchRequest();
assertThatThrownBy(() -> underTest.setIssues(issues))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Number of issue keys must be less than 500 (got 501)");
}
}

+ 0
- 6
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java View File

@@ -31,9 +31,6 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.db.rule.RuleDto;

import static com.google.common.base.Preconditions.checkArgument;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;

/**
* @since 3.6
*/
@@ -628,9 +625,6 @@ public class IssueQuery {
}

public IssueQuery build() {
if (issueKeys != null) {
checkArgument(issueKeys.size() <= MAX_PAGE_SIZE, "Number of issue keys must be less than " + MAX_PAGE_SIZE + " (got " + issueKeys.size() + ")");
}
return new IssueQuery(this);
}


+ 14
- 0
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java View File

@@ -1713,6 +1713,20 @@ public class SearchActionIT {
.containsExactly(hotspot3.getKey());
}

@Test
public void search_whenMoreThan500KeysPassed_throwException() {
ProjectData projectData = dbTester.components().insertPublicProject();
ComponentDto project = projectData.getMainBranchComponent();
userSessionRule.registerProjects(projectData.getProjectDto());

assertThatThrownBy(() -> newRequest(project).setParam(PARAM_HOTSPOTS, String.join(",", IntStream.range(0, 600).mapToObj(i -> "" + i)
.collect(toSet())))
.execute())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Number of issue keys must be less than 500 (got 600)");

}

@Test
public void returns_hotspots_with_specified_files() {
ProjectData projectData = dbTester.components().insertPublicProject();

+ 5
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java View File

@@ -84,6 +84,7 @@ import static org.sonar.api.utils.DateUtils.longToDate;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_INSECURE_INTERACTION;
import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_POROUS_DEFENSES;
import static org.sonar.server.security.SecurityStandards.SANS_TOP_25_RISKY_RESOURCE;
@@ -386,8 +387,10 @@ public class SearchAction implements HotspotsWsAction {
addMainBranchFilter(projectOrAppAndBranch.getBranch(), builder);
}

if (!wsRequest.getHotspotKeys().isEmpty()) {
builder.issueKeys(wsRequest.getHotspotKeys());
Set<String> hotspotKeys = wsRequest.getHotspotKeys();
if (!hotspotKeys.isEmpty()) {
checkArgument(hotspotKeys.size() <= MAX_PAGE_SIZE, "Number of issue keys must be less than " + MAX_PAGE_SIZE + " (got " + hotspotKeys.size() + ")");
builder.issueKeys(hotspotKeys);
}

if (!wsRequest.getFiles().isEmpty()) {

Loading…
Cancel
Save