use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class RangerSecurityZoneValidatorTest method rangerServiceDef.
private RangerServiceDef rangerServiceDef() {
RangerResourceDef rangerResourceDef = new RangerResourceDef();
rangerResourceDef.setName("hdfs");
List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
resources.add(rangerResourceDef);
List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setId(1L);
rangerServiceDef.setImplClass("RangerServiceHdfs");
rangerServiceDef.setName("HDFS Repository");
rangerServiceDef.setLabel("HDFS Repository");
rangerServiceDef.setDescription("HDFS Repository");
rangerServiceDef.setRbKeyDescription(null);
rangerServiceDef.setUpdatedBy("Admin");
rangerServiceDef.setUpdateTime(new Date());
rangerServiceDef.setConfigs(configs);
rangerServiceDef.setResources(resources);
rangerServiceDef.setAccessTypes(accessTypes);
rangerServiceDef.setPolicyConditions(policyConditions);
rangerServiceDef.setContextEnrichers(contextEnrichers);
rangerServiceDef.setEnums(enums);
return rangerServiceDef;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameCreationWithSpecialCharacters.
@Test
public void testIsValidServiceNameCreationWithSpecialCharacters() throws Exception {
String serviceName = "<script>c1_yarn</script>";
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setName(serviceName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, _action, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithGreater255Characters.
@Test
public void testIsValidServiceNameUpdationWithGreater255Characters() throws Exception {
String serviceName = "c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1_yarn_c1";
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setId(1L);
rangerService.setName(serviceName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getService(1L)).thenReturn(rangerService);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithSpecialCharacters.
@Test
public void testIsValidServiceNameUpdationWithSpecialCharacters() throws Exception {
String serviceName = "<alert>c1_yarn</alert>";
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setId(1L);
rangerService.setName(serviceName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getService(1L)).thenReturn(rangerService);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameUpdationWithOutSpecialCharacters.
@Test
public void testIsValidServiceNameUpdationWithOutSpecialCharacters() throws Exception {
String serviceName = "c1_yarn";
String serviceDisplayName = serviceName;
RangerService rangerService = new RangerService();
rangerService.setId(1L);
rangerService.setName(serviceName);
rangerService.setDisplayName(serviceDisplayName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getService(1L)).thenReturn(rangerService);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, Action.UPDATE, _failures);
Assert.assertEquals(0, _failures.size());
Assert.assertTrue(valid);
}
Aggregations