Search in sources :

Example 1 with PersistentId

use of io.imunity.furms.domain.users.PersistentId in project furms by unity-idm.

the class InvitatoryServiceTest method shouldDetectAndInviteExistingUser.

@Test
void shouldDetectAndInviteExistingUser() {
    Role role = Role.FENIX_ADMIN;
    ResourceId resourceId = new ResourceId((UUID) null, ResourceType.APP_LEVEL);
    PersistentId persistentId = new PersistentId("id");
    FenixUserId fenixId = new FenixUserId("fenixId");
    FURMSUser furmsUser = FURMSUser.builder().id(persistentId).fenixUserId(fenixId).email("email@email.com").build();
    Invitation invitation = Invitation.builder().resourceId(resourceId).role(role).userId(furmsUser.fenixUserId.get()).originator("originator").resourceName("system").email(furmsUser.email).utcExpiredAt(getExpiredAt()).build();
    when(usersDAO.findById(persistentId)).thenReturn(Optional.of(furmsUser));
    when(usersDAO.getAllUsers()).thenReturn(List.of(furmsUser));
    when(usersDAO.getUserAttributes(fenixId)).thenReturn(new UserAttributes(Set.of(), Map.of()));
    when(invitationRepository.findBy("email@email.com", role, resourceId)).thenReturn(Optional.empty());
    when(authzService.getCurrentAuthNUser()).thenReturn(FURMSUser.builder().email("originator").build());
    invitatoryService.inviteUser("email@email.com", resourceId, role, "system");
    verify(invitationRepository).create(invitation);
    verify(userInvitationNotificationService).notifyUserAboutNewRole(persistentId, invitation.role);
}
Also used : Role(io.imunity.furms.domain.authz.roles.Role) ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Invitation(io.imunity.furms.domain.invitations.Invitation) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PersistentId(io.imunity.furms.domain.users.PersistentId) UserAttributes(io.imunity.furms.domain.users.UserAttributes) Test(org.junit.jupiter.api.Test)

Example 2 with PersistentId

use of io.imunity.furms.domain.users.PersistentId in project furms by unity-idm.

the class InvitatoryServiceTest method shouldInviteNewUser.

@Test
void shouldInviteNewUser() {
    Role role = Role.FENIX_ADMIN;
    ResourceId resourceId = new ResourceId((UUID) null, ResourceType.APP_LEVEL);
    PersistentId persistentId = new PersistentId("id");
    InvitationCode code = new InvitationCode("code");
    FURMSUser furmsUser = FURMSUser.builder().id(persistentId).fenixUserId(new FenixUserId("fenixId")).email("email@email.com").build();
    Invitation invitation = Invitation.builder().resourceId(resourceId).role(role).code(code).resourceName("system").originator("originator").email(furmsUser.email).utcExpiredAt(getExpiredAt()).build();
    when(usersDAO.inviteUser(resourceId, role, "email@email.com", getExpiredAt().toInstant(ZoneOffset.UTC))).thenReturn(code);
    when(invitationRepository.findBy("email@email.com", role, resourceId)).thenReturn(Optional.empty());
    when(authzService.getCurrentAuthNUser()).thenReturn(FURMSUser.builder().email("originator").build());
    invitatoryService.inviteUser("email@email.com", resourceId, role, "system");
    verify(invitationRepository).create(invitation);
    verify(usersDAO).inviteUser(resourceId, role, "email@email.com", getExpiredAt().toInstant(ZoneOffset.UTC));
}
Also used : Role(io.imunity.furms.domain.authz.roles.Role) ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) FenixUserId(io.imunity.furms.domain.users.FenixUserId) InvitationCode(io.imunity.furms.domain.invitations.InvitationCode) Invitation(io.imunity.furms.domain.invitations.Invitation) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 3 with PersistentId

use of io.imunity.furms.domain.users.PersistentId in project furms by unity-idm.

the class InvitatoryServiceTest method shouldUpdateInvitationRoleForExistingUser.

