From 9f486bd587571f3d286b7fe624eb4b6052fa4771 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 22 Aug 2018 13:24:07 +0900 Subject: [PATCH] ReflogIT: Add test coverage for reflog permissions Test that owners and admins can access the reflog, but regular users cannot. Change-Id: I358802d190ca12f3bae506aef2acc459478a5269 --- .../acceptance/server/project/ReflogIT.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/project/ReflogIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/project/ReflogIT.java index 1bf2f92214..31617bf63f 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/project/ReflogIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/project/ReflogIT.java @@ -19,15 +19,21 @@ import static com.google.common.truth.Truth.assertThat; import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.UseLocalDisk; +import com.google.gerrit.common.data.Permission; import com.google.gerrit.extensions.api.changes.ReviewInput; +import com.google.gerrit.extensions.api.groups.GroupApi; import com.google.gerrit.extensions.api.projects.BranchApi; import com.google.gerrit.extensions.api.projects.ReflogEntryInfo; +import com.google.gerrit.extensions.restapi.AuthException; +import com.google.gerrit.reviewdb.client.AccountGroup; +import com.google.gerrit.server.git.ProjectConfig; +import com.google.gerrit.server.project.Util; import java.util.List; import org.junit.Test; -@UseLocalDisk public class ReflogIT extends AbstractDaemonTest { @Test + @UseLocalDisk public void reflogUpdatedBySubmittingChange() throws Exception { BranchApi branchApi = gApi.projects().name(project.get()).branch("master"); List reflog = branchApi.reflog(); @@ -48,4 +54,33 @@ public class ReflogIT extends AbstractDaemonTest { reflog = branchApi.reflog(); assertThat(reflog).hasSize(refLogLen + 1); } + + @Test + @UseLocalDisk + public void regularUserIsNotAllowedToGetReflog() throws Exception { + setApiUser(user); + exception.expect(AuthException.class); + gApi.projects().name(project.get()).branch("master").reflog(); + } + + @Test + @UseLocalDisk + public void ownerUserIsAllowedToGetReflog() throws Exception { + GroupApi groupApi = gApi.groups().create(name("get-reflog")); + groupApi.addMembers("user"); + + ProjectConfig cfg = projectCache.checkedGet(project).getConfig(); + Util.allow(cfg, Permission.OWNER, new AccountGroup.UUID(groupApi.get().id), "refs/*"); + saveProjectConfig(project, cfg); + + setApiUser(user); + gApi.projects().name(project.get()).branch("master").reflog(); + } + + @Test + @UseLocalDisk + public void adminUserIsAllowedToGetReflog() throws Exception { + setApiUser(admin); + gApi.projects().name(project.get()).branch("master").reflog(); + } }