RefControl: Include ref name in exception when permission check fails

Bug: Issue 7667
Change-Id: I627bfcb393f77cea3dc22449b197e47fb5d93a8f
This commit is contained in:
David Pursehouse 2017-11-08 14:36:32 +09:00
parent 239de04264
commit 9b603623fd
2 changed files with 13 additions and 5 deletions

View File

@ -44,7 +44,7 @@ public class CreateBranchIT extends AbstractDaemonTest {
@Test
public void createBranch_Forbidden() throws Exception {
setApiUser(user);
assertCreateFails(AuthException.class);
assertCreateFails(AuthException.class, "create not permitted for refs/heads/test");
}
@Test
@ -68,7 +68,7 @@ public class CreateBranchIT extends AbstractDaemonTest {
@Test
public void createBranchByAdminCreateReferenceBlocked_Forbidden() throws Exception {
blockCreateReference();
assertCreateFails(AuthException.class);
assertCreateFails(AuthException.class, "create not permitted for refs/heads/test");
}
@Test
@ -76,7 +76,7 @@ public class CreateBranchIT extends AbstractDaemonTest {
grantOwner();
blockCreateReference();
setApiUser(user);
assertCreateFails(AuthException.class);
assertCreateFails(AuthException.class, "create not permitted for refs/heads/test");
}
private void blockCreateReference() throws Exception {
@ -96,8 +96,16 @@ public class CreateBranchIT extends AbstractDaemonTest {
assertThat(created.ref).isEqualTo(Constants.R_HEADS + branch.getShortName());
}
private void assertCreateFails(Class<? extends RestApiException> errType) throws Exception {
private void assertCreateFails(Class<? extends RestApiException> errType, String errMsg)
throws Exception {
exception.expect(errType);
if (errMsg != null) {
exception.expectMessage(errMsg);
}
branch().create(new BranchInput());
}
private void assertCreateFails(Class<? extends RestApiException> errType) throws Exception {
assertCreateFails(errType, null);
}
}

View File

@ -532,7 +532,7 @@ public class RefControl {
@Override
public void check(RefPermission perm) throws AuthException, PermissionBackendException {
if (!can(perm)) {
throw new AuthException(perm.describeForException() + " not permitted");
throw new AuthException(perm.describeForException() + " not permitted for " + getRefName());
}
}