Search in sources :

Example 6 with AccessCheckInfo

use of com.google.gerrit.extensions.api.config.AccessCheckInfo in project gerrit by GerritCodeReview.

the class CheckAccessIT method noRules.

@Test
@Sandboxed
public void noRules() throws Exception {
    normalProject = projectOperations.newProject().create();
    for (AccessSection section : projectOperations.project(allProjectsName).getProjectConfig().getAccessSections()) {
        if (!section.getName().startsWith(Constants.R_REFS)) {
            continue;
        }
        for (Permission permission : section.getPermissions()) {
            projectOperations.project(allProjectsName).forUpdate().remove(permissionKey(permission.getName()).ref(section.getName()).build()).update();
        }
    }
    AccessCheckInput input = new AccessCheckInput();
    input.account = privilegedUser.email();
    input.permission = Permission.READ;
    input.ref = "refs/heads/main";
    AccessCheckInfo info = gApi.projects().name(normalProject.get()).checkAccess(input);
    assertThat(info.status).isEqualTo(403);
    assertThat(info.debugLogs).isNotEmpty();
    assertThat(info.debugLogs.get(0)).contains("Found no rules");
}
Also used : AccessCheckInput(com.google.gerrit.extensions.api.config.AccessCheckInput) AccessCheckInfo(com.google.gerrit.extensions.api.config.AccessCheckInfo) Permission(com.google.gerrit.entities.Permission) AccessSection(com.google.gerrit.entities.AccessSection) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Aggregations

AccessCheckInfo (com.google.gerrit.extensions.api.config.AccessCheckInfo)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 Test (org.junit.Test)4 AccessCheckInput (com.google.gerrit.extensions.api.config.AccessCheckInput)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sandboxed (com.google.gerrit.acceptance.Sandboxed)1 AccessSection (com.google.gerrit.entities.AccessSection)1 Permission (com.google.gerrit.entities.Permission)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 Account (com.google.gerrit.reviewdb.client.Account)1 Project (com.google.gerrit.reviewdb.client.Project)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 Map (java.util.Map)1 RefUpdate (org.eclipse.jgit.lib.RefUpdate)1 Repository (org.eclipse.jgit.lib.Repository)1