Quellcode durchsuchen

SONAR-13151 api/issues/search page size parameter negative value should not be allowed

tags/8.5.0.37579
Duarte Meneses vor 3 Jahren
Ursprung
Commit
cc10a68715
19 geänderte Dateien mit 69 neuen und 99 gelöschten Zeilen
  1. 6
    10
      server/sonar-server-common/src/main/java/org/sonar/server/es/SearchOptions.java
  2. 30
    33
      server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java
  3. 0
    6
      server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
  4. 2
    2
      server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java
  5. 3
    3
      server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
  6. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
  7. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
  8. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java
  9. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
  10. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java
  11. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java
  12. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
  13. 3
    3
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java
  14. 1
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java
  15. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java
  16. 2
    2
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveriesAction.java
  17. 4
    15
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
  18. 2
    2
      server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
  19. 0
    5
      server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/paging_with_page_size_to_minus_one.json

+ 6
- 10
server/sonar-server-common/src/main/java/org/sonar/server/es/SearchOptions.java Datei anzeigen

@@ -38,7 +38,7 @@ public class SearchOptions {

public static final int DEFAULT_OFFSET = 0;
public static final int DEFAULT_LIMIT = 10;
public static final int MAX_LIMIT = 500;
public static final int MAX_PAGE_SIZE = 500;
private static final int MAX_RETURNABLE_RESULTS = 10_000;

private int offset = DEFAULT_OFFSET;
@@ -63,15 +63,14 @@ public class SearchOptions {
}

/**
* Set offset and limit according to page approach. If pageSize is negative, then
* {@link #MAX_LIMIT} is used.
* Set offset and limit according to page approach
*/
public SearchOptions setPage(int page, int pageSize) {
checkArgument(page >= 1, "Page must be greater or equal to 1 (got " + page + ")");
setLimit(pageSize);
int lastResultIndex = page * pageSize;
checkArgument(lastResultIndex <= MAX_RETURNABLE_RESULTS, "Can return only the first %s results. %sth result asked.", MAX_RETURNABLE_RESULTS, lastResultIndex);
setLimit(pageSize);
setOffset((page * this.limit) - this.limit);
setOffset(lastResultIndex - pageSize);
return this;
}

@@ -90,11 +89,8 @@ public class SearchOptions {
* Sets the limit on the number of results to return.
*/
public SearchOptions setLimit(int limit) {
if (limit <= 0) {
this.limit = MAX_LIMIT;
} else {
this.limit = Math.min(limit, MAX_LIMIT);
}
checkArgument(limit > 0 && limit <= MAX_PAGE_SIZE, "Page size must be between 1 and " + MAX_PAGE_SIZE + " (got " + limit + ")");
this.limit = limit;
return this;
}


+ 30
- 33
server/sonar-server-common/src/test/java/org/sonar/server/es/SearchOptionsTest.java Datei anzeigen

@@ -27,7 +27,6 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.test.JsonAssert;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;

public class SearchOptionsTest {

@@ -64,43 +63,49 @@ public class SearchOptionsTest {
}

@Test
public void with_zero_page_size() {
SearchOptions options = new SearchOptions().setPage(1, 0);
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
assertThat(options.getOffset()).isEqualTo(0);
assertThat(options.getPage()).isEqualTo(1);
public void fail_if_page_is_not_strictly_positive() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page must be greater or equal to 1 (got 0)");
new SearchOptions().setPage(0, 10);
}

@Test
public void page_must_be_strictly_positive() {
try {
new SearchOptions().setPage(0, 10);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Page must be greater or equal to 1 (got 0)");
}
public void fail_if_ps_is_zero() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be between 1 and 500 (got 0)");
new SearchOptions().setPage(1, 0);
}

@Test
public void use_max_limit_if_negative() {
SearchOptions options = new SearchOptions().setPage(2, -1);
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
public void fail_if_ps_is_negative() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be between 1 and 500 (got -1)");
new SearchOptions().setPage(2, -1);
}

@Test
public void max_limit() {
SearchOptions options = new SearchOptions().setLimit(42);
assertThat(options.getLimit()).isEqualTo(42);
public void fail_if_ps_is_over_limit() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be between 1 and 500 (got 510)");
new SearchOptions().setPage(3, SearchOptions.MAX_PAGE_SIZE + 10);
}

@Test
public void fail_if_result_after_first_10_000() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Can return only the first 10000 results. 10500th result asked.");

options.setLimit(SearchOptions.MAX_LIMIT + 10);
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
underTest.setPage(21, 500);
}

@Test
public void max_page_size() {
SearchOptions options = new SearchOptions().setPage(3, SearchOptions.MAX_LIMIT + 10);
assertThat(options.getOffset()).isEqualTo(SearchOptions.MAX_LIMIT * 2);
assertThat(options.getLimit()).isEqualTo(SearchOptions.MAX_LIMIT);
public void max_limit() {
SearchOptions options = new SearchOptions().setLimit(42);
assertThat(options.getLimit()).isEqualTo(42);

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be between 1 and 500 (got 510)");
options.setLimit(SearchOptions.MAX_PAGE_SIZE + 10);
}

@Test
@@ -113,12 +118,4 @@ public class SearchOptionsTest {

JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}");
}

@Test
public void fail_if_result_after_first_10_000() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Can return only the first 10000 results. 10500th result asked.");

underTest.setPage(21, 500);
}
}

