Merge "tests: Simplify blockRead and block"
This commit is contained in:
commit
d2286d8c76
@ -17,7 +17,6 @@ package com.google.gerrit.acceptance;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||||
import static com.google.gerrit.server.project.Util.block;
|
|
||||||
import static com.google.gerrit.testutil.GerritServerTests.isNoteDbTestEnabled;
|
import static com.google.gerrit.testutil.GerritServerTests.isNoteDbTestEnabled;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
@ -542,6 +541,14 @@ public abstract class AbstractDaemonTest {
|
|||||||
saveProjectConfig(project, cfg);
|
saveProjectConfig(project, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PermissionRule block(String permission, AccountGroup.UUID id, String ref)
|
||||||
|
throws Exception {
|
||||||
|
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||||
|
PermissionRule rule = Util.block(cfg, permission, id, ref);
|
||||||
|
saveProjectConfig(project, cfg);
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg)
|
protected void saveProjectConfig(Project.NameKey p, ProjectConfig cfg)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(p);
|
MetaDataUpdate md = metaDataUpdateFactory.create(p);
|
||||||
@ -574,16 +581,14 @@ public abstract class AbstractDaemonTest {
|
|||||||
projectCache.evict(config.getProject());
|
projectCache.evict(config.getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blockRead(Project.NameKey project, String ref) throws Exception {
|
protected void blockRead(String ref) throws Exception {
|
||||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
block(Permission.READ, REGISTERED_USERS, ref);
|
||||||
block(cfg, Permission.READ, REGISTERED_USERS, ref);
|
|
||||||
saveProjectConfig(project, cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void blockForgeCommitter(Project.NameKey project, String ref)
|
protected void blockForgeCommitter(Project.NameKey project, String ref)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
||||||
block(cfg, Permission.FORGE_COMMITTER, REGISTERED_USERS, ref);
|
Util.block(cfg, Permission.FORGE_COMMITTER, REGISTERED_USERS, ref);
|
||||||
saveProjectConfig(project, cfg);
|
saveProjectConfig(project, cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,13 +15,11 @@
|
|||||||
package com.google.gerrit.acceptance.git;
|
package com.google.gerrit.acceptance.git;
|
||||||
|
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||||
import static com.google.gerrit.server.project.Util.block;
|
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -31,9 +29,7 @@ public class DraftChangeBlockedIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
block(Permission.PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
||||||
block(cfg, Permission.PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
|
||||||
saveProjectConfig(project, cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -30,7 +30,7 @@ public class IndexChangeIT extends AbstractDaemonTest {
|
|||||||
@Test
|
@Test
|
||||||
public void indexChangeOnNonVisibleBranch() throws Exception {
|
public void indexChangeOnNonVisibleBranch() throws Exception {
|
||||||
String changeId = createChange().getChangeId();
|
String changeId = createChange().getChangeId();
|
||||||
blockRead(project, "refs/heads/master");
|
blockRead("refs/heads/master");
|
||||||
userSession
|
userSession
|
||||||
.post("/changes/" + changeId + "/index/")
|
.post("/changes/" + changeId + "/index/")
|
||||||
.assertNotFound();
|
.assertNotFound();
|
||||||
|
@ -17,7 +17,6 @@ package com.google.gerrit.acceptance.rest.project;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||||
import static com.google.gerrit.server.project.Util.block;
|
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
@ -29,7 +28,6 @@ import com.google.gerrit.extensions.restapi.AuthException;
|
|||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -84,9 +82,7 @@ public class CreateBranchIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void blockCreateReference() throws Exception {
|
private void blockCreateReference() throws Exception {
|
||||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
block(Permission.CREATE, ANONYMOUS_USERS, "refs/*");
|
||||||
block(cfg, Permission.CREATE, ANONYMOUS_USERS, "refs/*");
|
|
||||||
saveProjectConfig(project, cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void grantOwner() throws Exception {
|
private void grantOwner() throws Exception {
|
||||||
|
@ -16,7 +16,6 @@ package com.google.gerrit.acceptance.rest.project;
|
|||||||
|
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||||
import static com.google.gerrit.server.project.Util.block;
|
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
@ -26,7 +25,6 @@ import com.google.gerrit.extensions.api.projects.BranchInput;
|
|||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -76,9 +74,7 @@ public class DeleteBranchIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void blockForcePush() throws Exception {
|
private void blockForcePush() throws Exception {
|
||||||
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
|
block(Permission.PUSH, ANONYMOUS_USERS, "refs/heads/*").setForce(true);
|
||||||
block(cfg, Permission.PUSH, ANONYMOUS_USERS, "refs/heads/*").setForce(true);
|
|
||||||
saveProjectConfig(project, cfg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void grantOwner() throws Exception {
|
private void grantOwner() throws Exception {
|
||||||
|
@ -39,7 +39,7 @@ public class GetCommitIT extends AbstractDaemonTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
repo = GitUtil.newTestRepository(repoManager.openRepository(project));
|
repo = GitUtil.newTestRepository(repoManager.openRepository(project));
|
||||||
blockRead(project, "refs/*");
|
blockRead("refs/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -37,7 +37,7 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listBranchesOfNonVisibleProject_NotFound() throws Exception {
|
public void listBranchesOfNonVisibleProject_NotFound() throws Exception {
|
||||||
blockRead(project, "refs/*");
|
blockRead("refs/*");
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
exception.expect(ResourceNotFoundException.class);
|
exception.expect(ResourceNotFoundException.class);
|
||||||
gApi.projects().name(project.get()).branches().get();
|
gApi.projects().name(project.get()).branches().get();
|
||||||
@ -65,7 +65,7 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listBranchesSomeHidden() throws Exception {
|
public void listBranchesSomeHidden() throws Exception {
|
||||||
blockRead(project, "refs/heads/dev");
|
blockRead("refs/heads/dev");
|
||||||
String master = pushTo("refs/heads/master").getCommit().name();
|
String master = pushTo("refs/heads/master").getCommit().name();
|
||||||
pushTo("refs/heads/dev");
|
pushTo("refs/heads/dev");
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
@ -78,7 +78,7 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listBranchesHeadHidden() throws Exception {
|
public void listBranchesHeadHidden() throws Exception {
|
||||||
blockRead(project, "refs/heads/master");
|
blockRead("refs/heads/master");
|
||||||
pushTo("refs/heads/master");
|
pushTo("refs/heads/master");
|
||||||
String dev = pushTo("refs/heads/dev").getCommit().name();
|
String dev = pushTo("refs/heads/dev").getCommit().name();
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
|
@ -60,7 +60,7 @@ public class TagsIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listTagsOfNonVisibleProject() throws Exception {
|
public void listTagsOfNonVisibleProject() throws Exception {
|
||||||
blockRead(project, "refs/*");
|
blockRead("refs/*");
|
||||||
userSession
|
userSession
|
||||||
.get("/projects/" + project.get() + "/tags")
|
.get("/projects/" + project.get() + "/tags")
|
||||||
.assertNotFound();
|
.assertNotFound();
|
||||||
@ -68,7 +68,7 @@ public class TagsIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listTagsOfNonVisibleProjectWithApi() throws Exception {
|
public void listTagsOfNonVisibleProjectWithApi() throws Exception {
|
||||||
blockRead(project, "refs/*");
|
blockRead("refs/*");
|
||||||
setApiUser(user);
|
setApiUser(user);
|
||||||
exception.expect(ResourceNotFoundException.class);
|
exception.expect(ResourceNotFoundException.class);
|
||||||
gApi.projects().name(project.get()).tags().get();
|
gApi.projects().name(project.get()).tags().get();
|
||||||
@ -76,7 +76,7 @@ public class TagsIT extends AbstractDaemonTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTagOfNonVisibleProjectWithApi() throws Exception {
|
public void getTagOfNonVisibleProjectWithApi() throws Exception {
|
||||||
blockRead(project, "refs/*");
|
blockRead("refs/*");
|
||||||
exception.expect(ResourceNotFoundException.class);
|
exception.expect(ResourceNotFoundException.class);
|
||||||
gApi.projects().name(project.get()).tag("tag").get();
|
gApi.projects().name(project.get()).tag("tag").get();
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ public class TagsIT extends AbstractDaemonTest {
|
|||||||
assertThat(result.get(1).ref).isEqualTo("refs/tags/" + tag2.name);
|
assertThat(result.get(1).ref).isEqualTo("refs/tags/" + tag2.name);
|
||||||
assertThat(result.get(1).revision).isEqualTo(r2.getCommitId().getName());
|
assertThat(result.get(1).revision).isEqualTo(r2.getCommitId().getName());
|
||||||
|
|
||||||
blockRead(project, "refs/heads/hidden");
|
blockRead("refs/heads/hidden");
|
||||||
result = getTags().get();
|
result = getTags().get();
|
||||||
assertThat(result).hasSize(1);
|
assertThat(result).hasSize(1);
|
||||||
assertThat(result.get(0).ref).isEqualTo("refs/tags/" + tag1.name);
|
assertThat(result.get(0).ref).isEqualTo("refs/tags/" + tag1.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user