Search in sources :

Example 46 with RangerSecurityZone

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[] ");
    }
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 47 with RangerSecurityZone

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");
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 48 with RangerSecurityZone

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);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Test(org.junit.Test)

Example 49 with RangerSecurityZone

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;
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RangerSecurityZoneService(org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 50 with 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[] ");
    }
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) Test(org.junit.Test)

Aggregations

RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)68 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)27 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)16 WebApplicationException (javax.ws.rs.WebApplicationException)14 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)12 RangerService (org.apache.ranger.plugin.model.RangerService)11 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)10 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)10 XXTrxLog (org.apache.ranger.entity.XXTrxLog)9 RangerSecurityZoneService (org.apache.ranger.plugin.model.RangerSecurityZone.RangerSecurityZoneService)7 HashMap (java.util.HashMap)6 ValidationErrorCode (org.apache.ranger.plugin.errors.ValidationErrorCode)5 HashSet (java.util.HashSet)4 List (java.util.List)4 XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 XXServiceDao (org.apache.ranger.db.XXServiceDao)3 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)3