+ 0
- 6
server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java Datei anzeigen

@@ -1115,12 +1115,6 @@ public class RuleIndexTest {
results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getUuids()).hasSize(1);

// from 2 to 11 included
options.setOffset(2).setLimit(0);
results = underTest.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getUuids()).hasSize(1);
}

@Test

+ 2
- 2
server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQuery.java Datei anzeigen

@@ -31,7 +31,7 @@ import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.sonar.db.rule.RuleDefinitionDto;

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

/**
* @since 3.6
@@ -500,7 +500,7 @@ public class IssueQuery {

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

+ 3
- 3
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java Datei anzeigen

@@ -108,7 +108,7 @@ public class IssueIndexTest {
assertThat(result.getHits().getHits()).hasSize(5);
assertThat(result.getHits().getTotalHits()).isEqualTo(12);

result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(2).setLimit(0));
result = underTest.search(IssueQuery.builder().build(), new SearchOptions().setOffset(2).setLimit(10));
assertThat(result.getHits().getHits()).hasSize(10);
assertThat(result.getHits().getTotalHits()).isEqualTo(12);
}
@@ -125,8 +125,8 @@ public class IssueIndexTest {
indexIssues(issues.toArray(new IssueDoc[] {}));

IssueQuery.Builder query = IssueQuery.builder();
SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(Integer.MAX_VALUE));
assertThat(result.getHits().getHits()).hasSize(SearchOptions.MAX_LIMIT);
SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(500));
assertThat(result.getHits().getHits()).hasSize(SearchOptions.MAX_PAGE_SIZE);
}

@Test

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java Datei anzeigen

@@ -57,7 +57,7 @@ import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.SUBVIEW;
import static org.sonar.api.resources.Qualifiers.VIEW;
import static org.sonar.core.util.stream.MoreCollectors.toHashSet;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
@@ -89,7 +89,7 @@ public class SearchAction implements ComponentsWsAction {
WebService.NewAction action = context.createAction(ACTION_SEARCH)
.setSince("6.3")
.setDescription("Search for components")
.addPagingParams(100, MAX_LIMIT)
.addPagingParams(100, MAX_PAGE_SIZE)
.setChangelog(
new Change("8.4", "Param 'language' has been removed"),
new Change("8.4", String.format("The use of 'DIR','FIL','UTS' as values for parameter '%s' is no longer supported", PARAM_QUALIFIERS)),

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java Datei anzeigen

@@ -91,7 +91,7 @@ import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.issue.AbstractChangeTagsAction.TAGS_PARAMETER;
import static org.sonar.server.issue.AssignAction.ASSIGNEE_PARAMETER;
import static org.sonar.server.issue.CommentAction.COMMENT_KEY;
@@ -356,7 +356,7 @@ public class BulkChangeAction implements IssuesWsAction {
this.propertiesByActions = toPropertiesByActions(request);

List<String> issueKeys = request.mandatoryParamAsStrings(PARAM_ISSUES);
checkArgument(issueKeys.size() <= MAX_LIMIT, "Number of issues is limited to %s", MAX_LIMIT);
checkArgument(issueKeys.size() <= MAX_PAGE_SIZE, "Number of issues is limited to %s", MAX_PAGE_SIZE);
List<IssueDto> allIssues = dbClient.issueDao().selectByKeys(dbSession, issueKeys)
.stream()
.filter(issueDto -> SECURITY_HOTSPOT.getDbConstant() != issueDto.getType())

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java Datei anzeigen

@@ -76,7 +76,7 @@ import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW;
import static org.sonar.api.server.ws.WebService.Param.FACETS;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.issue.index.IssueIndex.FACET_ASSIGNED_TO_ME;
import static org.sonar.server.issue.index.IssueIndex.FACET_PROJECTS;
import static org.sonar.server.issue.index.IssueQuery.SORT_BY_ASSIGNEE;
@@ -211,7 +211,7 @@ public class SearchAction implements IssuesWsAction {
new Change("5.5", "response field 'debt' is renamed 'effort'"))
.setResponseExample(getClass().getResource("search-example.json"));

action.addPagingParams(100, MAX_LIMIT);
action.addPagingParams(100, MAX_PAGE_SIZE);
action.createParam(FACETS)
.setDescription("Comma-separated list of the facets to be computed. No facet is computed by default.")
.setPossibleValues(SUPPORTED_FACETS);

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java Datei anzeigen

@@ -44,7 +44,7 @@ import org.sonar.server.es.SearchOptions;
import org.sonar.server.user.UserSession;

import static org.sonar.server.component.ComponentFinder.ParamNames.PROJECT_ID_AND_KEY;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.measure.custom.ws.CustomMeasureValidator.checkPermissions;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;

@@ -74,7 +74,7 @@ public class SearchAction implements CustomMeasuresWsAction {
.setSince("5.2")
.setDeprecatedSince("7.4")
.addFieldsParam(CustomMeasureJsonWriter.OPTIONAL_FIELDS)
.addPagingParams(100, MAX_LIMIT)
.addPagingParams(100, MAX_PAGE_SIZE)
.setResponseExample(getClass().getResource("example-search.json"))
.setHandler(this);


+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/metric/ws/SearchAction.java Datei anzeigen

@@ -34,7 +34,7 @@ import org.sonar.db.metric.MetricDto;
import org.sonar.server.es.SearchOptions;

import static com.google.common.collect.Sets.newHashSet;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.metric.ws.MetricJsonWriter.FIELD_ID;
import static org.sonar.server.metric.ws.MetricJsonWriter.FIELD_KEY;

@@ -61,7 +61,7 @@ public class SearchAction implements MetricsWsAction {
.setSince("5.2")
.setDescription("Search for metrics")
.setResponseExample(getClass().getResource("example-search.json"))
.addPagingParams(100, MAX_LIMIT)
.addPagingParams(100, MAX_PAGE_SIZE)
.setChangelog(
new Change("8.4", "Field 'id' in the response is deprecated"),
new Change("7.7", "Field 'custom' in the response is deprecated"))

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/organization/ws/SearchMembersAction.java Datei anzeigen

@@ -52,7 +52,7 @@ import static com.google.common.base.Strings.emptyToNull;
import static java.util.Optional.ofNullable;
import static org.sonar.api.server.ws.WebService.SelectionMode.SELECTED;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.organization.ws.OrganizationsWsSupport.PARAM_ORGANIZATION;
import static org.sonar.server.exceptions.NotFoundException.checkFoundWithOptional;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
@@ -86,7 +86,7 @@ public class SearchMembersAction implements OrganizationsWsAction {

action.createSearchQuery("orwe", "names", "logins")
.setMinimumLength(2);
action.addPagingParams(50, MAX_LIMIT);
action.addPagingParams(50, MAX_PAGE_SIZE);

action.createParam(Param.SELECTED)
.setDescription("Depending on the value, show only selected items (selected=selected) or deselected items (selected=deselected).")

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java Datei anzeigen

@@ -48,7 +48,7 @@ import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
import static org.sonar.core.util.stream.MoreCollectors.toSet;
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SINCE;
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO;

@@ -78,7 +78,7 @@ public class ChangelogAction implements QProfileWsAction {

QProfileReference.defineParams(wsAction, languages);

wsAction.addPagingParams(50, MAX_LIMIT);
wsAction.addPagingParams(50, MAX_PAGE_SIZE);

wsAction.createParam(PARAM_SINCE)
.setDescription("Start date for the changelog. <br>" +

+ 3
- 3
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java Datei anzeigen

@@ -63,7 +63,7 @@ import static org.sonar.api.server.ws.WebService.Param.FACETS;
import static org.sonar.api.server.ws.WebService.Param.FIELDS;
import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.rule.index.RuleIndex.ALL_STATUSES_EXCEPT_REMOVED;
import static org.sonar.server.rule.index.RuleIndex.FACET_ACTIVE_SEVERITIES;
import static org.sonar.server.rule.index.RuleIndex.FACET_CWE;
@@ -129,7 +129,7 @@ public class SearchAction implements RulesWsAction {
@Override
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(ACTION)
.addPagingParams(100, MAX_LIMIT)
.addPagingParams(100, MAX_PAGE_SIZE)
.setHandler(this)
.setChangelog(new Change("7.1", "The field 'scope' has been added to the response"))
.setChangelog(new Change("7.1", "The field 'scope' has been added to the 'f' parameter"))
@@ -227,7 +227,7 @@ public class SearchAction implements RulesWsAction {
context.addFacets(request.getFacets());
}
if (pageSize < 1) {
context.setPage(Integer.parseInt(request.getP()), 0).setLimit(MAX_LIMIT);
context.setPage(Integer.parseInt(request.getP()), 0).setLimit(MAX_PAGE_SIZE);
} else {
context.setPage(Integer.parseInt(request.getP()), pageSize);
}

+ 1
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java Datei anzeigen

@@ -54,7 +54,6 @@ import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.Users.SearchWsResponse.Groups;
import static org.sonarqube.ws.Users.SearchWsResponse.ScmAccounts;
@@ -101,7 +100,7 @@ public class SearchAction implements UsersWsAction {
.setHandler(this)
.setResponseExample(getClass().getResource("search-example.json"));

action.addPagingParams(50, MAX_LIMIT);
action.addPagingParams(50, SearchOptions.MAX_PAGE_SIZE);

action.createParam(TEXT_QUERY)
.setMinimumLength(2)

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/usergroups/ws/SearchAction.java Datei anzeigen

@@ -44,7 +44,7 @@ import static java.util.Optional.ofNullable;
import static org.apache.commons.lang.StringUtils.defaultIfBlank;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.usergroups.ws.GroupWsSupport.PARAM_ORGANIZATION_KEY;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.UserGroups.Group;
@@ -78,7 +78,7 @@ public class SearchAction implements UserGroupsWsAction {
.setResponseExample(getClass().getResource("search-example.json"))
.setSince("5.2")
.addFieldsParam(ALL_FIELDS)
.addPagingParams(100, MAX_LIMIT)
.addPagingParams(100, MAX_PAGE_SIZE)
.addSearchQuery("sonar-users", "names")
.setChangelog(
new Change("8.4", "Field 'id' in the response is deprecated. Format changes from integer to string."),

+ 2
- 2
server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/WebhookDeliveriesAction.java Datei anzeigen

@@ -48,7 +48,7 @@ import static org.sonar.api.server.ws.WebService.Param.PAGE;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.utils.Paging.offset;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
import static org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE;
import static org.sonar.server.webhook.ws.WebhookWsSupport.copyDtoToProtobuf;
import static org.sonar.server.ws.WsUtils.writeProtobuf;

@@ -92,7 +92,7 @@ public class WebhookDeliveriesAction implements WebhooksWsAction {
"auto-generated value that can be obtained through api/webhooks/create or api/webhooks/list")
.setExampleValue(UUID_EXAMPLE_02);

action.addPagingParamsSince(10, MAX_LIMIT, "7.1");
action.addPagingParamsSince(10, MAX_PAGE_SIZE, "7.1");
}

@Override

+ 4
- 15
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java Datei anzeigen

@@ -450,7 +450,7 @@ public class SearchActionTest {
ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY"));
indexPermissions();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY"));
for (int i = 0; i < SearchOptions.MAX_LIMIT + 1; i++) {
for (int i = 0; i < SearchOptions.MAX_PAGE_SIZE + 1; i++) {
IssueDto issue = newDto(rule, file, project).setAssigneeUuid(null);
dbClient.issueDao().insert(session, issue);
}
@@ -1038,23 +1038,12 @@ public class SearchActionTest {

@Test
public void paging_with_page_size_to_minus_one() {
RuleDto rule = newIssueRule();
OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org-1"));
ComponentDto project = db.components().insertComponent(ComponentTesting.newPublicProjectDto(organization, "PROJECT_ID").setDbKey("PROJECT_KEY"));
indexPermissions();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setDbKey("FILE_KEY"));
for (int i = 0; i < 12; i++) {
IssueDto issue = newDto(rule, file, project);
dbClient.issueDao().insert(session, issue);
}
session.commit();
indexIssues();

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be between 1 and 500 (got -1)");
ws.newRequest()
.setParam(WebService.Param.PAGE, "1")
.setParam(WebService.Param.PAGE_SIZE, "-1")
.execute()
.assertJson(this.getClass(), "paging_with_page_size_to_minus_one.json");
.execute();
}

@Test

+ 2
- 2
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java Datei anzeigen

@@ -707,7 +707,7 @@ public class QProfileRuleImplTest {

@Test
public void bulk_activation() {
int bulkSize = SearchOptions.MAX_LIMIT + 10 + new Random().nextInt(100);
int bulkSize = SearchOptions.MAX_PAGE_SIZE + 10 + new Random().nextInt(100);
String language = randomAlphanumeric(10);
String repositoryKey = randomAlphanumeric(10);
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(language));
@@ -734,7 +734,7 @@ public class QProfileRuleImplTest {

@Test
public void bulk_deactivation() {
int bulkSize = SearchOptions.MAX_LIMIT + 10 + new Random().nextInt(100);
int bulkSize = SearchOptions.MAX_PAGE_SIZE + 10 + new Random().nextInt(100);
String language = randomAlphanumeric(10);
String repositoryKey = randomAlphanumeric(10);
QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(language));

+ 0
- 5
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/issue/ws/SearchActionTest/paging_with_page_size_to_minus_one.json Datei anzeigen

@@ -1,5 +0,0 @@
{
"total": 12,
"p": 1,
"ps": 500
}

Laden…
Abbrechen
Speichern