use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestRangerPolicyValidator method test_isValidServiceWithZone_happyPath.
@Test
public final void test_isValidServiceWithZone_happyPath() throws Exception {
boolean isAdmin = true;
when(_policy.getId()).thenReturn(1L);
when(_policy.getName()).thenReturn("my-all");
when(_policy.getService()).thenReturn("hdfssvc");
when(_policy.getZoneName()).thenReturn("zone1");
when(_policy.getResources()).thenReturn(null);
when(_policy.getIsAuditEnabled()).thenReturn(Boolean.TRUE);
when(_policy.getIsEnabled()).thenReturn(Boolean.FALSE);
RangerService service = new RangerService();
service.setType("service-type");
service.setId(2L);
Action action = Action.CREATE;
List<String> tagSvcList = new ArrayList<String>();
tagSvcList.add("hdfssvc");
when(_store.getServiceByName("hdfssvc")).thenReturn(service);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setName("zone1");
securityZone.setId(1L);
securityZone.setTagServices(tagSvcList);
when(_store.getSecurityZone("zone1")).thenReturn(securityZone);
when(_store.getPolicyId(2L, "my-all", 1L)).thenReturn(null);
RangerServiceDef svcDef = new RangerServiceDef();
svcDef.setName("my-svc-def");
when(_store.getServiceDefByName("service-type")).thenReturn(svcDef);
RangerPolicyResourceSignature policySignature = mock(RangerPolicyResourceSignature.class);
when(_factory.createPolicyResourceSignature(_policy)).thenReturn(policySignature);
Assert.assertTrue(_validator.isValid(_policy, action, isAdmin, _failures));
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class TestRangerPolicyValidator method test_isValidServiceWithZone_failurePath.
@Test
public final void test_isValidServiceWithZone_failurePath() throws Exception {
boolean isAdmin = true;
when(_policy.getId()).thenReturn(1L);
when(_policy.getName()).thenReturn("my-all");
when(_policy.getService()).thenReturn("hdfssvc1");
when(_policy.getZoneName()).thenReturn("zone1");
when(_policy.getResources()).thenReturn(null);
when(_policy.getIsAuditEnabled()).thenReturn(Boolean.TRUE);
when(_policy.getIsEnabled()).thenReturn(Boolean.FALSE);
RangerService service = new RangerService();
service.setType("service-type");
service.setId(2L);
Action action = Action.CREATE;
List<String> tagSvcList = new ArrayList<String>();
tagSvcList.add("hdfssvc");
when(_store.getServiceByName("hdfssvc1")).thenReturn(service);
RangerSecurityZone securityZone = new RangerSecurityZone();
securityZone.setName("zone1");
securityZone.setId(1L);
securityZone.setTagServices(tagSvcList);
when(_store.getSecurityZone("zone1")).thenReturn(securityZone);
when(_store.getPolicyId(2L, "my-all", 1L)).thenReturn(null);
RangerServiceDef svcDef = new RangerServiceDef();
svcDef.setName("my-svc-def");
when(_store.getServiceDefByName("service-type")).thenReturn(svcDef);
RangerPolicyResourceSignature policySignature = mock(RangerPolicyResourceSignature.class);
when(_factory.createPolicyResourceSignature(_policy)).thenReturn(policySignature);
boolean isValid = _validator.isValid(_policy, action, isAdmin, _failures);
Assert.assertFalse(isValid);
Assert.assertEquals(_failures.get(0)._errorCode, 3048);
Assert.assertEquals(_failures.get(0)._reason, "Service name = hdfssvc1 is not associated to Zone name = zone1");
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneWitoutResourcesForCreateThrowsError.
@Test
public void testValidateSecurityZoneWitoutResourcesForCreateThrowsError() throws Exception {
RangerSecurityZoneService rangerSecurityZoneService = new RangerSecurityZoneService();
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
Map<String, RangerSecurityZone.RangerSecurityZoneService> map = new HashMap<String, RangerSecurityZone.RangerSecurityZoneService>();
map.put("hdfsSvc", rangerSecurityZoneService);
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
suppliedSecurityZone.setServices(map);
Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
try {
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
} catch (Exception ex) {
Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3039], reason[No resources specified for service [hdfsSvc]], field[security zone resources], subfield[null], type[missing] ");
}
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneWitoutRangerServiceDefResourceForCreateThrowsError.
@Test
public void testValidateSecurityZoneWitoutRangerServiceDefResourceForCreateThrowsError() throws Exception {
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
rangerSvcDef.setResources(null);
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
try {
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
} catch (Exception ex) {
Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3042], reason[Invalid resource hierarchy specified for service:[hdfsSvc], resource-hierarchy:[[hdfs]]], field[security zone resource hierarchy], subfield[null], type[] ");
}
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneNotExistForUpdateThrowsError.
@Test
public void testValidateSecurityZoneNotExistForUpdateThrowsError() throws Exception {
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
Mockito.when(_store.getSecurityZone(1L)).thenReturn(null);
try {
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.UPDATE);
} catch (Exception ex) {
Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3037], reason[No security zone found for [1]], field[id], subfield[null], type[] ");
}
}
Aggregations