Search in sources :

Example 21 with PermissionsView

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)))));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) EventAuditRecordParameters(org.cloudfoundry.credhub.audit.EventAuditRecordParameters) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with PermissionsView

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));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with PermissionsView

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));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) PasswordCredentialVersion(org.cloudfoundry.credhub.domain.PasswordCredentialVersion) CredentialVersion(org.cloudfoundry.credhub.domain.CredentialVersion) Test(org.junit.Test)

Example 24 with PermissionsView

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)));
}
Also used : PermissionsView(org.cloudfoundry.credhub.view.PermissionsView) PermissionOperation(org.cloudfoundry.credhub.request.PermissionOperation) PermissionEntry(org.cloudfoundry.credhub.request.PermissionEntry) Test(org.junit.Test)

Aggregations

PermissionsView (org.cloudfoundry.credhub.view.PermissionsView)24 Test (org.junit.Test)20 PermissionEntry (org.cloudfoundry.credhub.request.PermissionEntry)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 EventAuditRecordParameters (org.cloudfoundry.credhub.audit.EventAuditRecordParameters)7 MvcResult (org.springframework.test.web.servlet.MvcResult)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 DocumentContext (com.jayway.jsonpath.DocumentContext)2 List (java.util.List)2 CredentialVersion (org.cloudfoundry.credhub.domain.CredentialVersion)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 PasswordCredentialVersion (org.cloudfoundry.credhub.domain.PasswordCredentialVersion)1 PermissionOperation (org.cloudfoundry.credhub.request.PermissionOperation)1 Matchers.anyString (org.mockito.Matchers.anyString)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1