use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.
@Test(expected = RoleRequestException.class)
@Transactional
public void notRightForExecuteImmediatelyExceptionTest() {
IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleA = getHelper().createRole(100);
this.logout();
// Log as user without right for immediately execute role request (without
// approval)
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !CoreGroupPermission.ROLE_REQUEST_EXECUTE.equals(authority.getAuthority()) && !CoreGroupPermission.ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(testA, null, authorities, "test"));
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setOperation(ConceptRoleRequestOperation.ADD);
conceptA.setRole(roleA.getId());
conceptA.setIdentityContract(contractA.getId());
conceptA = conceptRoleRequestService.save(conceptA);
Assert.assertEquals(RoleRequestState.CONCEPT, conceptA.getState());
// We expect exception state (we don`t have right for execute without approval)
getHelper().startRequestInternal(request, true, true);
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testExecuteRequestForSameAutomaticRole.
@Test
public void testExecuteRequestForSameAutomaticRole() {
IdmRoleDto role = getHelper().createRole();
IdmAutomaticRoleAttributeDto automaticRole = getHelper().createAutomaticRole(role.getId());
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
//
// create two requests
IdmRoleRequestDto requestOne = new IdmRoleRequestDto();
requestOne.setApplicant(identity.getId());
requestOne.setExecuteImmediately(true);
requestOne.setRequestedByType(RoleRequestedByType.MANUALLY);
requestOne.setState(RoleRequestState.EXECUTED);
requestOne = roleRequestService.save(requestOne);
Assert.assertEquals(RoleRequestState.CONCEPT, requestOne.getState());
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(requestOne.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.ADD);
concept.setRole(role.getId());
concept.setAutomaticRole(automaticRole.getId());
concept.setIdentityContract(primeContract.getId());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
//
// create two requests
IdmRoleRequestDto requestTwo = new IdmRoleRequestDto();
requestTwo.setApplicant(identity.getId());
requestTwo.setExecuteImmediately(true);
requestTwo.setRequestedByType(RoleRequestedByType.MANUALLY);
requestTwo.setState(RoleRequestState.EXECUTED);
requestTwo = roleRequestService.save(requestTwo);
Assert.assertEquals(RoleRequestState.CONCEPT, requestTwo.getState());
concept = new IdmConceptRoleRequestDto();
concept.setRoleRequest(requestTwo.getId());
concept.setState(RoleRequestState.EXECUTED);
concept.setOperation(ConceptRoleRequestOperation.ADD);
concept.setRole(role.getId());
concept.setAutomaticRole(automaticRole.getId());
concept.setIdentityContract(primeContract.getId());
concept = conceptRoleRequestService.save(concept);
Assert.assertEquals(RoleRequestState.CONCEPT, concept.getState());
getHelper().startRequestInternal(requestOne, true, true);
requestOne = roleRequestService.get(requestOne.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, requestOne.getState());
getHelper().startRequestInternal(requestTwo, true, true);
requestTwo = roleRequestService.get(requestTwo.getId());
Assert.assertEquals(RoleRequestState.EXECUTED, requestTwo.getState());
//
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertTrue(assignedRoles.stream().allMatch(ir -> ir.getAutomaticRole().equals(automaticRole.getId())));
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmScriptServiceIntegrationTest method testDeployScriptFromAttachement.
@Test
public void testDeployScriptFromAttachement() throws IOException {
String scriptCode = getHelper().createName();
String scriptOne = "<script> <code>" + scriptCode + "</code> <name>Test script 1</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
// create attachment
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment.setName("scriptOne.xml");
attachment.setMimetype(MediaType.TEXT_XML_VALUE);
attachment.setInputData(IOUtils.toInputStream(scriptOne));
// owner and version is resolved after attachment is saved
attachment = attachmentManager.saveAttachment(null, attachment);
// deploy
List<IdmScriptDto> results = scriptService.deploy(attachment);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(scriptCode, results.get(0).getCode());
//
// test authorities
IdmScriptAuthorityFilter authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(results.get(0).getId());
List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(4, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
//
// deploy from archive
IdmScriptDto scriptOneDto = scriptService.getByCode(scriptCode);
String scriptCodeTwo = getHelper().createName();
String scriptOneUpdateName = getHelper().createName();
scriptOne = "<script> <code>" + scriptCode + "</code> <name>" + scriptOneUpdateName + "</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
// create attachment
String scriptTwo = "<script> <code>" + scriptCodeTwo + "</code> <name>Test script 2</name> <body> <![CDATA[ String s; ]]> </body> <type>groovy</type> <category>DEFAULT</category> <parameters>test1</parameters> <services> <service> <name>treeNodeService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmTreeNodeService</className> </service> <service> <name>identityService</name> <className>eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService</className> </service> </services><allowClasses> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmTreeNode</className> </allowClass> <allowClass> <className>eu.bcvsolutions.idm.core.model.entity.IdmIdentity</className> </allowClass> </allowClasses> </script>";
IdmAttachmentDto attachmentOne = new IdmAttachmentDto();
attachmentOne.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentOne.setName("scriptOne.xml");
attachmentOne.setMimetype(MediaType.TEXT_XML_VALUE);
attachmentOne.setInputData(IOUtils.toInputStream(scriptOne));
attachmentOne = attachmentManager.saveAttachment(null, attachmentOne);
IdmAttachmentDto attachmentTwo = new IdmAttachmentDto();
attachmentTwo.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentTwo.setName("scriptTwo.xml");
attachmentTwo.setMimetype(MediaType.TEXT_XML_VALUE);
attachmentTwo.setInputData(IOUtils.toInputStream(scriptTwo));
attachmentTwo = attachmentManager.saveAttachment(null, attachmentTwo);
// zip
File zipFolder = attachmentManager.createTempDirectory(null).toFile();
File targetFileOne = new File(zipFolder.toString(), String.format("%s.xml", attachmentOne.getName()));
Files.copy(attachmentManager.getAttachmentData(attachmentOne.getId()), targetFileOne.toPath(), StandardCopyOption.REPLACE_EXISTING);
File targetFileTwo = new File(zipFolder.toString(), String.format("%s.xml", attachmentTwo.getName()));
Files.copy(attachmentManager.getAttachmentData(attachmentTwo.getId()), targetFileTwo.toPath(), StandardCopyOption.REPLACE_EXISTING);
// compress
File zipFile = attachmentManager.createTempFile();
ZipUtils.compress(zipFolder, zipFile.getPath());
IdmAttachmentDto attachmentZip = new IdmAttachmentDto();
attachmentZip.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachmentZip.setInputData(new FileInputStream(zipFile));
attachmentZip.setEncoding(AttachableEntity.DEFAULT_ENCODING);
// zip ~ octet stream
attachmentZip.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
attachmentZip.setName("backup.zip");
attachmentZip = attachmentManager.saveAttachment(null, attachmentZip);
// deploy
results = scriptService.deploy(attachmentZip);
//
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(s -> s.getId().equals(scriptOneDto.getId())));
Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCode) && s.getName().equals(scriptOneUpdateName)));
Assert.assertTrue(results.stream().anyMatch(s -> s.getCode().equals(scriptCodeTwo)));
//
// test authorities
authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(scriptOneDto.getId());
authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(3, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
//
authorityFilter = new IdmScriptAuthorityFilter();
authorityFilter.setScriptId(scriptService.getByCode(scriptCodeTwo).getId());
authorities = scriptAuthorityService.find(authorityFilter, null).getContent();
Assert.assertEquals(4, authorities.size());
Assert.assertTrue(authorities.stream().allMatch(a -> StringUtils.isNotEmpty(a.getClassName())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "treeNodeService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> "identityService".equals(a.getService())));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmTreeNode")));
Assert.assertTrue(authorities.stream().anyMatch(a -> a.getClassName().equals("eu.bcvsolutions.idm.core.model.entity.IdmIdentity")));
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testGetRolesByIds.
@Test
public void testGetRolesByIds() {
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
//
List<IdmRoleDto> roles = roleService.getRolesByIds(StringUtils.join(Lists.newArrayList(roleOne.getId(), roleTwo.getId()), ','));
//
Assert.assertEquals(2, roles.size());
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleOne.getId())));
Assert.assertTrue(roles.stream().anyMatch(r -> r.getId().equals(roleTwo.getId())));
}
use of org.junit.Assert.assertEquals in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleFormAttributeServiceIntegrationTest method testSubDefinitionOverrideValidationReqex.
@Test
public void testSubDefinitionOverrideValidationReqex() {
String regex = "regex";
// Create role with attribute (include the sub-definition)
IdmRoleDto role = createRoleWithAttributes();
IdmRoleFormAttributeFilter filter = new IdmRoleFormAttributeFilter();
filter.setRole(role.getId());
List<IdmRoleFormAttributeDto> list = roleFormAttributeService.find(filter, null).getContent();
Assert.assertEquals(2, list.size());
IdmFormDefinitionDto formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
// Set regex validation on false to IP attribute in the sub-definition
list.stream().filter(roleFormAttributeDto -> {
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(roleFormAttributeDto, IdmRoleFormAttribute_.formAttribute.getName(), IdmFormAttributeDto.class);
return formAttributeDto.getCode().equals(IP);
}).forEach(roleFormAttributeDto -> {
Assert.assertNull(roleFormAttributeDto.getRegex());
roleFormAttributeDto.setRegex(regex);
roleFormAttributeService.save(roleFormAttributeDto);
});
// Load sub-definition by role
formAttributeSubdefinition = roleService.getFormAttributeSubdefinition(role);
Assert.assertEquals(2, formAttributeSubdefinition.getFormAttributes().size());
IdmFormAttributeDto ipFormAttribute = formAttributeSubdefinition.getFormAttributes().stream().filter(attributeDto -> {
return attributeDto.getCode().equals(IP);
}).findFirst().orElse(null);
Assert.assertNotNull(ipFormAttribute);
Assert.assertEquals(regex, ipFormAttribute.getRegex());
}
Aggregations