Check delete change with PermissionBackend

Deleting the entire change is slightly differently from deleting a
draft patch set.  Update only the change deletion path.

Update test assertions to expect the new generic messages thrown
by the PermissionBackend.

Change-Id: If5a83e386304d8f84db37f6c02f9c35cd5ae4266
This commit is contained in:
Shawn Pearce
2017-02-20 16:53:42 -08:00
committed by David Pursehouse
parent b5798658f5
commit 79ce708c38
8 changed files with 81 additions and 52 deletions

View File

@@ -557,11 +557,10 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result changeResult =
pushFactory.create(db, user.getIdent(), testRepo).to("refs/for/master");
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
setApiUser(user);
exception.expect(AuthException.class);
exception.expectMessage(String.format("Deleting change %s is not permitted", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
}
@@ -605,11 +604,10 @@ public class ChangeIT extends AbstractDaemonTest {
try {
PushOneCommit.Result changeResult = createChange();
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
setApiUser(user);
exception.expect(AuthException.class);
exception.expectMessage(String.format("Deleting change %s is not permitted", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
} finally {
removePermission(Permission.DELETE_OWN_CHANGES, project, "refs/*");
@@ -633,13 +631,12 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result changeResult =
pushFactory.create(db, user.getIdent(), testRepo).to("refs/for/master");
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
setApiUser(user);
gApi.changes().id(changeId).abandon();
exception.expect(AuthException.class);
exception.expectMessage(String.format("Deleting change %s is not permitted", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
}
@@ -661,12 +658,11 @@ public class ChangeIT extends AbstractDaemonTest {
public void deleteMergedChange() throws Exception {
PushOneCommit.Result changeResult = createChange();
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
merge(changeResult);
exception.expect(MethodNotAllowedException.class);
exception.expectMessage(String.format("Deleting merged change %s is not allowed", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
}
@@ -679,13 +675,12 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result changeResult =
pushFactory.create(db, user.getIdent(), testRepo).to("refs/for/master");
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
merge(changeResult);
setApiUser(user);
exception.expect(MethodNotAllowedException.class);
exception.expectMessage(String.format("Deleting merged change %s is not allowed", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
} finally {
removePermission(Permission.DELETE_OWN_CHANGES, project, "refs/*");

View File

@@ -82,14 +82,13 @@ public class DraftChangeIT extends AbstractDaemonTest {
PushOneCommit.Result changeResult = createDraftChange();
changeResult.assertOkStatus();
String changeId = changeResult.getChangeId();
Change.Id id = changeResult.getChange().getId();
// The user needs to be able to see the draft change (which reviewers can).
gApi.changes().id(changeId).addReviewer(user.fullName);
setApiUser(user);
exception.expect(AuthException.class);
exception.expectMessage(String.format("Deleting change %s is not permitted", id));
exception.expectMessage("delete not permitted");
gApi.changes().id(changeId).delete();
}