Search in sources :

Example 6 with XXResource

use of org.apache.ranger.entity.XXResource in project ranger by apache.

the class TestRangerBizUtil method testMatchHivePolicy_NoUserId.

@Test
public void testMatchHivePolicy_NoUserId() {
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    boolean bnlChk = rangerBizUtil.matchHivePolicy(resourceName, xResourceList, null, 0);
    Assert.assertFalse(bnlChk);
}
Also used : XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with XXResource

use of org.apache.ranger.entity.XXResource in project ranger by apache.

the class TestRangerBizUtil method testMatchHdfsPolicy_NoPremission.

@Test
public void testMatchHdfsPolicy_NoPremission() {
    VXResponse vXResponse = new VXResponse();
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    Mockito.when(stringUtil.split(Mockito.anyString(), Mockito.anyString())).thenReturn(new String[0]);
    boolean bnlChk = rangerBizUtil.matchHbasePolicy("/*/*/*", xResourceList, vXResponse, id, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(stringUtil).split(Mockito.anyString(), Mockito.anyString());
    Assert.assertFalse(bnlChk);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with XXResource

use of org.apache.ranger.entity.XXResource in project ranger by apache.

the class TestRangerBizUtil method testMatchHdfsPolicy_NoUserId.

@Test
public void testMatchHdfsPolicy_NoUserId() {
    VXResponse vXResponse = new VXResponse();
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    boolean bnlChk = rangerBizUtil.matchHbasePolicy(resourceName, xResourceList, vXResponse, null, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Assert.assertFalse(bnlChk);
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with XXResource

use of org.apache.ranger.entity.XXResource in project ranger by apache.

the class TestRangerBizUtil method testHasPermission_emptyResourceName.

@Test
public void testHasPermission_emptyResourceName() {
    VXResource vXResource = new VXResource();
    vXResource.setAssetId(12345L);
    XXPortalUser portalUser = new XXPortalUser();
    portalUser.setId(id);
    portalUser.setLoginId("12121");
    RangerContextHolder.getSecurityContext().getUserSession().setXXPortalUser(portalUser);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXUser xxUser = new XXUser();
    XXAsset xxAsset = new XXAsset();
    List<XXResource> lst = new ArrayList<XXResource>();
    XXResourceDao xxResourceDao = Mockito.mock(XXResourceDao.class);
    XXAssetDao xxAssetDao = Mockito.mock(XXAssetDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(userDao.getById(Mockito.anyLong())).thenReturn(portalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(Mockito.anyString())).thenReturn(xxUser);
    Mockito.when(daoManager.getXXResource()).thenReturn(xxResourceDao);
    Mockito.when(xxResourceDao.findByAssetIdAndResourceStatus(Mockito.anyLong(), Mockito.anyInt())).thenReturn(lst);
    Mockito.when(daoManager.getXXAsset()).thenReturn(xxAssetDao);
    Mockito.when(xxAssetDao.getById(Mockito.anyLong())).thenReturn(xxAsset);
    VXResponse resp = rangerBizUtil.hasPermission(vXResource, AppConstants.XA_PERM_TYPE_UNKNOWN);
    Mockito.verify(daoManager).getXXPortalUser();
    Mockito.verify(userDao).getById(Mockito.anyLong());
    Mockito.verify(daoManager).getXXUser();
    Mockito.verify(xxUserDao).findByUserName(Mockito.anyString());
    Assert.assertNotNull(resp);
    Assert.assertEquals(VXResponse.STATUS_ERROR, resp.getStatusCode());
    Assert.assertEquals("Permission Denied !", resp.getMsgDesc());
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXUser(org.apache.ranger.entity.XXUser) XXAssetDao(org.apache.ranger.db.XXAssetDao) XXResource(org.apache.ranger.entity.XXResource) XXUserDao(org.apache.ranger.db.XXUserDao) VXResource(org.apache.ranger.view.VXResource) XXAsset(org.apache.ranger.entity.XXAsset) ArrayList(java.util.ArrayList) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) XXResourceDao(org.apache.ranger.db.XXResourceDao) Test(org.junit.Test)

Example 10 with XXResource

use of org.apache.ranger.entity.XXResource in project ranger by apache.

the class TestRangerBizUtil method testMatchHivePolicy_NoPremission.

@Test
public void testMatchHivePolicy_NoPremission() {
    List<XXResource> xResourceList = new ArrayList<XXResource>();
    XXResource xXResource = new XXResource();
    xXResource.setId(id);
    xXResource.setName(resourceName);
    xXResource.setIsRecursive(AppConstants.BOOL_TRUE);
    xXResource.setResourceStatus(AppConstants.STATUS_ENABLED);
    xResourceList.add(xXResource);
    Mockito.when(stringUtil.split(Mockito.anyString(), Mockito.anyString())).thenReturn(new String[0]);
    boolean bnlChk = rangerBizUtil.matchHivePolicy("/*/*/*", xResourceList, id, 0);
    Assert.assertFalse(bnlChk);
}
Also used : XXResource(org.apache.ranger.entity.XXResource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

XXResource (org.apache.ranger.entity.XXResource)19 ArrayList (java.util.ArrayList)11 VXString (org.apache.ranger.view.VXString)6 Test (org.junit.Test)6 VXResponse (org.apache.ranger.view.VXResponse)5 XXAsset (org.apache.ranger.entity.XXAsset)4 List (java.util.List)3 SearchCriteria (org.apache.ranger.common.SearchCriteria)3 UserSessionBase (org.apache.ranger.common.UserSessionBase)3 VXResource (org.apache.ranger.view.VXResource)3 VXResourceList (org.apache.ranger.view.VXResourceList)3 XXResourceDao (org.apache.ranger.db.XXResourceDao)2 XXUserDao (org.apache.ranger.db.XXUserDao)2 XXPolicy (org.apache.ranger.entity.XXPolicy)2 XXUser (org.apache.ranger.entity.XXUser)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)2 VXPermMap (org.apache.ranger.view.VXPermMap)2 VXPermMapList (org.apache.ranger.view.VXPermMapList)2 VXPolicyList (org.apache.ranger.view.VXPolicyList)2