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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations