CreateBranch: Test that branches cannot be created under 'refs/for/'

This increases the test coverage of the CreateBranch REST endpoint.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I7593ff7031e46f6ca53510f9622d974a31d7382e
This commit is contained in:
Edwin Kempin
2020-03-25 10:48:49 +01:00
parent 9118e7a74c
commit b4ab1d3a6a

View File

@@ -45,6 +45,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.events.RefReceivedEvent;
import com.google.gerrit.server.git.validators.RefOperationValidationListener;
import com.google.gerrit.server.git.validators.ValidationMessage;
import com.google.gerrit.server.util.MagicBranch;
import com.google.gerrit.server.validators.ValidationException;
import com.google.inject.Inject;
import java.io.IOException;
@@ -327,6 +328,14 @@ public class CreateBranchIT extends AbstractDaemonTest {
"invalid revision \"invalid\trevision\"");
}
@Test
public void cannotCreateBranchInMagicBranchNamespace() throws Exception {
assertCreateFails(
BranchNameKey.create(project, MagicBranch.NEW_CHANGE + "foo"),
BadRequestException.class,
"not allowed to create branches under \"" + MagicBranch.NEW_CHANGE + "\"");
}
@Test
public void createBranchLeadingSlashesAreRemoved() throws Exception {
BranchNameKey expectedNameKey = BranchNameKey.create(project, "test");