diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/group/GroupsIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/group/GroupsIT.java new file mode 100644 index 0000000000..b3b0b27a32 --- /dev/null +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/group/GroupsIT.java @@ -0,0 +1,32 @@ +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +package com.google.gerrit.acceptance.rest.group; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.gerrit.acceptance.AbstractDaemonTest; +import com.google.gerrit.acceptance.RestResponse; + +import org.junit.Test; + +public class GroupsIT extends AbstractDaemonTest { + @Test + public void invalidQueryOptions() throws Exception { + RestResponse r = adminRestSession.put("/groups/?query=foo&query2=bar"); + r.assertBadRequest(); + assertThat(r.getEntityContent()) + .isEqualTo("\"query\" and \"query2\" options are mutually exclusive"); + } +} diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NeedsParams.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NeedsParams.java index 8eb3413c20..213ae13c25 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NeedsParams.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/restapi/NeedsParams.java @@ -28,5 +28,5 @@ public interface NeedsParams { * * @param params the request parameter */ - void setParams(Multimap params); + void setParams(Multimap params) throws RestApiException; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/group/GroupsCollection.java b/gerrit-server/src/main/java/com/google/gerrit/server/group/GroupsCollection.java index efc0046a9c..17d336670a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/group/GroupsCollection.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/group/GroupsCollection.java @@ -22,6 +22,7 @@ import com.google.gerrit.common.errors.NoSuchGroupException; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.AcceptsCreate; import com.google.gerrit.extensions.restapi.AuthException; +import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.NeedsParams; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; @@ -69,7 +70,13 @@ public class GroupsCollection implements } @Override - public void setParams(Multimap params) { + public void setParams(Multimap params) + throws BadRequestException { + if (params.containsKey("query") && params.containsKey("query2")) { + throw new BadRequestException( + "\"query\" and \"query2\" options are mutually exclusive"); + } + // The --query2 option is defined in QueryGroups this.hasQuery2 = params.containsKey("query2"); }