Let RefControlTest be responsible for creating own test projects
All test cases which test inheritance of the access rights assume
existence of two projects: "local" and "parent", where "parent"
is the parent of the "local".
The cc00e00569 moved the creation of
the "parent" into the Util class and it wasn't intuitive to follow
what exactly the "util.getParentConfig()" meant.
Remove the creation of the "parent" project from the Util class and
create the "parent" in the RefControlTest. Also, make sure that "parent"
is set to be the parent of the "local" in the setUp method.
Change-Id: I991a9bc25ca7609b5d9e15e54167446c7b0aa6cf
This commit is contained in:
@@ -55,6 +55,8 @@ public class RefControlTest {
|
|||||||
private final AccountGroup.UUID fixers = new AccountGroup.UUID("test.fixers");
|
private final AccountGroup.UUID fixers = new AccountGroup.UUID("test.fixers");
|
||||||
private Project.NameKey localKey = new Project.NameKey("local");
|
private Project.NameKey localKey = new Project.NameKey("local");
|
||||||
private ProjectConfig local;
|
private ProjectConfig local;
|
||||||
|
private Project.NameKey parentKey = new Project.NameKey("parent");
|
||||||
|
private ProjectConfig parent;
|
||||||
private final Util util;
|
private final Util util;
|
||||||
|
|
||||||
public RefControlTest() {
|
public RefControlTest() {
|
||||||
@@ -63,9 +65,14 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
parent = new ProjectConfig(parentKey);
|
||||||
|
parent.load(newRepository(parentKey));
|
||||||
|
util.add(parent);
|
||||||
|
|
||||||
local = new ProjectConfig(localKey);
|
local = new ProjectConfig(localKey);
|
||||||
local.load(newRepository(localKey));
|
local.load(newRepository(localKey));
|
||||||
util.add(local);
|
util.add(local);
|
||||||
|
local.getProject().setParentName(parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -127,8 +134,8 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritRead_SingleBranchDeniesUpload() {
|
public void testInheritRead_SingleBranchDeniesUpload() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
allow(util.getParentConfig(), PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
allow(parent, PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
||||||
allow(local, READ, REGISTERED_USERS, "refs/heads/foobar");
|
allow(local, READ, REGISTERED_USERS, "refs/heads/foobar");
|
||||||
doNotInherit(local, READ, "refs/heads/foobar");
|
doNotInherit(local, READ, "refs/heads/foobar");
|
||||||
doNotInherit(local, PUSH, "refs/for/refs/heads/foobar");
|
doNotInherit(local, PUSH, "refs/for/refs/heads/foobar");
|
||||||
@@ -145,8 +152,8 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockPushDrafts() {
|
public void testBlockPushDrafts() {
|
||||||
allow(util.getParentConfig(), PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
allow(parent, PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local);
|
ProjectControl u = util.user(local);
|
||||||
assertTrue("can upload refs/heads/master",
|
assertTrue("can upload refs/heads/master",
|
||||||
@@ -157,8 +164,8 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockPushDraftsUnblockAdmin() {
|
public void testBlockPushDraftsUnblockAdmin() {
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/drafts/*");
|
||||||
allow(util.getParentConfig(), PUSH, ADMIN, "refs/drafts/*");
|
allow(parent, PUSH, ADMIN, "refs/drafts/*");
|
||||||
|
|
||||||
assertTrue("push is blocked for anonymous to refs/drafts/master",
|
assertTrue("push is blocked for anonymous to refs/drafts/master",
|
||||||
util.user(local).controlForRef("refs/drafts/refs/heads/master")
|
util.user(local).controlForRef("refs/drafts/refs/heads/master")
|
||||||
@@ -170,8 +177,8 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritRead_SingleBranchDoesNotOverrideInherited() {
|
public void testInheritRead_SingleBranchDoesNotOverrideInherited() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
allow(util.getParentConfig(), PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
allow(parent, PUSH, REGISTERED_USERS, "refs/for/refs/*");
|
||||||
allow(local, READ, REGISTERED_USERS, "refs/heads/foobar");
|
allow(local, READ, REGISTERED_USERS, "refs/heads/foobar");
|
||||||
|
|
||||||
ProjectControl u = util.user(local);
|
ProjectControl u = util.user(local);
|
||||||
@@ -186,20 +193,20 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritDuplicateSections() throws Exception {
|
public void testInheritDuplicateSections() throws Exception {
|
||||||
allow(util.getParentConfig(), READ, ADMIN, "refs/*");
|
allow(parent, READ, ADMIN, "refs/*");
|
||||||
allow(local, READ, DEVS, "refs/heads/*");
|
allow(local, READ, DEVS, "refs/heads/*");
|
||||||
local.getProject().setParentName(util.getParentConfig().getProject().getName());
|
|
||||||
assertTrue("a can read", util.user(local, "a", ADMIN).isVisible());
|
assertTrue("a can read", util.user(local, "a", ADMIN).isVisible());
|
||||||
|
|
||||||
local = new ProjectConfig(new Project.NameKey("local"));
|
local = new ProjectConfig(localKey);
|
||||||
local.load(newRepository(localKey));
|
local.load(newRepository(localKey));
|
||||||
|
local.getProject().setParentName(parentKey);
|
||||||
allow(local, READ, DEVS, "refs/*");
|
allow(local, READ, DEVS, "refs/*");
|
||||||
assertTrue("d can read", util.user(local, "d", DEVS).isVisible());
|
assertTrue("d can read", util.user(local, "d", DEVS).isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritRead_OverrideWithDeny() {
|
public void testInheritRead_OverrideWithDeny() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
deny(local, READ, REGISTERED_USERS, "refs/*");
|
deny(local, READ, REGISTERED_USERS, "refs/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local);
|
ProjectControl u = util.user(local);
|
||||||
@@ -208,7 +215,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritRead_AppendWithDenyOfRef() {
|
public void testInheritRead_AppendWithDenyOfRef() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
deny(local, READ, REGISTERED_USERS, "refs/heads/*");
|
deny(local, READ, REGISTERED_USERS, "refs/heads/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local);
|
ProjectControl u = util.user(local);
|
||||||
@@ -220,7 +227,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritRead_OverridesAndDeniesOfRef() {
|
public void testInheritRead_OverridesAndDeniesOfRef() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
deny(local, READ, REGISTERED_USERS, "refs/*");
|
deny(local, READ, REGISTERED_USERS, "refs/*");
|
||||||
allow(local, READ, REGISTERED_USERS, "refs/heads/*");
|
allow(local, READ, REGISTERED_USERS, "refs/heads/*");
|
||||||
|
|
||||||
@@ -233,7 +240,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInheritSubmit_OverridesAndDeniesOfRef() {
|
public void testInheritSubmit_OverridesAndDeniesOfRef() {
|
||||||
allow(util.getParentConfig(), SUBMIT, REGISTERED_USERS, "refs/*");
|
allow(parent, SUBMIT, REGISTERED_USERS, "refs/*");
|
||||||
deny(local, SUBMIT, REGISTERED_USERS, "refs/*");
|
deny(local, SUBMIT, REGISTERED_USERS, "refs/*");
|
||||||
allow(local, SUBMIT, REGISTERED_USERS, "refs/heads/*");
|
allow(local, SUBMIT, REGISTERED_USERS, "refs/heads/*");
|
||||||
|
|
||||||
@@ -245,7 +252,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCannotUploadToAnyRef() {
|
public void testCannotUploadToAnyRef() {
|
||||||
allow(util.getParentConfig(), READ, REGISTERED_USERS, "refs/*");
|
allow(parent, READ, REGISTERED_USERS, "refs/*");
|
||||||
allow(local, READ, DEVS, "refs/heads/*");
|
allow(local, READ, DEVS, "refs/heads/*");
|
||||||
allow(local, PUSH, DEVS, "refs/for/refs/heads/*");
|
allow(local, PUSH, DEVS, "refs/for/refs/heads/*");
|
||||||
|
|
||||||
@@ -288,7 +295,7 @@ public class RefControlTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSortWithRegex() {
|
public void testSortWithRegex() {
|
||||||
allow(local, READ, DEVS, "^refs/heads/.*");
|
allow(local, READ, DEVS, "^refs/heads/.*");
|
||||||
allow(util.getParentConfig(), READ, ANONYMOUS_USERS, "^refs/heads/.*-QA-.*");
|
allow(parent, READ, ANONYMOUS_USERS, "^refs/heads/.*-QA-.*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local, DEVS), d = util.user(local, DEVS);
|
ProjectControl u = util.user(local, DEVS), d = util.user(local, DEVS);
|
||||||
assertTrue("u can read", u.controlForRef("refs/heads/foo-QA-bar").isVisible());
|
assertTrue("u can read", u.controlForRef("refs/heads/foo-QA-bar").isVisible());
|
||||||
@@ -298,7 +305,7 @@ public class RefControlTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBlockRule_ParentBlocksChild() {
|
public void testBlockRule_ParentBlocksChild() {
|
||||||
allow(local, PUSH, DEVS, "refs/tags/*");
|
allow(local, PUSH, DEVS, "refs/tags/*");
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
||||||
ProjectControl u = util.user(local, DEVS);
|
ProjectControl u = util.user(local, DEVS);
|
||||||
assertFalse("u can't update tag", u.controlForRef("refs/tags/V10").canUpdate());
|
assertFalse("u can't update tag", u.controlForRef("refs/tags/V10").canUpdate());
|
||||||
}
|
}
|
||||||
@@ -307,7 +314,7 @@ public class RefControlTest {
|
|||||||
public void testBlockRule_ParentBlocksChildEvenIfAlreadyBlockedInChild() {
|
public void testBlockRule_ParentBlocksChildEvenIfAlreadyBlockedInChild() {
|
||||||
allow(local, PUSH, DEVS, "refs/tags/*");
|
allow(local, PUSH, DEVS, "refs/tags/*");
|
||||||
block(local, PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
block(local, PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/tags/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local, DEVS);
|
ProjectControl u = util.user(local, DEVS);
|
||||||
assertFalse("u can't update tag", u.controlForRef("refs/tags/V10").canUpdate());
|
assertFalse("u can't update tag", u.controlForRef("refs/tags/V10").canUpdate());
|
||||||
@@ -316,7 +323,7 @@ public class RefControlTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBlockLabelRange_ParentBlocksChild() {
|
public void testBlockLabelRange_ParentBlocksChild() {
|
||||||
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||||
block(util.getParentConfig(), LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
block(parent, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local, DEVS);
|
ProjectControl u = util.user(local, DEVS);
|
||||||
|
|
||||||
@@ -331,7 +338,7 @@ public class RefControlTest {
|
|||||||
public void testBlockLabelRange_ParentBlocksChildEvenIfAlreadyBlockedInChild() {
|
public void testBlockLabelRange_ParentBlocksChildEvenIfAlreadyBlockedInChild() {
|
||||||
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||||
block(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
block(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||||
block(util.getParentConfig(), LABEL + "Code-Review", -2, +2, DEVS,
|
block(parent, LABEL + "Code-Review", -2, +2, DEVS,
|
||||||
"refs/heads/*");
|
"refs/heads/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local, DEVS);
|
ProjectControl u = util.user(local, DEVS);
|
||||||
@@ -393,7 +400,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnblockInLocal_Fails() {
|
public void testUnblockInLocal_Fails() {
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/heads/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/heads/*");
|
||||||
allow(local, PUSH, fixers, "refs/heads/*");
|
allow(local, PUSH, fixers, "refs/heads/*");
|
||||||
|
|
||||||
ProjectControl f = util.user(local, fixers);
|
ProjectControl f = util.user(local, fixers);
|
||||||
@@ -402,8 +409,8 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnblockInParentBlockInLocal() {
|
public void testUnblockInParentBlockInLocal() {
|
||||||
block(util.getParentConfig(), PUSH, ANONYMOUS_USERS, "refs/heads/*");
|
block(parent, PUSH, ANONYMOUS_USERS, "refs/heads/*");
|
||||||
allow(util.getParentConfig(), PUSH, DEVS, "refs/heads/*");
|
allow(parent, PUSH, DEVS, "refs/heads/*");
|
||||||
block(local, PUSH, DEVS, "refs/heads/*");
|
block(local, PUSH, DEVS, "refs/heads/*");
|
||||||
|
|
||||||
ProjectControl d = util.user(local, DEVS);
|
ProjectControl d = util.user(local, DEVS);
|
||||||
@@ -421,7 +428,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnblockInLocalVisibilityByRegisteredUsers_Fails() {
|
public void testUnblockInLocalVisibilityByRegisteredUsers_Fails() {
|
||||||
block(util.getParentConfig(), READ, ANONYMOUS_USERS, "refs/heads/*");
|
block(parent, READ, ANONYMOUS_USERS, "refs/heads/*");
|
||||||
allow(local, READ, REGISTERED_USERS, "refs/heads/*");
|
allow(local, READ, REGISTERED_USERS, "refs/heads/*");
|
||||||
|
|
||||||
ProjectControl u = util.user(local, REGISTERED_USERS);
|
ProjectControl u = util.user(local, REGISTERED_USERS);
|
||||||
@@ -440,7 +447,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnblockInLocalForceEditTopicName_Fails() {
|
public void testUnblockInLocalForceEditTopicName_Fails() {
|
||||||
block(util.getParentConfig(), EDIT_TOPIC_NAME, ANONYMOUS_USERS, "refs/heads/*");
|
block(parent, EDIT_TOPIC_NAME, ANONYMOUS_USERS, "refs/heads/*");
|
||||||
allow(local, EDIT_TOPIC_NAME, DEVS, "refs/heads/*").setForce(true);
|
allow(local, EDIT_TOPIC_NAME, DEVS, "refs/heads/*").setForce(true);
|
||||||
|
|
||||||
ProjectControl u = util.user(local, REGISTERED_USERS);
|
ProjectControl u = util.user(local, REGISTERED_USERS);
|
||||||
@@ -483,7 +490,7 @@ public class RefControlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnblockInLocalRange_Fails() {
|
public void testUnblockInLocalRange_Fails() {
|
||||||
block(util.getParentConfig(), LABEL + "Code-Review", -1, 1, ANONYMOUS_USERS,
|
block(parent, LABEL + "Code-Review", -1, 1, ANONYMOUS_USERS,
|
||||||
"refs/heads/*");
|
"refs/heads/*");
|
||||||
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
allow(local, LABEL + "Code-Review", -2, +2, DEVS, "refs/heads/*");
|
||||||
|
|
||||||
|
|||||||
@@ -180,17 +180,19 @@ public class Util {
|
|||||||
private final PermissionCollection.Factory sectionSorter;
|
private final PermissionCollection.Factory sectionSorter;
|
||||||
private final GitRepositoryManager repoManager;
|
private final GitRepositoryManager repoManager;
|
||||||
|
|
||||||
private final AllProjectsName allProjectsName = new AllProjectsName("parent");
|
private final AllProjectsName allProjectsName =
|
||||||
private final ProjectConfig parent = new ProjectConfig(allProjectsName);
|
new AllProjectsName("All-Projects");
|
||||||
|
private final ProjectConfig allProjects;
|
||||||
|
|
||||||
public Util() {
|
public Util() {
|
||||||
all = new HashMap<>();
|
all = new HashMap<>();
|
||||||
repoManager = new InMemoryRepositoryManager();
|
repoManager = new InMemoryRepositoryManager();
|
||||||
try {
|
try {
|
||||||
Repository repo = repoManager.createRepository(allProjectsName);
|
Repository repo = repoManager.createRepository(allProjectsName);
|
||||||
parent.load(repo);
|
allProjects = new ProjectConfig(new Project.NameKey(allProjectsName.get()));
|
||||||
parent.getLabelSections().put(CR.getName(), CR);
|
allProjects.load(repo);
|
||||||
add(parent);
|
allProjects.getLabelSections().put(CR.getName(), CR);
|
||||||
|
add(allProjects);
|
||||||
} catch (IOException | ConfigInvalidException e) {
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -281,10 +283,6 @@ public class Util {
|
|||||||
injector.getInstance(ChangeControl.AssistedFactory.class);
|
injector.getInstance(ChangeControl.AssistedFactory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectConfig getParentConfig() {
|
|
||||||
return this.parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(ProjectConfig pc) {
|
public void add(ProjectConfig pc) {
|
||||||
PrologEnvironment.Factory envFactory = null;
|
PrologEnvironment.Factory envFactory = null;
|
||||||
ProjectControl.AssistedFactory projectControlFactory = null;
|
ProjectControl.AssistedFactory projectControlFactory = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user