Search in sources :

Example 16 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneREST method testGetAllSecurityZone.

@Test(expected = WebApplicationException.class)
public void testGetAllSecurityZone() throws Exception {
    RangerSecurityZone securityZone = createRangerSecurityZone();
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    SearchFilter filter = new SearchFilter();
    when(searchUtil.getSearchFilter(request, securityZoneService.sortFields)).thenReturn(filter);
    Long securityZoneId = 2L;
    securityZone.setId(securityZoneId);
    List<RangerSecurityZone> zonesList = new ArrayList<>();
    zonesList.add(securityZone);
    RangerSecurityZoneList rangerZoneList = new RangerSecurityZoneList();
    rangerZoneList.setSecurityZoneList(zonesList);
    when(securityZoneStore.getSecurityZones(filter)).thenReturn(zonesList);
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
    RangerSecurityZoneList returnedZonesList = securityZoneREST.getAllZones(request);
    assertEquals(returnedZonesList.getResultSize(), rangerZoneList.getList().size());
    verify(securityZoneStore, times(1)).getSecurityZones(filter);
    // No access
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
    when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
    securityZoneREST.getAllZones(request);
    verify(securityZoneStore, times(0)).getSecurityZones(filter);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) RangerSecurityZoneList(org.apache.ranger.view.RangerSecurityZoneList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) Test(org.junit.Test)

Example 17 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneREST method testGetSecurityZoneById.

@Test(expected = WebApplicationException.class)
public void testGetSecurityZoneById() throws Exception {
    RangerSecurityZone securityZone = createRangerSecurityZone();
    Long securityZoneId = 2L;
    securityZone.setId(securityZoneId);
    when(securityZoneStore.getSecurityZone(securityZoneId)).thenReturn(securityZone);
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
    RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneId);
    assertEquals(securityZoneId, rangerSecurityZone.getId());
    verify(securityZoneStore, times(1)).getSecurityZone(securityZoneId);
    // No access
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
    when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
    securityZoneREST.getSecurityZone(securityZoneId);
    verify(securityZoneStore, times(0)).getSecurityZone(securityZoneId);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 18 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneREST method testDeleteSecurityZoneById.

@Test
public void testDeleteSecurityZoneById() throws Exception {
    RangerSecurityZone securityZone = createRangerSecurityZone();
    Long securityZoneId = 2L;
    securityZone.setId(securityZoneId);
    when(rangerBizUtil.isAdmin()).thenReturn(true);
    when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
    doNothing().when(validator).validate(securityZoneId, RangerValidator.Action.DELETE);
    securityZoneREST.deleteSecurityZone(securityZoneId);
    verify(securityZoneStore, times(1)).deleteSecurityZoneById(securityZoneId);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) Test(org.junit.Test)

Example 19 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneREST method testUpdateSecurityZone.

@Test
public void testUpdateSecurityZone() throws Exception {
    RangerSecurityZone rangerSecurityZoneToUpdate = createRangerSecurityZone();
    Long securityZoneId = 2L;
    XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
    XXService xService = Mockito.mock(XXService.class);
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    rangerSecurityZoneToUpdate.setId(securityZoneId);
    when(rangerBizUtil.isAdmin()).thenReturn(true);
    when(validatorFactory.getSecurityZoneValidator(svcStore, securityZoneStore)).thenReturn(validator);
    when(daoManager.getXXService()).thenReturn(xServiceDao);
    when(xServiceDao.findByName("test_service_1")).thenReturn(xService);
    when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    doNothing().when(validator).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
    when(securityZoneStore.updateSecurityZoneById(rangerSecurityZoneToUpdate)).thenReturn(rangerSecurityZoneToUpdate);
    RangerSecurityZone updatedRangerSecurityZone = securityZoneREST.updateSecurityZone(securityZoneId, rangerSecurityZoneToUpdate);
    assertEquals(rangerSecurityZoneToUpdate.getId(), updatedRangerSecurityZone.getId());
    verify(validator, times(1)).validate(rangerSecurityZoneToUpdate, RangerValidator.Action.UPDATE);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) Test(org.junit.Test)

Example 20 with RangerSecurityZone

use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.

the class TestSecurityZoneREST method testGetSecurityZoneByName.

@Test(expected = WebApplicationException.class)
public void testGetSecurityZoneByName() throws Exception {
    RangerSecurityZone securityZone = createRangerSecurityZone();
    Long securityZoneId = 2L;
    String securityZoneName = securityZone.getName();
    securityZone.setId(securityZoneId);
    when(securityZoneStore.getSecurityZoneByName(securityZoneName)).thenReturn(securityZone);
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(true);
    RangerSecurityZone rangerSecurityZone = securityZoneREST.getSecurityZone(securityZoneName);
    assertEquals(securityZoneName, rangerSecurityZone.getName());
    verify(securityZoneStore, times(1)).getSecurityZoneByName(securityZoneName);
    // No access
    when(rangerBizUtil.hasModuleAccess(Mockito.anyString())).thenReturn(false);
    when(restErrorUtil.createRESTException(Mockito.anyString(), Mockito.any())).thenReturn(new WebApplicationException());
    securityZoneREST.getSecurityZone(securityZoneName);
    verify(securityZoneStore, times(0)).getSecurityZoneByName(securityZoneName);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)68 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)27 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)16 WebApplicationException (javax.ws.rs.WebApplicationException)14 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 RangerService (org.apache.ranger.plugin.model.RangerService)11 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)10 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 XXTrxLog (org.apache.ranger.entity.XXTrxLog)9 RangerSecurityZoneService (org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService)7 HashMap (java.util.HashMap)6 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)3