use of com.google.gerrit.extensions.api.config.AccessCheckInput in project gerrit by GerritCodeReview.
the class CheckAccessIT method invalidInputs.
@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) {
}
}
}
use of com.google.gerrit.extensions.api.config.AccessCheckInput in project gerrit by GerritCodeReview.
the class CheckAccessIT method accessible.
@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);
for (Map.Entry<AccessCheckInput, Integer> entry : inputs.entrySet()) {
String in = newGson().toJson(entry.getKey());
AccessCheckInfo info = null;
try {
info = gApi.config().server().checkAccess(entry.getKey());
} catch (RestApiException e) {
fail(String.format("check.check(%s): exception %s", in, e));
}
int want = entry.getValue();
if (want != info.status) {
fail(String.format("check.access(%s) = %d, want %d", in, info.status, want));
}
switch(want) {
case 403:
assertThat(info.message).contains("cannot see");
break;
case 404:
assertThat(info.message).contains("does not exist");
break;
case 200:
assertThat(info.message).isNull();
break;
default:
fail(String.format("unknown code %d", want));
}
}
}
Aggregations