use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateWhileFetchingSecurityZoneForCreateThrowsError.
/*
@Test
public void testValidateSecurityZoneWitoutRangerServiceDefResourceValueWildCardCharacterForCreateThrowsError() throws Exception{
List<String> resourceList = new ArrayList<String>();
resourceList.add("*");
HashMap<String, List<String>> resourcesMap = new HashMap<String, List<String>>();
resourcesMap.put("hdfs", resourceList);
List<HashMap<String, List<String>>> resources = new ArrayList<HashMap<String,List<String>>>();
resources.add(resourcesMap);
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
RangerSecurityZoneService rangerSecurityZoneService = new RangerSecurityZoneService();
rangerSecurityZoneService.setResources(resources);
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);
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[3043], reason[All wildcard values specified for resources for service:[hdfsSvc]], field[security zone resource values], subfield[null], type[] ");
}
}
*/
@Test
public void testValidateWhileFetchingSecurityZoneForCreateThrowsError() throws Exception {
SearchFilter filter = getSerachFilter();
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
Mockito.when(_securityZoneStore.getSecurityZones(filter)).thenThrow(new NullPointerException());
try {
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
} catch (Exception ex) {
Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3045], reason[Internal Error:[null]], field[null], subfield[null], type[] ");
}
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneForCreate.
@Test
public void testValidateSecurityZoneForCreate() throws Exception {
SearchFilter filter = getSerachFilter();
List<RangerSecurityZone> rangerSecurityZoneList = new ArrayList<RangerSecurityZone>();
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
rangerSecurityZoneList.add(suppliedSecurityZone);
Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
Mockito.when(_securityZoneStore.getSecurityZones(filter)).thenReturn(rangerSecurityZoneList);
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
Mockito.verify(_store).getSecurityZone("MyZone");
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneForUpdate.
@Test
public void testValidateSecurityZoneForUpdate() throws Exception {
SearchFilter filter = getSerachFilter();
List<RangerSecurityZone> rangerSecurityZoneList = new ArrayList<RangerSecurityZone>();
RangerService rangerSvc = getRangerService();
RangerServiceDef rangerSvcDef = rangerServiceDef();
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
rangerSecurityZoneList.add(suppliedSecurityZone);
Mockito.when(_store.getSecurityZone(1L)).thenReturn(suppliedSecurityZone);
Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
Mockito.when(_securityZoneStore.getSecurityZones(filter)).thenReturn(rangerSecurityZoneList);
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.UPDATE);
Mockito.verify(_store, Mockito.atLeastOnce()).getSecurityZone(1L);
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method getRangerSecurityZone.
private RangerSecurityZone getRangerSecurityZone() {
List<String> resourceList = new ArrayList<String>();
resourceList.add("/path/myfolder");
HashMap<String, List<String>> resourcesMap = new HashMap<String, List<String>>();
resourcesMap.put("hdfs", resourceList);
List<HashMap<String, List<String>>> resources = new ArrayList<HashMap<String, List<String>>>();
resources.add(resourcesMap);
List<String> adminUsers = new ArrayList<String>();
adminUsers.add("adminUser1");
List<String> adminGrpUsers = new ArrayList<String>();
adminGrpUsers.add("adminGrpUser1");
List<String> aduitUsers = new ArrayList<String>();
aduitUsers.add("aduitUser1");
List<String> aduitGrpUsers = new ArrayList<String>();
aduitUsers.add("aduitGrpUser1");
RangerSecurityZoneService rangerSecurityZoneService = new RangerSecurityZoneService();
rangerSecurityZoneService.setResources(resources);
Map<String, RangerSecurityZone.RangerSecurityZoneService> map = new HashMap<String, RangerSecurityZone.RangerSecurityZoneService>();
map.put("hdfsSvc", rangerSecurityZoneService);
RangerSecurityZone rangerSecurityZone = new RangerSecurityZone();
rangerSecurityZone.setId(1L);
rangerSecurityZone.setAdminUsers(adminUsers);
rangerSecurityZone.setAuditUsers(aduitUsers);
rangerSecurityZone.setAdminUserGroups(adminGrpUsers);
rangerSecurityZone.setAuditUserGroups(aduitGrpUsers);
rangerSecurityZone.setName("MyZone");
rangerSecurityZone.setServices(map);
rangerSecurityZone.setDescription("MyZone");
return rangerSecurityZone;
}
use of org.apache.ranger.plugin.model.RangerSecurityZone in project ranger by apache.
the class RangerSecurityZoneValidatorTest method testValidateSecurityZoneForCreateWithExistingNameThrowsError.
@Test
public void testValidateSecurityZoneForCreateWithExistingNameThrowsError() throws Exception {
RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();
RangerSecurityZone existingSecurityZone = getRangerSecurityZone();
Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(existingSecurityZone);
try {
rangerSecurityZoneValidator.validate(suppliedSecurityZone, RangerValidator.Action.CREATE);
} catch (Exception ex) {
Assert.assertEquals(ex.getMessage(), "(0) Validation failure: error code[3036], reason[Another security zone already exists for this name: zone-id=[1]]], field[name], subfield[null], type[] ");
}
}
Aggregations