RefControl: Include ref name in exception when permission check fails
Bug: Issue 7667 Change-Id: I627bfcb393f77cea3dc22449b197e47fb5d93a8f
This commit is contained in:
parent
239de04264
commit
9b603623fd
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user