ChangeApiImpl: Don't catch RestApiException on rebase
RestApiException (and any subclass of it) is caught and rethrown as a RestApiException with a generic message. This causes the actual exception type and message to be lost. Don't catch RestApiException; allow the original to propagate. Also add tests in ChangeIT to verify behavior when rebasing with and without the rebase permission. Change-Id: Ia303dcf0b7158aafa82adfaeeaabd76a8a980b15
This commit is contained in:
		@@ -383,6 +383,46 @@ public class ChangeIT extends AbstractDaemonTest {
 | 
			
		||||
    gApi.changes().id(changeId).current().rebase();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void rebaseNotAllowedWithoutPermission() throws Exception {
 | 
			
		||||
    // Create two changes both with the same parent
 | 
			
		||||
    PushOneCommit.Result r = createChange();
 | 
			
		||||
    testRepo.reset("HEAD~1");
 | 
			
		||||
    PushOneCommit.Result r2 = createChange();
 | 
			
		||||
 | 
			
		||||
    // Approve and submit the first change
 | 
			
		||||
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
 | 
			
		||||
    revision.review(ReviewInput.approve());
 | 
			
		||||
    revision.submit();
 | 
			
		||||
 | 
			
		||||
    // Rebase the second
 | 
			
		||||
    String changeId = r2.getChangeId();
 | 
			
		||||
    setApiUser(user);
 | 
			
		||||
    exception.expect(AuthException.class);
 | 
			
		||||
    exception.expectMessage("rebase not permitted");
 | 
			
		||||
    gApi.changes().id(changeId).rebase();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void rebaseAllowedWithPermission() throws Exception {
 | 
			
		||||
    // Create two changes both with the same parent
 | 
			
		||||
    PushOneCommit.Result r = createChange();
 | 
			
		||||
    testRepo.reset("HEAD~1");
 | 
			
		||||
    PushOneCommit.Result r2 = createChange();
 | 
			
		||||
 | 
			
		||||
    // Approve and submit the first change
 | 
			
		||||
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
 | 
			
		||||
    revision.review(ReviewInput.approve());
 | 
			
		||||
    revision.submit();
 | 
			
		||||
 | 
			
		||||
    grant(Permission.REBASE, project, "refs/heads/master", false, REGISTERED_USERS);
 | 
			
		||||
 | 
			
		||||
    // Rebase the second
 | 
			
		||||
    String changeId = r2.getChangeId();
 | 
			
		||||
    setApiUser(user);
 | 
			
		||||
    gApi.changes().id(changeId).rebase();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void publish() throws Exception {
 | 
			
		||||
    PushOneCommit.Result r = createChange("refs/drafts/master");
 | 
			
		||||
 
 | 
			
		||||
@@ -340,7 +340,7 @@ class ChangeApiImpl implements ChangeApi {
 | 
			
		||||
  public void rebase(RebaseInput in) throws RestApiException {
 | 
			
		||||
    try {
 | 
			
		||||
      rebase.apply(change, in);
 | 
			
		||||
    } catch (EmailException | OrmException | UpdateException | RestApiException | IOException e) {
 | 
			
		||||
    } catch (EmailException | OrmException | UpdateException | IOException e) {
 | 
			
		||||
      throw new RestApiException("Cannot rebase change", e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user