use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method createThreeScripts.
/**
* Method create three unique script with same code and name. Script body isn't filled.
*
* @return
*/
private Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> createThreeScripts() {
String codeName1 = "script_name_" + System.currentTimeMillis();
IdmScriptDto script1 = new IdmScriptDto();
script1.setCategory(IdmScriptCategory.DEFAULT);
script1.setCode(codeName1);
script1.setName(codeName1);
script1 = this.scriptService.save(script1);
//
String codeName2 = "script_name_" + System.currentTimeMillis();
IdmScriptDto script2 = new IdmScriptDto();
script2.setCategory(IdmScriptCategory.DEFAULT);
script2.setCode(codeName2);
script2.setName(codeName2);
script2 = this.scriptService.save(script2);
//
String codeName3 = "script_name_" + System.currentTimeMillis();
IdmScriptDto script3 = new IdmScriptDto();
script3.setCategory(IdmScriptCategory.DEFAULT);
script3.setCode(codeName3);
script3.setName(codeName3);
script3 = this.scriptService.save(script3);
//
return new Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto>(script1, script2, script3);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testRemoveScriptWithAuthentization.
@Test
public void testRemoveScriptWithAuthentization() {
IdmScriptDto script = new IdmScriptDto();
script.setCategory(IdmScriptCategory.DEFAULT);
script.setCode("script_code_" + System.currentTimeMillis());
script.setName("script_name_" + System.currentTimeMillis());
//
script = scriptService.saveInternal(script);
IdmScriptAuthorityDto auth = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, List.class.getName(), null);
IdmScriptAuthorityDto auth2 = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, ArrayList.class.getName(), null);
//
scriptService.deleteInternal(script);
//
assertNull(scriptAuthorityService.get(auth.getId()));
assertNull(scriptAuthorityService.get(auth2.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testScriptRuntimeExceptionWithoutCatch.
@Test
public void testScriptRuntimeExceptionWithoutCatch() {
String testString = "TEST-" + System.currentTimeMillis();
//
Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
IdmScriptDto script1 = scripts.getFirst();
IdmScriptDto script2 = scripts.getSecond();
IdmScriptDto script3 = scripts.getThird();
//
script1.setScript(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
script3.setScript("throw new RuntimeException(\"" + testString + "\")");
//
script1 = this.scriptService.save(script1);
script2 = this.scriptService.save(script2);
script3 = this.scriptService.save(script3);
try {
// must throw exception
defaultScriptEvaluator.evaluate(script1.getCode());
fail();
} catch (Throwable e) {
assertTrue(e instanceof RuntimeException);
assertTrue(e.getMessage().contains(testString));
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testScriptSecurityExceptionWithCatch.
@Test
public void testScriptSecurityExceptionWithCatch() {
String testString = "TEST-" + System.currentTimeMillis();
//
Triple<IdmScriptDto, IdmScriptDto, IdmScriptDto> scripts = createThreeScripts();
IdmScriptDto script1 = scripts.getFirst();
IdmScriptDto script2 = scripts.getSecond();
IdmScriptDto script3 = scripts.getThird();
//
StringBuilder script1Body = new StringBuilder();
script1Body.append("try {\n");
script1Body.append(this.createScriptThatCallAnother(script2, IdmScriptCategory.DEFAULT, null, false));
script1Body.append("} catch (Throwable e) {\n");
script1Body.append("return \"" + testString + "\";\n");
script1Body.append("}\n");
script1Body.append("return null;\n");
//
script1.setScript(script1Body.toString());
script2.setScript(this.createScriptThatCallAnother(script3, IdmScriptCategory.DEFAULT, null, false));
script3.setScript("throw new SecurityException(\"" + testString + "\")");
//
script1 = this.scriptService.save(script1);
script2 = this.scriptService.save(script2);
script3 = this.scriptService.save(script3);
//
try {
// try catch SecurityException but propage this exception as throwable, this is possible
Object result = defaultScriptEvaluator.evaluate(script1.getCode());
assertNotNull(result);
assertEquals(testString, result);
} catch (Throwable e) {
fail();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testEvaluateScriptWithAuth.
@Test
public void testEvaluateScriptWithAuth() {
IdmScriptDto subScript = new IdmScriptDto();
subScript.setCategory(IdmScriptCategory.DEFAULT);
subScript.setCode("script_name_" + System.currentTimeMillis());
subScript.setName("script_name_" + System.currentTimeMillis());
//
subScript.setScript(createListScript(Boolean.TRUE));
//
subScript = scriptService.saveInternal(subScript);
//
createAuthority(subScript.getId(), ScriptAuthorityType.CLASS_NAME, IdmRole.class.getName(), null);
//
IdmScriptDto parent = new IdmScriptDto();
parent.setCategory(IdmScriptCategory.DEFAULT);
parent.setCode("script_name_" + System.currentTimeMillis());
parent.setName("script_name_" + System.currentTimeMillis());
//
parent.setScript(createScriptThatCallAnother(subScript, IdmScriptCategory.DEFAULT, null, false));
parent = scriptService.saveInternal(parent);
//
groovyScriptService.evaluate(parent.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
}
Aggregations