Introduce TestProjectUpdate to update project config
The first usage of this utility will be to update permissions, replacing com.google.gerrit.server.project.testing.Util. Add permissions using a new TestPermission AutoValue, specifically for tests. This API is intended for easy fluent use; the number of places we set up permissions in tests vastly outnumbers the codepaths that update permissions in production code. This change adds the ProjectOperations implementation, adds a test for the new functionality, and updates a small number of callers in real tests to prove it works in the real world. Followup changes will migrate more callers as well as add support for global capabilities, deleting permissions, etc. The old Util methods use a dangerous antipattern of returning the mutable PermissionRule that is stored in the ProjectCache, which is then mutated by callers. This new test API does not require mutating live PermissionRules after initialization, and migrating all tests to use the new API is on the critical path to making PermissionRule immutable. Change-Id: I37148bdb297e5fd129e814ef4532a6ed5ffdc041
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.eclipse.jgit.lib.Constants.R_HEADS;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
|
||||
import com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate;
|
||||
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.projects.BranchApi;
|
||||
@@ -134,8 +135,18 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void deleteUserBranch_Conflict() throws Exception {
|
||||
allow(allUsers, RefNames.REFS_USERS + "*", Permission.CREATE, REGISTERED_USERS);
|
||||
allow(allUsers, RefNames.REFS_USERS + "*", Permission.PUSH, REGISTERED_USERS);
|
||||
projectOperations
|
||||
.project(allUsers)
|
||||
.forUpdate()
|
||||
.add(
|
||||
TestProjectUpdate.allow(Permission.CREATE)
|
||||
.ref(RefNames.REFS_USERS + "*")
|
||||
.group(REGISTERED_USERS))
|
||||
.add(
|
||||
TestProjectUpdate.allow(Permission.PUSH)
|
||||
.ref(RefNames.REFS_USERS + "*")
|
||||
.group(REGISTERED_USERS))
|
||||
.update();
|
||||
|
||||
ResourceConflictException thrown =
|
||||
assertThrows(
|
||||
@@ -159,7 +170,15 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private void blockForcePush() throws Exception {
|
||||
block("refs/heads/*", Permission.PUSH, ANONYMOUS_USERS).setForce(true);
|
||||
projectOperations
|
||||
.project(project)
|
||||
.forUpdate()
|
||||
.add(
|
||||
TestProjectUpdate.block(Permission.PUSH)
|
||||
.ref("refs/heads/*")
|
||||
.group(ANONYMOUS_USERS)
|
||||
.force(true))
|
||||
.update();
|
||||
}
|
||||
|
||||
private void grantForcePush() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user