Search in sources :

Example 21 with AccessSection

use of com.google.gerrit.entities.AccessSection 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)

Example 22 with AccessSection

use of com.google.gerrit.entities.AccessSection in project gerrit by GerritCodeReview.

the class LabelNormalizerTest method configureProject.

private void configureProject() throws Exception {
    ProjectConfig pc = loadAllProjects();
    for (AccessSection sec : pc.getAccessSections()) {
        pc.upsertAccessSection(sec.getName(), updatedSection -> {
            for (String label : pc.getLabelSections().keySet()) {
                updatedSection.removePermission(forLabel(label));
            }
        });
    }
    LabelType lt = label(LabelId.VERIFIED, value(1, LabelId.VERIFIED), value(0, "No score"), value(-1, "Fails"));
    pc.upsertLabelType(lt);
    save(pc);
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) LabelType(com.google.gerrit.entities.LabelType) AccessSection(com.google.gerrit.entities.AccessSection)

Aggregations

AccessSection (com.google.gerrit.entities.AccessSection)22 Permission (com.google.gerrit.entities.Permission)16 PermissionRule (com.google.gerrit.entities.PermissionRule)7 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)6 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 Project (com.google.gerrit.entities.Project)3 InvalidNameException (com.google.gerrit.exceptions.InvalidNameException)3 CoreOrPluginProjectPermission (com.google.gerrit.extensions.api.access.CoreOrPluginProjectPermission)3 PluginProjectPermission (com.google.gerrit.extensions.api.access.PluginProjectPermission)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 SectionMatcher (com.google.gerrit.server.project.SectionMatcher)3 ImmutableList (com.google.common.collect.ImmutableList)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 GroupDescription (com.google.gerrit.entities.GroupDescription)2 GroupReference (com.google.gerrit.entities.GroupReference)2 LabelType (com.google.gerrit.entities.LabelType)2