Search in sources :

Example 1 with FURMSUser

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

the class GenericGroupServiceImplTest method shouldFindAllGenericGroupAssignmentWithUser.

@Test
void shouldFindAllGenericGroupAssignmentWithUser() {
    GenericGroupId genericGroupId = new GenericGroupId(UUID.randomUUID());
    FURMSUser furmsUser = FURMSUser.builder().email("email").fenixUserId(new FenixUserId("userId")).build();
    GenericGroupMembership genericGroupMembership = GenericGroupMembership.builder().genericGroupId(genericGroupId).fenixUserId("userId").build();
    when(genericGroupRepository.existsBy("communityId", genericGroupId)).thenReturn(true);
    when(genericGroupRepository.findAllBy(genericGroupId)).thenReturn(Set.of(genericGroupMembership));
    when(usersDAO.getAllUsers()).thenReturn(List.of(furmsUser));
    Set<GenericGroupAssignmentWithUser> genericGroupServiceAll = genericGroupService.findAll("communityId", genericGroupId);
    assertEquals(1, genericGroupServiceAll.size());
    GenericGroupAssignmentWithUser next = genericGroupServiceAll.iterator().next();
    assertEquals(furmsUser, next.furmsUser);
    assertEquals(genericGroupMembership, next.membership);
}
Also used : GenericGroupAssignmentWithUser(io.imunity.furms.domain.generic_groups.GenericGroupAssignmentWithUser) GenericGroupMembership(io.imunity.furms.domain.generic_groups.GenericGroupMembership) FenixUserId(io.imunity.furms.domain.users.FenixUserId) GenericGroupId(io.imunity.furms.domain.generic_groups.GenericGroupId) FURMSUser(io.imunity.furms.domain.users.FURMSUser) Test(org.junit.jupiter.api.Test)

Example 2 with FURMSUser

use of io.imunity.furms.domain.users.FURMSUser 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 3 with FURMSUser

use of io.imunity.furms.domain.users.FURMSUser 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 4 with FURMSUser

use of io.imunity.furms.domain.users.FURMSUser 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 5 with FURMSUser

use of io.imunity.furms.domain.users.FURMSUser 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

FURMSUser (io.imunity.furms.domain.users.FURMSUser)147 Test (org.junit.jupiter.api.Test)71 PersistentId (io.imunity.furms.domain.users.PersistentId)67 AuditLog (io.imunity.furms.domain.audit_log.AuditLog)51 FenixUserId (io.imunity.furms.domain.users.FenixUserId)48 EventListener (org.springframework.context.event.EventListener)48 AuditLogEvent (io.imunity.furms.domain.audit_log.AuditLogEvent)45 ResourceId (io.imunity.furms.domain.authz.roles.ResourceId)34 UUID (java.util.UUID)21 Set (java.util.Set)20 Invitation (io.imunity.furms.domain.invitations.Invitation)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 Role (io.imunity.furms.domain.authz.roles.Role)15 PolicyAcceptance (io.imunity.furms.domain.policy_documents.PolicyAcceptance)13 PolicyId (io.imunity.furms.domain.policy_documents.PolicyId)13 PolicyDocument (io.imunity.furms.domain.policy_documents.PolicyDocument)12 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)12 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)11 InvitationId (io.imunity.furms.domain.invitations.InvitationId)11 UserPolicyAcceptancesWithServicePolicies (io.imunity.furms.domain.policy_documents.UserPolicyAcceptancesWithServicePolicies)10