Search in sources :

Example 11 with RangerPolicy

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

the class TestAssetREST method testCreateXResource.

@Test
public void testCreateXResource() {
    VXResource vxResource = vxResource(Id);
    RangerPolicy rangerPolicy = rangerPolicy(Id);
    RangerService rangerService = rangerService(Id);
    Mockito.when(serviceREST.getService(vxResource.getAssetId())).thenReturn(rangerService);
    Mockito.when(serviceREST.createPolicy(rangerPolicy, null)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toRangerPolicy(vxResource, rangerService)).thenReturn(rangerPolicy);
    Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vxResource);
    VXResource actualvxResource = assetREST.createXResource(vxResource);
    Assert.assertNotNull(actualvxResource);
    Assert.assertEquals(vxResource, actualvxResource);
    Mockito.verify(serviceREST).getService(vxResource.getAssetId());
    Mockito.verify(serviceREST).createPolicy(rangerPolicy, null);
    Mockito.verify(serviceUtil).toRangerPolicy(vxResource, rangerService);
    Mockito.verify(serviceUtil).toVXResource(rangerPolicy, rangerService);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXResource(org.apache.ranger.view.VXResource) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 12 with RangerPolicy

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

the class TestAssetREST method servicePolicies.

private ServicePolicies servicePolicies() {
    RangerPolicy rangerPolicy = rangerPolicy(Id);
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    ServicePolicies servicePolicies = new ServicePolicies();
    List<RangerPolicy> policies = new ArrayList<RangerPolicy>();
    policies.add(rangerPolicy);
    servicePolicies.setServiceId(Id);
    servicePolicies.setServiceName("Hdfs_1");
    servicePolicies.setPolicyVersion(1L);
    servicePolicies.setPolicyUpdateTime(new Date());
    servicePolicies.setServiceDef(rangerServiceDef);
    servicePolicies.setPolicies(policies);
    return servicePolicies;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ServicePolicies(org.apache.ranger.plugin.util.ServicePolicies) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 13 with RangerPolicy

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

the class TestAssetREST method testCountXResource.

@Test
public void testCountXResource() {
    List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
    List<VXResource> vXResourcesList = new ArrayList<VXResource>();
    RangerService rangerService = rangerService(Id);
    long i;
    for (i = 1; i <= 2; i++) {
        RangerPolicy rangerPolicy = rangerPolicy(i);
        VXResource vXresource = vxResource(i);
        rangerPolicyList.add(rangerPolicy);
        vXResourcesList.add(vXresource);
        Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
    }
    VXLong expectedXResouce = new VXLong();
    expectedXResouce.setValue(2l);
    Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
    VXResourceList expectedVXResourceList = new VXResourceList();
    expectedVXResourceList.setVXResources(vXResourcesList);
    SearchFilter searchFilter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
    Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
    VXLong actualXResource = assetREST.countXResources(request);
    Assert.assertEquals(expectedXResouce.getValue(), actualXResource.getValue());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXLong(org.apache.ranger.view.VXLong) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 14 with RangerPolicy

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

the class TestAssetREST method testSearchXResource.

@Test
public void testSearchXResource() {
    List<RangerPolicy> rangerPolicyList = new ArrayList<RangerPolicy>();
    List<VXResource> vXResourcesList = new ArrayList<VXResource>();
    RangerService rangerService = rangerService(Id);
    long i;
    for (i = 1; i <= 2; i++) {
        RangerPolicy rangerPolicy = rangerPolicy(i);
        VXResource vXresource = vxResource(i);
        rangerPolicyList.add(rangerPolicy);
        vXResourcesList.add(vXresource);
        Mockito.when(serviceUtil.toVXResource(rangerPolicy, rangerService)).thenReturn(vXresource);
    }
    Mockito.when(serviceREST.getServiceByName(rangerPolicyList.get(0).getService())).thenReturn(rangerService);
    VXResourceList expectedVXResourceList = new VXResourceList();
    expectedVXResourceList.setVXResources(vXResourcesList);
    SearchFilter searchFilter = new SearchFilter();
    Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, null)).thenReturn(searchFilter);
    Mockito.when(serviceREST.getPolicies(searchFilter)).thenReturn(rangerPolicyList);
    VXResourceList actualVXResourceList = assetREST.searchXResources(request);
    Assert.assertNotNull(actualVXResourceList);
    Assert.assertEquals(expectedVXResourceList.getVXResources(), actualVXResourceList.getVXResources());
    Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, null);
    Mockito.verify(serviceREST).getPolicies(searchFilter);
    for (i = 0; i < 2; i++) {
        Mockito.verify(serviceUtil, Mockito.times(1)).toVXResource(rangerPolicyList.get((int) i), rangerService);
    }
    Mockito.verify(serviceREST, Mockito.times(2)).getServiceByName(rangerPolicyList.get(0).getService());
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXResourceList(org.apache.ranger.view.VXResourceList) ArrayList(java.util.ArrayList) VXResource(org.apache.ranger.view.VXResource) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 15 with RangerPolicy

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

the class TestAssetREST method testRevokePermissionWebApplicationException.

@Test
public void testRevokePermissionWebApplicationException() {
    RangerPolicy policy = rangerPolicy(Id);
    RangerService service = rangerService(Id);
    VXPolicy vXPolicy = vXPolicy(policy, service);
    GrantRevokeRequest grantRequestObj = new GrantRevokeRequest();
    grantRequestObj.setAccessTypes(null);
    grantRequestObj.setDelegateAdmin(true);
    grantRequestObj.setEnableAudit(true);
    grantRequestObj.setGrantor("read");
    grantRequestObj.setIsRecursive(true);
    WebApplicationException webApplicationException = new WebApplicationException();
    Mockito.when(serviceUtil.toGrantRevokeRequest(vXPolicy)).thenReturn(grantRequestObj);
    try {
        Mockito.when(serviceREST.revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
    try {
        assetREST.revokePermission(request, vXPolicy);
        fail("Exception not thrown");
    } catch (WebApplicationException e) {
        Assert.assertTrue(true);
    }
    Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
    try {
        Mockito.verify(serviceREST).revokeAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
    } catch (Exception e) {
        fail("test failed due to: " + e.getMessage());
    }
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) WebApplicationException(javax.ws.rs.WebApplicationException) VXPolicy(org.apache.ranger.view.VXPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) GrantRevokeRequest(org.apache.ranger.plugin.util.GrantRevokeRequest) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)196 ArrayList (java.util.ArrayList)78 Test (org.junit.Test)73 RangerService (org.apache.ranger.plugin.model.RangerService)52 VXString (org.apache.ranger.view.VXString)48 HashMap (java.util.HashMap)38 RangerPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItem)36 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)33 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)30 WebApplicationException (javax.ws.rs.WebApplicationException)29 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)27 RangerPolicyItemAccess (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyItemAccess)26 Path (javax.ws.rs.Path)23 Produces (javax.ws.rs.Produces)22 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)20 Date (java.util.Date)19 IOException (java.io.IOException)18 XXService (org.apache.ranger.entity.XXService)18 ServicePolicies (org.apache.ranger.plugin.util.ServicePolicies)16 RangerPolicyList (org.apache.ranger.view.RangerPolicyList)15