Java Code Examples for org.apache.ranger.plugin.model.RangerServiceDef#RangerServiceConfigDef

The following examples show how to use org.apache.ranger.plugin.model.RangerServiceDef#RangerServiceConfigDef . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsValidServiceNameCreationWithOutSpecialCharacters() throws Exception{
	String serviceName        = "c1_yarn";
	String serviceDisplayName = serviceName;

	RangerService rangerService = new RangerService();
	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.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
	boolean  valid = _validator.isValid(rangerService, Action.CREATE, _failures);
	Assert.assertEquals(0, _failures.size());
	Assert.assertTrue(valid);

}
 
Example 2
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 5 votes vote down vote up
@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);

}
 
Example 3
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsValidServiceNameCreationWithSpaceCharacter() throws Exception{
	String serviceName  = "Cluster 1_c1_yarn";
	String serviceDisplayName = serviceName;

	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.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.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);
}
 
Example 5
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsValidServiceNameCreationWithGreater255Characters() 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.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);

}
 
Example 6
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 4 votes vote down vote up
@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);

}
 
Example 7
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Test
public void testIsValidServiceNameUpdationWithSpaceCharacter() throws Exception{
	String serviceName  = "Cluster 1_c1_yarn";
	String serviceDisplayName = serviceName;

	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.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);

	String serviceNameWithoutSpace  = "Cluster_1_c1_yarn";
	String serviceDisplayNameWithoutSpace = serviceNameWithoutSpace;
	RangerService rangerServiceWithoutSpace = new RangerService();
	rangerServiceWithoutSpace.setId(1L);
	rangerServiceWithoutSpace.setName(serviceNameWithoutSpace);
	rangerServiceWithoutSpace.setDisplayName(serviceDisplayNameWithoutSpace);
	rangerServiceWithoutSpace.setType("yarn");
	rangerServiceWithoutSpace.setTagService("");

	//Case: previous service name does not have space, updating with name containing space
	when(_store.getService(1L)).thenReturn(rangerServiceWithoutSpace);
	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);

	//Case: previous service name does have space, updating with name containing space
	when(_store.getService(1L)).thenReturn(rangerService);
	when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
	boolean  validWithSpace = _validator.isValid(rangerService, Action.UPDATE, _failures);
	Assert.assertTrue(validWithSpace);
}
 
Example 8
Source File: TestRangerServiceValidator.java    From ranger with Apache License 2.0 4 votes vote down vote up
@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);

}