Move CheckAccess endpoint into /projects/
This ensures proper load balancing on multi-master setups with repo-affine request routing. Since the original REST endpoint was added by Icf74b0fc40 which is not part of any release yet, this change will not break backwards compatibility. Change-Id: Ie1be1173ff8ab2a4c79e568834c6a1d182d79883
This commit is contained in:

committed by
Changcheng Xiao

parent
2def676ee6
commit
d1ed08d46a
@@ -12,24 +12,24 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.account;
|
||||
package com.google.gerrit.acceptance.api.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.config.AccessCheckInfo;
|
||||
import com.google.gerrit.extensions.api.config.AccessCheckInput;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -79,46 +79,59 @@ public class CheckAccessIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidInputs() {
|
||||
List<AccessCheckInput> inputs =
|
||||
ImmutableList.of(
|
||||
new AccessCheckInput(),
|
||||
new AccessCheckInput(user.email, null, null),
|
||||
new AccessCheckInput(null, normalProject.toString(), null),
|
||||
new AccessCheckInput("doesnotexist@invalid.com", normalProject.toString(), null));
|
||||
for (AccessCheckInput input : inputs) {
|
||||
try {
|
||||
gApi.config().server().checkAccess(input);
|
||||
fail(String.format("want RestApiException for %s", newGson().toJson(input)));
|
||||
} catch (RestApiException e) {
|
||||
public void emptyInput() throws Exception {
|
||||
exception.expect(BadRequestException.class);
|
||||
exception.expectMessage("input requires 'account'");
|
||||
gApi.projects().name(normalProject.get()).checkAccess(new AccessCheckInput());
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
public void nonexistentEmail() throws Exception {
|
||||
exception.expect(UnprocessableEntityException.class);
|
||||
exception.expectMessage("cannot find account doesnotexist@invalid.com");
|
||||
gApi.projects()
|
||||
.name(normalProject.get())
|
||||
.checkAccess(new AccessCheckInput("doesnotexist@invalid.com", null));
|
||||
}
|
||||
|
||||
private static class TestCase {
|
||||
AccessCheckInput input;
|
||||
String project;
|
||||
int want;
|
||||
|
||||
TestCase(String mail, String project, String ref, int want) {
|
||||
this.input = new AccessCheckInput(mail, ref);
|
||||
this.project = project;
|
||||
this.want = want;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessible() {
|
||||
Map<AccessCheckInput, Integer> inputs =
|
||||
ImmutableMap.of(
|
||||
new AccessCheckInput(user.email, normalProject.get(), null), 200,
|
||||
new AccessCheckInput(user.email, secretProject.get(), null), 403,
|
||||
new AccessCheckInput(user.email, "nonexistent", null), 404,
|
||||
new AccessCheckInput(privilegedUser.email, normalProject.get(), null), 200,
|
||||
new AccessCheckInput(privilegedUser.email, secretProject.get(), null), 200);
|
||||
public void accessible() throws Exception {
|
||||
List<TestCase> inputs =
|
||||
ImmutableList.of(
|
||||
new TestCase(user.email, normalProject.get(), null, 200),
|
||||
new TestCase(user.email, secretProject.get(), null, 403),
|
||||
new TestCase(user.email, secretRefProject.get(), "refs/heads/secret/master", 403),
|
||||
new TestCase(
|
||||
privilegedUser.email, secretRefProject.get(), "refs/heads/secret/master", 200),
|
||||
new TestCase(privilegedUser.email, normalProject.get(), null, 200),
|
||||
new TestCase(privilegedUser.email, secretProject.get(), null, 200));
|
||||
|
||||
for (Map.Entry<AccessCheckInput, Integer> entry : inputs.entrySet()) {
|
||||
String in = newGson().toJson(entry.getKey());
|
||||
for (TestCase tc : inputs) {
|
||||
String in = newGson().toJson(tc.input);
|
||||
AccessCheckInfo info = null;
|
||||
|
||||
try {
|
||||
info = gApi.config().server().checkAccess(entry.getKey());
|
||||
info = gApi.projects().name(tc.project).checkAccess(tc.input);
|
||||
} catch (RestApiException e) {
|
||||
fail(String.format("check.check(%s): exception %s", in, e));
|
||||
fail(String.format("check.access(%s, %s): exception %s", tc.project, in, e));
|
||||
}
|
||||
|
||||
int want = entry.getValue();
|
||||
int want = tc.want;
|
||||
if (want != info.status) {
|
||||
fail(String.format("check.access(%s) = %d, want %d", in, info.status, want));
|
||||
fail(
|
||||
String.format("check.access(%s, %s) = %d, want %d", tc.project, in, info.status, want));
|
||||
}
|
||||
|
||||
switch (want) {
|
Reference in New Issue
Block a user