@Test
void shouldUpdateInvitationRoleForExistingUser() {
    Role role = Role.SITE_ADMIN;
    ResourceId resourceId = new ResourceId(UUID.randomUUID(), ResourceType.SITE);
    InvitationId invitationId = new InvitationId(UUID.randomUUID());
    PersistentId persistentId = new PersistentId("id");
    FenixUserId fenixId = new FenixUserId("fenixId");
    FURMSUser furmsUser = FURMSUser.builder().id(persistentId).fenixUserId(fenixId).email("email@email.com").build();
    Invitation invitation = Invitation.builder().id(invitationId).resourceId(resourceId).userId(fenixId).role(role).originator("originator").email("email@email.com").utcExpiredAt(getExpiredAt()).build();
    when(invitationRepository.findBy(invitationId)).thenReturn(Optional.of(invitation));
    when(usersDAO.getAllUsers()).thenReturn(List.of(furmsUser));
    invitatoryService.updateInvitationRole(invitationId, Role.SITE_SUPPORT);
    verify(invitationRepository).updateExpiredAtAndRole(invitationId, getExpiredAt(), Role.SITE_SUPPORT);
    verify(userInvitationNotificationService).notifyUserAboutNewRole(persistentId, Role.SITE_SUPPORT);
}
Also used : Role(io.imunity.furms.domain.authz.roles.Role) ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Invitation(io.imunity.furms.domain.invitations.Invitation) FURMSUser(io.imunity.furms.domain.users.FURMSUser) InvitationId(io.imunity.furms.domain.invitations.InvitationId) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 4 with PersistentId

use of io.imunity.furms.domain.users.PersistentId in project furms by unity-idm.

the class InvitatoryServiceTest method shouldThrowExceptionWhenEmailIsIncorrect.

@Test
void shouldThrowExceptionWhenEmailIsIncorrect() {
    Role role = Role.FENIX_ADMIN;
    ResourceId resourceId = new ResourceId((UUID) null, ResourceType.APP_LEVEL);
    PersistentId persistentId = new PersistentId("id");
    String message = assertThrows(IllegalArgumentException.class, () -> invitatoryService.inviteUser("email", resourceId, role, "system")).getMessage();
    assertEquals("Email is not valid", message);
}
Also used : Role(io.imunity.furms.domain.authz.roles.Role) ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 5 with PersistentId

use of io.imunity.furms.domain.users.PersistentId in project furms by unity-idm.

the class InvitatoryServiceTest method shouldInviteExistingUser.

@Test
void shouldInviteExistingUser() {
    Role role = Role.FENIX_ADMIN;
    ResourceId resourceId = new ResourceId((UUID) null, ResourceType.APP_LEVEL);
    PersistentId persistentId = new PersistentId("id");
    FenixUserId fenixId = new FenixUserId("fenixId");
    FURMSUser furmsUser = FURMSUser.builder().id(persistentId).fenixUserId(fenixId).email("email@email.com").build();
    Invitation invitation = Invitation.builder().resourceId(resourceId).role(role).userId(furmsUser.fenixUserId.get()).resourceName("system").originator("originator").email(furmsUser.email).utcExpiredAt(getExpiredAt()).build();
    when(usersDAO.findById(persistentId)).thenReturn(Optional.of(furmsUser));
    when(usersDAO.getUserAttributes(fenixId)).thenReturn(new UserAttributes(Set.of(), Map.of()));
    when(invitationRepository.findBy("email@email.com", role, resourceId)).thenReturn(Optional.empty());
    when(authzService.getCurrentAuthNUser()).thenReturn(FURMSUser.builder().email("originator").build());
    invitatoryService.inviteUser(persistentId, resourceId, role, "system");
    verify(invitationRepository).create(invitation);
    verify(userInvitationNotificationService).notifyUserAboutNewRole(persistentId, invitation.role);
}
Also used : Role(io.imunity.furms.domain.authz.roles.Role) ResourceId(io.imunity.furms.domain.authz.roles.ResourceId) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Invitation(io.imunity.furms.domain.invitations.Invitation) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PersistentId(io.imunity.furms.domain.users.PersistentId) UserAttributes(io.imunity.furms.domain.users.UserAttributes) Test(org.junit.jupiter.api.Test)

Aggregations

PersistentId (io.imunity.furms.domain.users.PersistentId)220 Test (org.junit.jupiter.api.Test)189 FenixUserId (io.imunity.furms.domain.users.FenixUserId)78 FURMSUser (io.imunity.furms.domain.users.FURMSUser)64 SSHKey (io.imunity.furms.domain.ssh_keys.SSHKey)51 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)47 ResourceId (io.imunity.furms.domain.authz.roles.ResourceId)40 UUID (java.util.UUID)35 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)24 AuditLogServiceImplTest (io.imunity.furms.core.audit_log.AuditLogServiceImplTest)20 Set (java.util.Set)18 Project (io.imunity.furms.domain.projects.Project)17 Site (io.imunity.furms.domain.sites.Site)16 Role (io.imunity.furms.domain.authz.roles.Role)15 Invitation (io.imunity.furms.domain.invitations.Invitation)15 I18nString (pl.edu.icm.unity.types.I18nString)15 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)13 RoleAssignmentAuditLogServiceTest (io.imunity.furms.core.users.audit_log.RoleAssignmentAuditLogServiceTest)12 PolicyId (io.imunity.furms.domain.policy_documents.PolicyId)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12