use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testCreateDuplScriptName.
@Test
public void testCreateDuplScriptName() {
String duplName = "script_name";
//
IdmScriptDto script = new IdmScriptDto();
script.setCategory(IdmScriptCategory.DEFAULT);
script.setCode("script_code_" + System.currentTimeMillis());
script.setName(duplName);
//
script = scriptService.saveInternal(script);
//
IdmScriptDto script2 = new IdmScriptDto();
script2.setCategory(IdmScriptCategory.DEFAULT);
script2.setCode("script_code_" + System.currentTimeMillis());
script2.setName(duplName);
//
script2 = scriptService.saveInternal(script2);
//
assertNotEquals(script.getCode(), script2.getCode());
assertEquals(script.getName(), script2.getName());
assertEquals(script.getCategory(), script2.getCategory());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testThreeScriptAuthorityThirdScriptUseAnotherAuth.
@Test(expected = IdmSecurityException.class)
public void testThreeScriptAuthorityThirdScriptUseAnotherAuth() {
IdmScriptDto third = new IdmScriptDto();
third.setCategory(IdmScriptCategory.DEFAULT);
third.setCode("script_name_" + System.currentTimeMillis());
third.setName("script_name_" + System.currentTimeMillis());
StringBuilder script = new StringBuilder(createTreeNodeScript());
// fail
script.append(createIdenityScript());
third.setScript(script.toString());
third = scriptService.save(third);
createAuthority(third.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeNodeDto.class.getName(), null);
//
IdmScriptDto second = new IdmScriptDto();
second.setCategory(IdmScriptCategory.DEFAULT);
second.setCode("script_name_" + System.currentTimeMillis());
second.setName("script_name_" + System.currentTimeMillis());
script = new StringBuilder(createTreeTypeScript());
script.append(createTreeNodeScript());
second.setScript(createScriptThatCallAnother(third, IdmScriptCategory.DEFAULT, null, false, null));
second = scriptService.save(second);
createAuthority(second.getId(), ScriptAuthorityType.CLASS_NAME, IdmTreeTypeDto.class.getName(), null);
//
//
IdmScriptDto first = new IdmScriptDto();
first.setCategory(IdmScriptCategory.DEFAULT);
first.setCode("script_name_" + System.currentTimeMillis());
first.setName("script_name_" + System.currentTimeMillis());
script = new StringBuilder(createIdenityScript());
script.append(createScriptThatCallAnother(second, IdmScriptCategory.DEFAULT, null, false, null));
first.setScript(script.toString());
first = scriptService.save(first);
createAuthority(first.getId(), ScriptAuthorityType.CLASS_NAME, IdmIdentity.class.getName(), null);
//
//
defaultScriptEvaluator.evaluate(first.getCode());
fail();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testEvaluateScriptWithoutAuth.
@Test(expected = IdmSecurityException.class)
public void testEvaluateScriptWithoutAuth() {
IdmScriptDto script = new IdmScriptDto();
script.setCategory(IdmScriptCategory.DEFAULT);
script.setCode("script_name_" + System.currentTimeMillis());
script.setName("script_name_" + System.currentTimeMillis());
//
script.setScript(createListScript(Boolean.TRUE));
//
script = scriptService.saveInternal(script);
//
IdmScriptDto script2 = new IdmScriptDto();
script2.setCategory(IdmScriptCategory.DEFAULT);
script2.setCode("script_name_" + System.currentTimeMillis());
script2.setName("script_name_" + System.currentTimeMillis());
//
script.setScript(createScriptThatCallAnother(script, IdmScriptCategory.DEFAULT, null, false));
//
script2 = scriptService.saveInternal(script2);
//
groovyScriptService.evaluate(script.getScript(), createParametersWithEvaluator(IdmScriptCategory.DEFAULT), createExtraAllowedClass());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method testScriptExceptionWithoutCatch.
@Test
public void testScriptExceptionWithoutCatch() {
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 Exception(\"" + 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 ResultCodeException);
assertTrue(e.getMessage().contains(testString));
}
}
Aggregations