use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsHandlerTest method getPermissions_whenTheNameDoesntStartWithASlash_fixesTheName.
@Test
public void getPermissions_whenTheNameDoesntStartWithASlash_fixesTheName() {
List<PermissionEntry> accessControlList = newArrayList();
when(permissionService.getPermissions(any(CredentialVersion.class), eq(auditRecordParameters), eq(CREDENTIAL_NAME))).thenReturn(accessControlList);
when(permissionCheckingService.hasPermission(any(String.class), eq(CREDENTIAL_NAME), eq(PermissionOperation.READ_ACL))).thenReturn(true);
PermissionsView response = subject.getPermissions(CREDENTIAL_NAME, auditRecordParameters);
assertThat(response.getCredentialName(), equalTo(CREDENTIAL_NAME));
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsHandlerTest method getPermissions_verifiesTheUserHasPermissionToReadTheAcl_andReturnsTheAclResponse.
@Test
public void getPermissions_verifiesTheUserHasPermissionToReadTheAcl_andReturnsTheAclResponse() {
ArrayList<PermissionOperation> operations = newArrayList(PermissionOperation.READ, PermissionOperation.WRITE);
when(permissionCheckingService.hasPermission(any(String.class), eq(CREDENTIAL_NAME), eq(PermissionOperation.READ_ACL))).thenReturn(true);
PermissionEntry permissionEntry = new PermissionEntry(ACTOR_NAME, operations);
List<PermissionEntry> accessControlList = newArrayList(permissionEntry);
when(permissionService.getPermissions(credentialVersion, auditRecordParameters, CREDENTIAL_NAME)).thenReturn(accessControlList);
PermissionsView response = subject.getPermissions(CREDENTIAL_NAME, auditRecordParameters);
List<PermissionEntry> accessControlEntries = response.getPermissions();
assertThat(response.getCredentialName(), equalTo(CREDENTIAL_NAME));
assertThat(accessControlEntries, hasSize(1));
PermissionEntry entry = accessControlEntries.get(0);
assertThat(entry.getActor(), equalTo(ACTOR_NAME));
List<PermissionOperation> allowedOperations = entry.getAllowedOperations();
assertThat(allowedOperations, contains(equalTo(PermissionOperation.READ), equalTo(PermissionOperation.WRITE)));
}
use of org.cloudfoundry.credhub.request.PermissionEntry in project credhub by cloudfoundry-incubator.
the class PermissionsHandlerTest method setPermissions_whenUserUpdatesOwnPermission_throwsException.
@Test
public void setPermissions_whenUserUpdatesOwnPermission_throwsException() {
when(permissionCheckingService.hasPermission(any(String.class), eq(CREDENTIAL_NAME), eq(PermissionOperation.WRITE_ACL))).thenReturn(true);
when(permissionCheckingService.userAllowedToOperateOnActor(ACTOR_NAME)).thenReturn(false);
List<PermissionEntry> accessControlList = Arrays.asList(new PermissionEntry(ACTOR_NAME, Arrays.asList(PermissionOperation.READ)));
when(permissionsRequest.getCredentialName()).thenReturn(CREDENTIAL_NAME);
when(permissionsRequest.getPermissions()).thenReturn(accessControlList);
try {
subject.setPermissions(permissionsRequest, auditRecordParameters);
} catch (InvalidPermissionOperationException e) {
assertThat(e.getMessage(), equalTo("error.permission.invalid_update_operation"));
verify(permissionService, times(0)).savePermissions(any(), any(), eq(auditRecordParameters), eq(false), eq(CREDENTIAL_NAME));
}
}
Aggregations