use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionAndCredentialTest method hasEditedAcl.
private void hasEditedAcl(String token) throws Exception {
MvcResult result = mockMvc.perform(get("/api/v1/permissions?credential_name=/test-password").header("Authorization", "Bearer " + token)).andDo(print()).andExpect(status().isOk()).andReturn();
String content = result.getResponse().getContentAsString();
PermissionsView acl = JsonTestHelper.deserialize(content, PermissionsView.class);
assertThat(acl.getCredentialName(), equalTo("/test-password"));
assertThat(acl.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, asList(READ, WRITE, DELETE, READ_ACL, WRITE_ACL))), samePropertyValuesAs(new PermissionEntry(MTLS_APP_GUID, asList(WRITE))), samePropertyValuesAs(new PermissionEntry(UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID, asList(READ, WRITE, DELETE)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointTest method POST_whenTheLeadingSlashIsMissing_prependsTheSlashCorrectly.
@Test
public void POST_whenTheLeadingSlashIsMissing_prependsTheSlashCorrectly() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.READ, "dan")));
PermissionsView acl = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(acl.getCredentialName(), equalTo(credentialName));
assertThat(acl.getPermissions(), hasSize(2));
assertThat(acl.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", singletonList(PermissionOperation.READ)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointTest method GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions.
@Test
public void GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialNameWithoutLeadingSlash, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
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)))));
verifyAudit(ACL_ACCESS, credentialName, 200);
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointTest method DELETE_whenTheActorDoesNotHavePermissionToDeletePermissions_returnsNotFound.
@Test
public void DELETE_whenTheActorDoesNotHavePermissionToDeletePermissions_returnsNotFound() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read");
RequestHelper.expectStatusWhenDeletingPermissions(mockMvc, 404, credentialName, "dan", AuthConstants.UAA_OAUTH2_CLIENT_CREDENTIALS_TOKEN);
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID, "/api/v1/permissions", 404, newArrayList(new EventAuditRecordParameters(ACL_DELETE, credentialName, PermissionOperation.READ, "dan")));
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(permissions.getPermissions(), hasSize(2));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointWithoutEnforcementTest method GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions.
@Test
public void GET_whenTheUserHasPermissionToAccessPermissions_andTheLeadingSlashIsMissing_returnsPermissions() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "test-actor", "read");
PermissionsView permissions = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
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("test-actor", asList(PermissionOperation.READ)))));
verifyAudit(AuditingOperationCode.ACL_ACCESS, credentialName, 200);
}
Aggregations