Search in sources :

Example 11 with AccessSectionInfo

use of com.google.gerrit.extensions.api.access.AccessSectionInfo in project gerrit by GerritCodeReview.

the class AccessIT method unknownPermissionRemainsUnchanged.

@Test
public void unknownPermissionRemainsUnchanged() throws Exception {
    String access = "access";
    String unknownPermission = "unknownPermission";
    String registeredUsers = "group Registered Users";
    String refsFor = "refs/for/*";
    // Clone repository to forcefully add permission
    TestRepository<InMemoryRepository> allProjectsRepo = cloneProject(allProjects, admin);
    // Fetch permission ref
    GitUtil.fetch(allProjectsRepo, "refs/meta/config:cfg");
    allProjectsRepo.reset("cfg");
    // Load current permissions
    String config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    // Append and push unknown permission
    Config cfg = new Config();
    cfg.fromText(config);
    cfg.setString(access, refsFor, unknownPermission, registeredUsers);
    config = cfg.toText();
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), allProjectsRepo, "Subject", "project.config", config);
    push.to(RefNames.REFS_CONFIG).assertOkStatus();
    // Verify that unknownPermission is present
    config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    cfg.fromText(config);
    assertThat(cfg.getString(access, refsFor, unknownPermission)).isEqualTo(registeredUsers);
    // Make permission change through API
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultAccessSectionInfo();
    accessInput.add.put(refsFor, accessSectionInfo);
    gApi.projects().name(allProjects.get()).access(accessInput);
    accessInput.add.clear();
    accessInput.remove.put(refsFor, accessSectionInfo);
    gApi.projects().name(allProjects.get()).access(accessInput);
    // Verify that unknownPermission is still present
    config = gApi.projects().name(allProjects.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    cfg.fromText(config);
    assertThat(cfg.getString(access, refsFor, unknownPermission)).isEqualTo(registeredUsers);
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Config(org.eclipse.jgit.lib.Config) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 12 with AccessSectionInfo

use of com.google.gerrit.extensions.api.access.AccessSectionInfo in project gerrit by GerritCodeReview.

the class AccessIT method createDefaultGlobalCapabilitiesAccessSectionInfo.

private AccessSectionInfo createDefaultGlobalCapabilitiesAccessSectionInfo() {
    AccessSectionInfo accessSection = newAccessSectionInfo();
    PermissionInfo email = newPermissionInfo();
    PermissionRuleInfo pri = new PermissionRuleInfo(PermissionRuleInfo.Action.ALLOW, false);
    email.rules.put(SystemGroupBackend.REGISTERED_USERS.get(), pri);
    accessSection.permissions.put(GlobalCapability.EMAIL_REVIEWERS, email);
    return accessSection;
}
Also used : PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) PermissionRuleInfo(com.google.gerrit.extensions.api.access.PermissionRuleInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo)

Example 13 with AccessSectionInfo

use of com.google.gerrit.extensions.api.access.AccessSectionInfo in project gerrit by GerritCodeReview.

the class AccessIT method removePermission.

@Test
public void removePermission() throws Exception {
    // Add initial permission set
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultAccessSectionInfo();
    accessInput.add.put(REFS_HEADS, accessSectionInfo);
    pApi.access(accessInput);
    // Remove specific permission
    AccessSectionInfo accessSectionToRemove = newAccessSectionInfo();
    accessSectionToRemove.permissions.put(Permission.LABEL + LABEL_CODE_REVIEW, newPermissionInfo());
    ProjectAccessInput removal = newProjectAccessInput();
    removal.remove.put(REFS_HEADS, accessSectionToRemove);
    pApi.access(removal);
    // Remove locally
    accessInput.add.get(REFS_HEADS).permissions.remove(Permission.LABEL + LABEL_CODE_REVIEW);
    // Check
    assertThat(pApi.access().local).isEqualTo(accessInput.add);
}
Also used : AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 14 with AccessSectionInfo

use of com.google.gerrit.extensions.api.access.AccessSectionInfo in project gerrit by GerritCodeReview.

the class AccessIT method addAccessSection.

@Test
public void addAccessSection() throws Exception {
    Project.NameKey p = new Project.NameKey(newProjectName);
    RevCommit initialHead = getRemoteHead(p, RefNames.REFS_CONFIG);
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultAccessSectionInfo();
    accessInput.add.put(REFS_HEADS, accessSectionInfo);
    pApi.access(accessInput);
    assertThat(pApi.access().local).isEqualTo(accessInput.add);
    RevCommit updatedHead = getRemoteHead(p, RefNames.REFS_CONFIG);
    eventRecorder.assertRefUpdatedEvents(p.get(), RefNames.REFS_CONFIG, null, initialHead, initialHead, updatedHead);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with AccessSectionInfo

use of com.google.gerrit.extensions.api.access.AccessSectionInfo in project gerrit by GerritCodeReview.

the class AccessIT method addGlobalCapabilityAsUser.

@Test
public void addGlobalCapabilityAsUser() throws Exception {
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = createDefaultGlobalCapabilitiesAccessSectionInfo();
    accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
    setApiUser(user);
    exception.expect(AuthException.class);
    gApi.projects().name(allProjects.get()).access(accessInput);
}
Also used : AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AccessSectionInfo (com.google.gerrit.extensions.api.access.AccessSectionInfo)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 ProjectAccessInput (com.google.gerrit.extensions.api.access.ProjectAccessInput)13 Test (org.junit.Test)13 PermissionInfo (com.google.gerrit.extensions.api.access.PermissionInfo)9 PermissionRuleInfo (com.google.gerrit.extensions.api.access.PermissionRuleInfo)7 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 Permission (com.google.gerrit.common.data.Permission)2 PermissionRule (com.google.gerrit.common.data.PermissionRule)2 ProjectAccessInfo (com.google.gerrit.extensions.api.access.ProjectAccessInfo)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 AccessSection (com.google.gerrit.common.data.AccessSection)1 GroupDescription (com.google.gerrit.common.data.GroupDescription)1 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)1 Project (com.google.gerrit.reviewdb.client.Project)1 GlobalPermission (com.google.gerrit.server.permissions.GlobalPermission)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 Config (org.eclipse.jgit.lib.Config)1