import org.sonarqube.ws.WsUsers.GroupsWsResponse.Group;
import org.sonarqube.ws.client.user.GroupsRequest;
+import static com.google.common.base.Preconditions.checkArgument;
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.server.ws.WebService.Param.SELECTED;
public class GroupsAction implements UsersWsAction {
+ private static final int MAX_PAGE_SIZE = 500;
+
private final DbClient dbClient;
private final UserSession userSession;
private final DefaultOrganizationProvider defaultOrganizationProvider;
}
private static GroupsRequest toGroupsRequest(Request request) {
+ int pageSize = request.mandatoryParamAsInt(PAGE_SIZE);
+ checkArgument(pageSize <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %s", PAGE_SIZE, MAX_PAGE_SIZE);
return GroupsRequest.builder()
.setLogin(request.mandatoryParam(PARAM_LOGIN))
.setOrganization(request.param(PARAM_ORGANIZATION))
.setSelected(request.mandatoryParam(SELECTED))
.setQuery(request.param(TEXT_QUERY))
.setPage(request.mandatoryParamAsInt(PAGE))
- .setPageSize(request.mandatoryParamAsInt(PAGE_SIZE))
+ .setPageSize(pageSize)
.build();
}
call(ws.newRequest().setParam("login", USER_LOGIN).setParam("organization", "unknown"));
}
+ @Test
+ public void fail_when_page_size_is_greater_than_500() throws Exception {
+ UserDto user = insertUser();
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("The 'ps' parameter must be less than 500");
+
+ call(ws.newRequest()
+ .setParam("login", user.getLogin())
+ .setParam(Param.PAGE_SIZE, "501")
+ );
+ }
+
@Test
public void fail_on_missing_permission() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();