Fix refPattern when using username/shardeduserid pattern with regexp

The special regexp caracters ('{', '}') from gerrit pattern are causing
an exception. As ${username} and ${shardeduserid} are only meaningful to
gerrit, we substitute them for placeholders.

Unlike what is done in RefPatternMatcher.ExpandParameters, the
placeholder does not contain ':' but '_' to be correctly evaluated by
Repository.isValidRefName later on.

Bug: Issue 3340
Change-Id: Iedf3022f6ce3068f7e9534f224cf05bb99b0f970
This commit is contained in:
Guillaume Chauvel
2020-02-09 18:46:32 +01:00
committed by David Pursehouse
parent 9a5141f0ad
commit 1b4b264adf
2 changed files with 18 additions and 1 deletions

View File

@@ -525,6 +525,13 @@ public class RefControlTest {
assertCanUpload(u);
}
@Test
public void usernamePatternRegExpCanUploadToAnyRef() throws Exception {
allow(local, PUSH, REGISTERED_USERS, "^refs/heads/users/${username}/(public|private)/.+");
ProjectControl u = user(local, "a-registered-user");
assertCanUpdate("refs/heads/users/a-registered-user/private/a", u);
}
@Test
public void usernamePatternNonRegex() throws Exception {
allow(local, READ, DEVS, "refs/sb/${username}/heads/*");
@@ -943,6 +950,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(expected = InvalidNameException.class)