]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21259 allowing number of issues that will be fixed to be greater than 500 in...
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Mon, 15 Jan 2024 15:43:15 +0000 (16:43 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 17 Jan 2024 20:02:44 +0000 (20:02 +0000)
server/sonar-server-common/src/main/java/org/sonar/server/issue/SearchRequest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/SearchRequestTest.java
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java

index d146dfd071fecf00c341cf22d0bd1f8d8bae0f9d..1fde69680356e08ea08376e1828f40d7676b1edf 100644 (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;
   }
index 6295ee9fd06bfd0080d36bb066af64f20b99681b..be5b755ffb1c8aaed94692635f0d5d9c575b3b4a 100644 (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)");
+  }
 }
index 5da45db5877429812a49a0824b38decd6959b21a..b712c5be6cb2f816c4bb154a3daff16751b5da93 100644 (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);
     }
 
index 12872d0744bce730734ac35c055df7427440535d..b05627c6cb367509551a5e2ffab1fcb245b77181 100644 (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();
index ca381ca6943c825730786ee5fc14e8d6c049f882..a1aa8da0a623b60aef55e81e990a82cdfa62e01d 100644 (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()) {