Search in sources :

Example 1 with PermissionException

use of org.cloudfoundry.credhub.exceptions.PermissionException in project credhub by cloudfoundry-incubator.

the class PermissionedCredentialServiceTest method save_whenThereIsAnExistingCredentialWithACEs_shouldThrowAnExceptionIfItLacksPermission.

@Test
public void save_whenThereIsAnExistingCredentialWithACEs_shouldThrowAnExceptionIfItLacksPermission() {
    when(request.getType()).thenReturn("password");
    when(request.getOverwriteMode()).thenReturn(CredentialWriteMode.NO_OVERWRITE.mode);
    when(credentialVersionDataService.findMostRecent(CREDENTIAL_NAME)).thenReturn(existingCredentialVersion);
    when(permissionCheckingService.hasPermission(userContext.getActor(), CREDENTIAL_NAME, WRITE_ACL)).thenReturn(false);
    accessControlEntries.add(new PermissionEntry("some_actor", Arrays.asList(PermissionOperation.READ_ACL)));
    try {
        subject.save(existingCredentialVersion, credentialValue, request, auditRecordParameters);
    } catch (PermissionException pe) {
        assertThat(pe.getMessage(), equalTo("error.credential.invalid_access"));
    }
}
Also used : PermissionException(org.cloudfoundry.credhub.exceptions.PermissionException) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) Test(org.junit.Test)

Aggregations

PermissionException (org.cloudfoundry.credhub.exceptions.PermissionException)1 PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)1 Test (org.junit.Test)1