use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class NoOverwriteTest method whenMultipleThreadsPutWithSameNameAndNoOverwrite_itShouldNotOverwrite.
@Test
public void whenMultipleThreadsPutWithSameNameAndNoOverwrite_itShouldNotOverwrite() throws Exception {
runRequestsConcurrently(CREDENTIAL_NAME, ",\"value\":\"thread1\"", ",\"value\":\"thread2\"", () -> put("/api/v1/data"));
MvcResult result1 = responses[0].andDo(print()).andReturn();
final DocumentContext context1 = JsonPath.parse(result1.getResponse().getContentAsString());
MvcResult result2 = responses[1].andDo(print()).andReturn();
final DocumentContext context2 = JsonPath.parse(result2.getResponse().getContentAsString());
assertThat(context1.read("$.value"), equalTo(context2.read("$.value")));
String winningValue = context1.read("$.value");
String tokenForWinningActor = ImmutableMap.of("thread1", UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "thread2", UAA_OAUTH2_CLIENT_CREDENTIALS_TOKEN).get(winningValue);
String winningActor = ImmutableMap.of("thread1", UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "thread2", UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID).get(winningValue);
MvcResult result = mockMvc.perform(get("/api/v1/permissions?credential_name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + tokenForWinningActor)).andDo(print()).andExpect(status().isOk()).andReturn();
String content = result.getResponse().getContentAsString();
PermissionsView acl = JsonTestHelper.deserialize(content, PermissionsView.class);
assertThat(acl.getPermissions(), containsInAnyOrder(samePropertyValuesAs(new PermissionEntry(winningActor, asList(READ, WRITE, DELETE, READ_ACL, WRITE_ACL))), samePropertyValuesAs(new PermissionEntry("uaa-client:a-different-actor", asList(READ)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionAndCredentialTest method hasUnchangedAcl.
private void hasUnchangedAcl() throws Exception {
MvcResult result = mockMvc.perform(get("/api/v1/permissions?credential_name=" + "/test-password").header("Authorization", "Bearer " + UAA_OAUTH2_PASSWORD_GRANT_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(UAA_OAUTH2_CLIENT_CREDENTIALS_ACTOR_ID, asList(READ, WRITE)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionAndCredentialTest method getAcl.
private PermissionsView getAcl(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"));
return acl;
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointTest method POST_whenTheUserHasPermissionToWritePermissions_updatesPermissions.
@Test
public void POST_whenTheUserHasPermissionToWritePermissions_updatesPermissions() throws Exception {
Long initialCount = eventAuditRecordRepository.count();
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "read", "delete");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.READ, "dan"), new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.DELETE, "dan")));
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "write", "read");
auditingHelper.verifyAuditing(AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_ACTOR_ID, "/api/v1/permissions", 201, newArrayList(new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.READ, "dan"), new EventAuditRecordParameters(ACL_UPDATE, credentialName, PermissionOperation.WRITE, "dan")));
// 2 from initialPost, 2 from updatePost
assertThat(eventAuditRecordRepository.count(), equalTo(4L + initialCount));
PermissionsView acl = RequestHelper.getPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN);
assertThat(acl.getPermissions(), hasSize(2));
assertThat(acl.getCredentialName(), equalTo(credentialName));
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", asList(PermissionOperation.READ, PermissionOperation.WRITE, PermissionOperation.DELETE)))));
}
use of org.cloudfoundry.credhub.view.PermissionsView in project credhub by cloudfoundry-incubator.
the class PermissionsEndpointTest method GET_whenTheUserHasPermissionToAccessPermissions_returnPermissions.
@Test
public void GET_whenTheUserHasPermissionToAccessPermissions_returnPermissions() throws Exception {
RequestHelper.grantPermissions(mockMvc, credentialName, AuthConstants.UAA_OAUTH2_PASSWORD_GRANT_TOKEN, "dan", "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("dan", asList(PermissionOperation.READ)))));
verifyAudit(ACL_ACCESS, credentialName, 200);
}
Aggregations