Search in sources :

Example 16 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationServiceTest method deleteNamespaceIamRoleAuthorizationAssertCallsDependenciesAndResultExpected.

@Test
public void deleteNamespaceIamRoleAuthorizationAssertCallsDependenciesAndResultExpected() {
    String expectedNamespace = "namespace";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    List<NamespaceIamRoleAuthorizationEntity> expectedNamespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity1.setIamRoleName("iamRoleName1");
    namespaceIamRoleAuthorizationEntity1.setDescription("description1");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setNamespace(expectedNamespaceEntity);
    namespaceIamRoleAuthorizationEntity2.setIamRoleName("iamRoleName2");
    namespaceIamRoleAuthorizationEntity2.setDescription("description2");
    expectedNamespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(expectedNamespaceIamRoleAuthorizationEntities);
    NamespaceIamRoleAuthorization result = namespaceIamRoleAuthorizationServiceImpl.deleteNamespaceIamRoleAuthorization(expectedNamespace);
    assertNotNull(result);
    assertEquals(expectedNamespaceEntity.getCode(), result.getNamespace());
    assertNotNull(result.getIamRoles());
    assertEquals(2, result.getIamRoles().size());
    {
        IamRole iamRole = result.getIamRoles().get(0);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity1.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity1.getDescription(), iamRole.getIamRoleDescription());
    }
    {
        IamRole iamRole = result.getIamRoles().get(1);
        assertNotNull(iamRole);
        assertEquals(namespaceIamRoleAuthorizationEntity2.getIamRoleName(), iamRole.getIamRoleName());
        assertEquals(namespaceIamRoleAuthorizationEntity2.getDescription(), iamRole.getIamRoleDescription());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity1);
    verify(namespaceIamRoleAuthorizationDao).delete(namespaceIamRoleAuthorizationEntity2);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) NamespaceIamRoleAuthorization(org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization) ArrayList(java.util.ArrayList) IamRole(org.finra.herd.model.api.xml.IamRole) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test)

Example 17 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationServiceTest method getNamespaceIamRoleAuthorizationAssertErrorWhenNoEntitiesFound.

@Test
public void getNamespaceIamRoleAuthorizationAssertErrorWhenNoEntitiesFound() {
    String expectedNamespace = "namespace";
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("NAMESPACE");
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = Collections.emptyList();
    when(namespaceDaoHelper.getNamespaceEntity(any())).thenReturn(expectedNamespaceEntity);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    try {
        namespaceIamRoleAuthorizationServiceImpl.getNamespaceIamRoleAuthorization(expectedNamespace);
        fail();
    } catch (Exception e) {
        assertEquals(ObjectNotFoundException.class, e.getClass());
        assertEquals(String.format("Namespace IAM role authorizations for namespace \"%s\" do not exist", expectedNamespaceEntity.getCode()), e.getMessage());
    }
    verify(namespaceDaoHelper).getNamespaceEntity(expectedNamespace);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(namespaceDaoHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) Test(org.junit.Test)

Example 18 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationHelperTest method checkPermissionsAssertNoErrorWhenNamespaceAuthorizedToAllRoles.

@Test
public void checkPermissionsAssertNoErrorWhenNamespaceAuthorizedToAllRoles() {
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    String iamRoleName1 = "iamRoleName1";
    String iamRoleName2 = "iamRoleName2";
    Collection<String> requestedIamRoleNames = Arrays.asList(iamRoleName1, iamRoleName2);
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames);
    verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 19 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationHelperTest method checkPermissionsWithArrayAssertNoErrorWhenNamespaceAuthorizedToAllRoles.

@Test
public void checkPermissionsWithArrayAssertNoErrorWhenNamespaceAuthorizedToAllRoles() {
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    String iamRoleName1 = "iamRoleName1";
    String iamRoleName2 = "iamRoleName2";
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity1 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity1.setIamRoleName(iamRoleName1);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity1);
    NamespaceIamRoleAuthorizationEntity namespaceIamRoleAuthorizationEntity2 = new NamespaceIamRoleAuthorizationEntity();
    namespaceIamRoleAuthorizationEntity2.setIamRoleName(iamRoleName2);
    namespaceIamRoleAuthorizationEntities.add(namespaceIamRoleAuthorizationEntity2);
    when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, iamRoleName1, iamRoleName2);
    verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 20 with NamespaceIamRoleAuthorizationEntity

use of org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity in project herd by FINRAOS.

the class NamespaceIamRoleAuthorizationHelperTest method checkPermissionsAssertAccessDeniedWhenNamespaceNotAuthorizedToAllRole.

@Test
public void checkPermissionsAssertAccessDeniedWhenNamespaceNotAuthorizedToAllRole() {
    NamespaceEntity expectedNamespaceEntity = new NamespaceEntity();
    expectedNamespaceEntity.setCode("namespace");
    String iamRoleName1 = "iamRoleName1";
    String iamRoleName2 = "iamRoleName2";
    Collection<String> requestedIamRoleNames = Arrays.asList(iamRoleName1, iamRoleName2);
    List<NamespaceIamRoleAuthorizationEntity> namespaceIamRoleAuthorizationEntities = new ArrayList<>();
    when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
    when(namespaceIamRoleAuthorizationDao.getNamespaceIamRoleAuthorizations(any())).thenReturn(namespaceIamRoleAuthorizationEntities);
    try {
        namespaceIamRoleAuthorizationHelper.checkPermissions(expectedNamespaceEntity, requestedIamRoleNames);
        fail();
    } catch (AccessDeniedException e) {
        assertEquals("The namespace \"namespace\" does not have access to the following IAM roles: [iamRoleName1, iamRoleName2]", e.getMessage());
    }
    verify(configurationHelper).getBooleanProperty(ConfigurationValue.NAMESPACE_IAM_ROLE_AUTHORIZATION_ENABLED);
    verify(namespaceIamRoleAuthorizationDao).getNamespaceIamRoleAuthorizations(expectedNamespaceEntity);
    verifyNoMoreInteractions(configurationHelper, namespaceIamRoleAuthorizationDao);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) AccessDeniedException(org.springframework.security.access.AccessDeniedException) ArrayList(java.util.ArrayList) NamespaceIamRoleAuthorizationEntity(org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Aggregations

NamespaceIamRoleAuthorizationEntity (org.finra.herd.model.jpa.NamespaceIamRoleAuthorizationEntity)27 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)24 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)14 IamRole (org.finra.herd.model.api.xml.IamRole)13 NamespaceIamRoleAuthorization (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorization)12 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)7 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 List (java.util.List)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 NamespaceIamRoleAuthorizationUpdateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationUpdateRequest)2 NamespaceIamRoleAuthorizations (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizations)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeSet (java.util.TreeSet)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 NamespaceIamRoleAuthorizationCreateRequest (org.finra.herd.model.api.xml.NamespaceIamRoleAuthorizationCreateRequest)1