Search in sources :

Example 31 with RangerService

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

the class TestServiceREST method test10getServiceById.

@Test
public void test10getServiceById() throws Exception {
    RangerService rangerService = rangerService();
    Mockito.when(svcStore.getService(rangerService.getId())).thenReturn(rangerService);
    RangerService dbRangerService = serviceREST.getService(rangerService.getId());
    Assert.assertNotNull(dbRangerService);
    Assert.assertEquals(dbRangerService.getId(), dbRangerService.getId());
    Mockito.verify(svcStore).getService(dbRangerService.getId());
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 32 with RangerService

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

the class TestServiceREST method test26getServices.

@Test
public void test26getServices() throws Exception {
    List<RangerService> ret = new ArrayList<RangerService>();
    SearchFilter filter = new SearchFilter();
    filter.setParam(SearchFilter.POLICY_NAME, "policyName");
    filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
    Mockito.when(svcStore.getServices(filter)).thenReturn(ret);
    List<RangerService> dbRangerService = serviceREST.getServices(filter);
    Assert.assertNotNull(dbRangerService);
    Mockito.verify(svcStore).getServices(filter);
}
Also used : ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 33 with RangerService

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

the class TestTagREST method test56getSecureServiceTagsIfUpdatedIsAllowedFalse.

@Test
public void test56getSecureServiceTagsIfUpdatedIsAllowedFalse() {
    boolean isAdmin = false;
    boolean isKeyAdmin = false;
    boolean isAllowed = false;
    ServiceTags oldServiceTag = new ServiceTags();
    oldServiceTag.setServiceName(serviceName);
    oldServiceTag.setTagVersion(5L);
    XXService xService = new XXService();
    xService.setId(id);
    xService.setName(serviceName);
    xService.setType(5L);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(id);
    xServiceDef.setVersion(5L);
    RangerService rangerService = new RangerService();
    rangerService.setId(id);
    rangerService.setName(serviceName);
    XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
    Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
    Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
    Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
    Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    try {
        Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
    } catch (Exception e) {
    }
    Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
    Mockito.verify(bizUtil).isAdmin();
    Mockito.verify(bizUtil).isKeyAdmin();
    Mockito.verify(daoManager).getXXService();
    Mockito.verify(xXServiceDao).findByName(serviceName);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(xXServiceDefDao).getById(xService.getType());
    try {
        Mockito.verify(svcStore).getServiceByName(serviceName);
    } catch (Exception e) {
    }
    Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) WebApplicationException(javax.ws.rs.WebApplicationException) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 34 with RangerService

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

the class TestTagREST method test55getSecureServiceTagsIfUpdatedIsAdminFalse.

@Test
public void test55getSecureServiceTagsIfUpdatedIsAdminFalse() {
    boolean isAdmin = false;
    boolean isKeyAdmin = false;
    boolean isAllowed = true;
    ServiceTags oldServiceTag = new ServiceTags();
    oldServiceTag.setServiceName(serviceName);
    oldServiceTag.setTagVersion(5L);
    XXService xService = new XXService();
    xService.setId(id);
    xService.setName(serviceName);
    xService.setType(5L);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(id);
    xServiceDef.setVersion(5L);
    RangerService rangerService = new RangerService();
    rangerService.setId(id);
    rangerService.setName(serviceName);
    XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
    Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
    Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
    Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
    Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    try {
        Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
    } catch (Exception e) {
    }
    Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
    try {
        Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
    } catch (Exception e) {
    }
    ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
    Assert.assertNotNull(result.getServiceName());
    Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
    Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
    Mockito.verify(bizUtil).isAdmin();
    Mockito.verify(bizUtil).isKeyAdmin();
    Mockito.verify(daoManager).getXXService();
    Mockito.verify(xXServiceDao).findByName(serviceName);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(xXServiceDefDao).getById(xService.getType());
    try {
        Mockito.verify(svcStore).getServiceByName(serviceName);
    } catch (Exception e) {
    }
    Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
    try {
        Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
    } catch (Exception e) {
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 35 with RangerService

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

the class TestTagREST method test54getSecureServiceTagsIfUpdatedIsKeyAdminFalse.

@Test
public void test54getSecureServiceTagsIfUpdatedIsKeyAdminFalse() {
    boolean isAdmin = false;
    boolean isKeyAdmin = false;
    boolean isAllowed = true;
    ServiceTags oldServiceTag = new ServiceTags();
    oldServiceTag.setServiceName(serviceName);
    oldServiceTag.setTagVersion(5L);
    XXService xService = new XXService();
    xService.setId(id);
    xService.setName(serviceName);
    xService.setType(5L);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(id);
    xServiceDef.setVersion(5L);
    xServiceDef.setImplclassname("org.apache.ranger.services.kms.RangerServiceKMS");
    RangerService rangerService = new RangerService();
    rangerService.setId(id);
    rangerService.setName(serviceName);
    XXServiceDao xXServiceDao = Mockito.mock(XXServiceDao.class);
    XXServiceDefDao xXServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(bizUtil.isAdmin()).thenReturn(isAdmin);
    Mockito.when(bizUtil.isKeyAdmin()).thenReturn(isKeyAdmin);
    Mockito.when(daoManager.getXXService()).thenReturn(xXServiceDao);
    Mockito.when(xXServiceDao.findByName(serviceName)).thenReturn(xService);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xXServiceDefDao);
    Mockito.when(xXServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
    try {
        Mockito.when(svcStore.getServiceByName(serviceName)).thenReturn(rangerService);
    } catch (Exception e) {
    }
    Mockito.when(bizUtil.isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download)).thenReturn(isAllowed);
    try {
        Mockito.when(tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion)).thenReturn(oldServiceTag);
    } catch (Exception e) {
    }
    ServiceTags result = tagREST.getSecureServiceTagsIfUpdated(serviceName, lastKnownVersion, 0L, pluginId, null);
    Assert.assertNotNull(result.getServiceName());
    Assert.assertEquals(result.getServiceName(), oldServiceTag.getServiceName());
    Assert.assertEquals(result.getTagVersion(), oldServiceTag.getTagVersion());
    Mockito.verify(bizUtil).isAdmin();
    Mockito.verify(bizUtil).isKeyAdmin();
    Mockito.verify(daoManager).getXXService();
    Mockito.verify(xXServiceDao).findByName(serviceName);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(xXServiceDefDao).getById(xService.getType());
    try {
        Mockito.verify(svcStore).getServiceByName(serviceName);
    } catch (Exception e) {
    }
    Mockito.verify(bizUtil).isUserAllowed(rangerService, Allowed_User_List_For_Tag_Download);
    try {
        Mockito.verify(tagStore).getServiceTagsIfUpdated(serviceName, lastKnownVersion);
    } catch (Exception e) {
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) XXServiceDao(org.apache.ranger.db.XXServiceDao) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12