Search in sources :

Example 1 with AccessCheckInput

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) {
        }
    }
}
Also used : AccessCheckInput(com.google.gerrit.extensions.api.config.AccessCheckInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with AccessCheckInput

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));
        }
    }
}
Also used : AccessCheckInput(com.google.gerrit.extensions.api.config.AccessCheckInput) AccessCheckInfo(com.google.gerrit.extensions.api.config.AccessCheckInfo) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 AccessCheckInput (com.google.gerrit.extensions.api.config.AccessCheckInput)2 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AccessCheckInfo (com.google.gerrit.extensions.api.config.AccessCheckInfo)1 Map (java.util.Map)1