use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointWithoutEnforcementTest method POST_whenTheUserHasPermissionToWritePermissions_returnsPermissions.
@Test
public void POST_whenTheUserHasPermissionToWritePermissions_returnsPermissions() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read", "write");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.READ, "dan"), new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.WRITE, "dan")));
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "isobel", "delete");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(AuditingOperationCode.ACL_UPDATE, credentialName, PermissionOperation.DELETE, "isobel")));
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getPermissions(), hasSize(3));
assertThat(permissions.getCredentialName(), equalTo(credentialName));
assertThat(permissions.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, asList(PermissionOperation.READ, PermissionOperation.WRITE, PermissionOperation.DELETE, PermissionOperation.READ_ACL, PermissionOperation.WRITE_ACL))), samePropertyValuesAs(new PermissionEntry("dan", asList(PermissionOperation.READ, PermissionOperation.WRITE))), samePropertyValuesAs(new PermissionEntry("isobel", asList(PermissionOperation.DELETE)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsControllerTest method GET_returnsThePermissionsForTheCredential.
@Test
public void GET_returnsThePermissionsForTheCredential() throws Exception {
PermissionsView permissionsView = new PermissionsView("/test_credential_name", newArrayList());
when(permissionsHandler.getPermissions(eq("/test_credential_name"), any(List.class))).thenReturn(permissionsView);
PermissionsView permissions = getPermissions(mockMvc, "/test_credential_name", UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getCredentialName(), equalTo("/test_credential_name"));
assertThat(permissions.getPermissions(), hasSize(0));
}
use of org.cloudfoundry.credhub.view.PermissionsView 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.view.PermissionsView 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)));
}
Aggregations