DeleteBranchIT: Add tests for deleting branch by REST with full name
When calling DELETE with a branch's full name, i.e. refs/heads/branch,
the name must be URL encoded as mentioned in the documentation [1].
If the name is not encoded, the branch name gets parsed as "ref" and
then the delete fails with "404 Not Found".
Add tests for both cases: deleting with unencoded name, and deleting
with encoded name.
Note that the endpoint to delete multiple branches does not require
the names to be URL encoded because they are passed in the request
body rather than in the URL.
[1] http://gerrit-documentation.storage.googleapis.com/Documentation/2.14/rest-api.html#encoding
Change-Id: Ic96043854c4d9714eabe5be263a0dfbd2a543b43
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/project/DeleteBranchIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/project/DeleteBranchIT.java
index bcc6766..66c61f7 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/project/DeleteBranchIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/project/DeleteBranchIT.java
@@ -26,6 +26,7 @@
import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
+import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.reviewdb.client.Branch;
import org.junit.Before;
import org.junit.Test;
@@ -92,8 +93,22 @@
grantDelete();
String ref = branch.getShortName();
assertThat(ref).doesNotMatch(R_HEADS);
- RestResponse r = userRestSession.delete("/projects/" + project.get() + "/branches/" + ref);
- r.assertNoContent();
+ assertDeleteByRestSucceeds(ref);
+ }
+
+ @Test
+ public void deleteBranchByRestWithEncodedFullName() throws Exception {
+ grantDelete();
+ assertDeleteByRestSucceeds(Url.encode(branch.get()));
+ }
+
+ @Test
+ public void deleteBranchByRestFailsWithUnencodedFullName() throws Exception {
+ grantDelete();
+ RestResponse r =
+ userRestSession.delete("/projects/" + project.get() + "/branches/" + branch.get());
+ r.assertNotFound();
+ branch().get();
}
private void blockForcePush() throws Exception {
@@ -116,6 +131,13 @@
return gApi.projects().name(branch.getParentKey().get()).branch(branch.get());
}
+ private void assertDeleteByRestSucceeds(String ref) throws Exception {
+ RestResponse r = userRestSession.delete("/projects/" + project.get() + "/branches/" + ref);
+ r.assertNoContent();
+ exception.expect(ResourceNotFoundException.class);
+ branch().get();
+ }
+
private void assertDeleteSucceeds() throws Exception {
String branchRev = branch().get().revision;
branch().delete();