Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  Fix Access when the only readable ref is a RegExp with a gerrit pattern
  Fix refPattern when using username/shardeduserid pattern with regexp
  Enable optional DEBUG level logs for query tests

Adjust RefControlTest to use projectOperations.

Change-Id: I80f6158993e0b9e4389f73ad25c3364f2a1eef62
This commit is contained in:
David Pursehouse
2020-02-14 09:02:53 +09:00
13 changed files with 142 additions and 5 deletions

View File

@@ -476,6 +476,21 @@ public class RefControlTest {
assertCanUpload(u);
}
@Test
public void usernamePatternRegExpCanUploadToAnyRef() throws Exception {
projectOperations
.project(localKey)
.forUpdate()
.add(
allow(PUSH)
.ref("^refs/heads/users/${username}/(public|private)/.+")
.group(REGISTERED_USERS))
.update();
ProjectControl u = user(localKey, "a-registered-user");
assertCanUpload(u);
assertCanUpdate("refs/heads/users/a-registered-user/private/a", u);
}
@Test
public void usernamePatternNonRegex() throws Exception {
projectOperations
@@ -500,6 +515,8 @@ public class RefControlTest {
ProjectControl u = user(localKey, "d.v", DEVS);
ProjectControl d = user(localKey, "dev", DEVS);
assertCanAccess(u);
assertCanAccess(d);
assertCannotRead("refs/sb/dev/heads/foobar", u);
assertCanRead("refs/sb/dev/heads/foobar", d);
}
@@ -1127,6 +1144,7 @@ public class RefControlTest {
RefPattern.validate("^refs/heads/*");
RefPattern.validate("^refs/tags/[0-9a-zA-Z-_.]+");
RefPattern.validate("refs/heads/review/${username}/*");
RefPattern.validate("^refs/heads/review/${username}/.+");
}
@Test

View File

@@ -91,10 +91,14 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -146,6 +150,20 @@ public abstract class AbstractQueryAccountsTest extends GerritServerTests {
protected abstract Injector createInjector();
@BeforeClass
public static void setLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.DEBUG);
}
}
@AfterClass
public static void resetLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.INFO);
}
}
@Before
public void setUpInjector() throws Exception {
lifecycle = new LifecycleManager();

View File

@@ -23,8 +23,10 @@ java_library(
"//lib:guava",
"//lib:jgit",
"//lib/guice",
"//lib/log:log4j",
"//lib/truth",
"//lib/truth:truth-java8-extension",
"//resources:log4j-config",
],
)

View File

@@ -130,6 +130,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -141,7 +143,9 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -204,6 +208,20 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
protected abstract Injector createInjector();
@BeforeClass
public static void setLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.DEBUG);
}
}
@AfterClass
public static void resetLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.INFO);
}
}
@Before
public void setUpInjector() throws Exception {
lifecycle = new LifecycleManager();

View File

@@ -32,7 +32,9 @@ java_library(
"//lib:jgit",
"//lib:jgit-junit",
"//lib/guice",
"//lib/log:log4j",
"//lib/truth",
"//resources:log4j-config",
],
)

View File

@@ -68,8 +68,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -115,6 +119,20 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
protected abstract Injector createInjector();
@BeforeClass
public static void setLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.DEBUG);
}
}
@AfterClass
public static void resetLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.INFO);
}
}
@Before
public void setUpInjector() throws Exception {
lifecycle = new LifecycleManager();

View File

@@ -20,8 +20,10 @@ java_library(
"//lib:guava",
"//lib:jgit",
"//lib/guice",
"//lib/log:log4j",
"//lib/truth",
"//lib/truth:truth-java8-extension",
"//resources:log4j-config",
],
)

View File

@@ -68,8 +68,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
@@ -111,6 +115,20 @@ public abstract class AbstractQueryProjectsTest extends GerritServerTests {
protected abstract Injector createInjector();
@BeforeClass
public static void setLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.DEBUG);
}
}
@AfterClass
public static void resetLogLevel() {
if (Boolean.getBoolean("debug")) {
LogManager.getRootLogger().setLevel(Level.INFO);
}
}
@Before
public void setUpInjector() throws Exception {
lifecycle = new LifecycleManager();

View File

@@ -21,7 +21,9 @@ java_library(
"//lib:guava",
"//lib:jgit",
"//lib/guice",
"//lib/log:log4j",
"//lib/truth",
"//resources:log4j-config",
],
)