use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class TestAssetREST method testGrantPermissionWebApplicationException.
@Test
public void testGrantPermissionWebApplicationException() {
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.grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request)).thenThrow(webApplicationException);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
try {
assetREST.grantPermission(request, vXPolicy);
fail("Exception not thrown");
} catch (WebApplicationException e) {
Assert.assertTrue(true);
}
Mockito.verify(serviceUtil).toGrantRevokeRequest(vXPolicy);
try {
Mockito.verify(serviceREST).grantAccess(vXPolicy.getRepositoryName(), grantRequestObj, request);
} catch (Exception e) {
fail("test failed due to: " + e.getMessage());
}
}
use of org.apache.ranger.view.VXPolicy 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());
}
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class TestPublicAPIs method vXPolicy.
private VXPolicy vXPolicy(RangerPolicy policy, RangerService service) {
VXPolicy ret = new VXPolicy();
ret.setPolicyName(StringUtils.trim(policy.getName()));
ret.setDescription(policy.getDescription());
ret.setRepositoryName(policy.getService());
ret.setIsEnabled(policy.getIsEnabled() ? true : false);
ret.setRepositoryType(service.getType());
ret.setIsAuditEnabled(policy.getIsAuditEnabled());
return ret;
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class TestPublicAPIs method test12countPolicies.
@Test
public void test12countPolicies() throws Exception {
VXLong vXLong = new VXLong();
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
RangerService service = rangerService();
RangerPolicy policy = rangerPolicy();
List<RangerPolicy> policyList = new ArrayList<RangerPolicy>();
policyList.add(policy);
VXPolicy vXPolicy = vXPolicy(policy, service);
List<VXPolicy> vXPolicies = new ArrayList<VXPolicy>();
vXPolicies.add(vXPolicy);
VXPolicyList vXPolicyList = new VXPolicyList(vXPolicies);
SearchFilter filter = new SearchFilter();
filter.setParam(SearchFilter.POLICY_NAME, "policyName");
filter.setParam(SearchFilter.SERVICE_NAME, "serviceName");
filter.setStartIndex(0);
filter.setMaxRows(10);
Mockito.when(searchUtil.getSearchFilterFromLegacyRequest(request, policyService.sortFields)).thenReturn(filter);
Mockito.when(serviceREST.getPolicies(filter)).thenReturn(policyList);
Mockito.when(serviceUtil.rangerPolicyListToPublic(policyList, filter)).thenReturn(vXPolicyList);
VXPolicyList dbVXPolicyList = publicAPIs.searchPolicies(request);
vXLong.setValue(dbVXPolicyList.getResultSize());
Assert.assertNotNull(vXLong);
Assert.assertEquals(vXLong.getValue(), 1);
Mockito.verify(searchUtil).getSearchFilterFromLegacyRequest(request, policyService.sortFields);
Mockito.verify(serviceREST).getPolicies(filter);
Mockito.verify(serviceUtil).rangerPolicyListToPublic(policyList, filter);
}
use of org.apache.ranger.view.VXPolicy in project ranger by apache.
the class XPolicyService method mapToVXPolicyList.
public VXPolicyList mapToVXPolicyList(VXResourceList vXResourceList) {
List<VXPolicy> policyList = new ArrayList<VXPolicy>();
for (VXResource vXAsset : vXResourceList.getVXResources()) {
VXPolicy vXRepo = mapXAToPublicObject(vXAsset);
policyList.add(vXRepo);
}
VXPolicyList vXPolicyList = new VXPolicyList(policyList);
return vXPolicyList;
}
Aggregations