Search in sources :

Example 1 with PolicyAcceptance

use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.

the class PolicyDocumentAuditLogServiceIntegrationTest method shouldDetectPolicyDocumentAcceptation.

@Test
void shouldDetectPolicyDocumentAcceptation() {
    FenixUserId userId = new FenixUserId("userId");
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).revision(1).siteId("siteId").build();
    PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
    FURMSUser user = FURMSUser.builder().id(new PersistentId("id")).email("email").fenixUserId(userId).build();
    when(usersDAO.findById(userId)).thenReturn(Optional.of(user));
    when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
    service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
    ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
    Mockito.verify(auditLogRepository).create(argument.capture());
    assertEquals(Operation.POLICY_ACCEPTANCE, argument.getValue().operationCategory);
    assertEquals(Action.ACCEPT, argument.getValue().action);
}
Also used : PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) FenixUserId(io.imunity.furms.domain.users.FenixUserId) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) PersistentId(io.imunity.furms.domain.users.PersistentId) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PolicyAcceptance

use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.

the class PolicyDocumentServiceImplTest method shouldUpdateUsersPolicyAcceptances.

@Test
void shouldUpdateUsersPolicyAcceptances() {
    FenixUserId userId = new FenixUserId("userId");
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
    FURMSUser furmsUser = FURMSUser.builder().email("email").fenixUserId(userId).build();
    PolicyDocument policyDocument = PolicyDocument.builder().id((policyId)).siteId("siteId").revision(1).build();
    Site site = Site.builder().id("siteId").externalId(new SiteExternalId("id")).build();
    AssignedPolicyDocument servicePolicyDocument = AssignedPolicyDocument.builder().build();
    when(usersDAO.findById(userId)).thenReturn(Optional.of(furmsUser));
    when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
    when(repository.findAllAssignPoliciesBySiteId("siteId")).thenReturn(Set.of(servicePolicyDocument));
    when(siteRepository.findById("siteId")).thenReturn(Optional.of(site));
    when(userRepository.isUserInstalledOnSite(userId, "siteId")).thenReturn(true);
    when(policyDocumentDAO.getPolicyAcceptances(userId)).thenReturn(Set.of(policyAcceptance));
    service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
    Mockito.verify(siteAgentPolicyDocumentService).updateUsersPolicyAcceptances(site.getExternalId(), new UserPolicyAcceptancesWithServicePolicies(furmsUser, Set.of(policyAcceptance), Optional.empty(), Set.of(servicePolicyDocument)));
}
Also used : Site(io.imunity.furms.domain.sites.Site) UserPolicyAcceptancesWithServicePolicies(io.imunity.furms.domain.policy_documents.UserPolicyAcceptancesWithServicePolicies) PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) FenixUserId(io.imunity.furms.domain.users.FenixUserId) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) SiteExternalId(io.imunity.furms.domain.sites.SiteExternalId) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) Test(org.junit.jupiter.api.Test)

Example 3 with PolicyAcceptance

use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.

the class PolicyDocumentServiceImplTest method shouldAddPolicyToUser.

@Test
void shouldAddPolicyToUser() {
    FenixUserId userId = new FenixUserId("userId");
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).policyDocumentRevision(1).build();
    FURMSUser furmsUser = FURMSUser.builder().email("email").fenixUserId(userId).build();
    PolicyDocument policyDocument = PolicyDocument.builder().id((policyId)).siteId("siteId").revision(1).build();
    when(usersDAO.findById(userId)).thenReturn(Optional.of(furmsUser));
    when(repository.findById(policyId)).thenReturn(Optional.of(policyDocument));
    service.addUserPolicyAcceptance("siteId", userId, policyAcceptance);
    orderVerifier.verify(policyDocumentDAO).addUserPolicyAcceptance(userId, policyAcceptance);
    orderVerifier.verify(publisher).publishEvent(new UserAcceptedPolicyEvent(userId, policyAcceptance));
    verify(repository, times(0)).findById(PolicyId.empty());
}
Also used : PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) UserAcceptedPolicyEvent(io.imunity.furms.domain.policy_documents.UserAcceptedPolicyEvent) FenixUserId(io.imunity.furms.domain.users.FenixUserId) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) AssignedPolicyDocument(io.imunity.furms.domain.policy_documents.AssignedPolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) Test(org.junit.jupiter.api.Test)

Example 4 with PolicyAcceptance

use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.

the class PolicyNotificationServiceTest method shouldNotNotifyAboutChangedPolicy.

@Test
void shouldNotNotifyAboutChangedPolicy() {
    PersistentId id = new PersistentId(UUID.randomUUID().toString());
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    String siteId = "siteId";
    PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).siteId(siteId).name("policyName").build();
    FURMSUser user = FURMSUser.builder().id(id).fenixUserId("fenixUserId").email("email").build();
    PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(new PolicyId(UUID.randomUUID())).build();
    UserPolicyAcceptances userPolicyAcceptances = new UserPolicyAcceptances(user, Set.of(policyAcceptance));
    when(policyDocumentDAO.getUserPolicyAcceptances(siteId)).thenReturn(Set.of(userPolicyAcceptances));
    policyNotificationService.notifyAboutChangedPolicy(policyDocument);
    verify(emailNotificationSender, times(0)).notifyAboutChangedPolicy(id, "policyName");
}
Also used : PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) UserPolicyAcceptances(io.imunity.furms.domain.policy_documents.UserPolicyAcceptances) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Example 5 with PolicyAcceptance

use of io.imunity.furms.domain.policy_documents.PolicyAcceptance in project furms by unity-idm.

the class PolicyNotificationServiceTest method shouldNotifyAboutChangedPolicy.

@Test
void shouldNotifyAboutChangedPolicy() {
    PersistentId id = new PersistentId(UUID.randomUUID().toString());
    PolicyId policyId = new PolicyId(UUID.randomUUID());
    String siteId = "siteId";
    PolicyDocument policyDocument = PolicyDocument.builder().id(policyId).siteId(siteId).name("policyName").build();
    FURMSUser user = FURMSUser.builder().id(id).fenixUserId("fenixUserId").email("email").build();
    PolicyAcceptance policyAcceptance = PolicyAcceptance.builder().policyDocumentId(policyId).build();
    UserPolicyAcceptances userPolicyAcceptances = new UserPolicyAcceptances(user, Set.of(policyAcceptance));
    when(policyDocumentDAO.getUserPolicyAcceptances(siteId)).thenReturn(Set.of(userPolicyAcceptances));
    policyNotificationService.notifyAboutChangedPolicy(policyDocument);
    verify(emailNotificationSender).notifyAboutChangedPolicy(id, "policyName");
}
Also used : PolicyAcceptance(io.imunity.furms.domain.policy_documents.PolicyAcceptance) UserPolicyAcceptances(io.imunity.furms.domain.policy_documents.UserPolicyAcceptances) PolicyDocument(io.imunity.furms.domain.policy_documents.PolicyDocument) FURMSUser(io.imunity.furms.domain.users.FURMSUser) PolicyId(io.imunity.furms.domain.policy_documents.PolicyId) PersistentId(io.imunity.furms.domain.users.PersistentId) Test(org.junit.jupiter.api.Test)

Aggregations

PolicyAcceptance (io.imunity.furms.domain.policy_documents.PolicyAcceptance)23 PolicyId (io.imunity.furms.domain.policy_documents.PolicyId)20 PolicyDocument (io.imunity.furms.domain.policy_documents.PolicyDocument)17 FenixUserId (io.imunity.furms.domain.users.FenixUserId)16 Test (org.junit.jupiter.api.Test)16 FURMSUser (io.imunity.furms.domain.users.FURMSUser)14 PersistentId (io.imunity.furms.domain.users.PersistentId)8 AssignedPolicyDocument (io.imunity.furms.domain.policy_documents.AssignedPolicyDocument)7 UserAcceptedPolicyEvent (io.imunity.furms.domain.policy_documents.UserAcceptedPolicyEvent)7 UserPolicyAcceptances (io.imunity.furms.domain.policy_documents.UserPolicyAcceptances)7 Site (io.imunity.furms.domain.sites.Site)7 SiteId (io.imunity.furms.domain.sites.SiteId)6 SiteExternalId (io.imunity.furms.domain.sites.SiteExternalId)5 Optional (java.util.Optional)5 UserPolicyAcceptancesWithServicePolicies (io.imunity.furms.domain.policy_documents.UserPolicyAcceptancesWithServicePolicies)4 Service (org.springframework.stereotype.Service)4 Collectors (java.util.stream.Collectors)3 PolicyDocumentService (io.imunity.furms.api.policy_documents.PolicyDocumentService)2 UserWithoutFenixIdValidationError (io.imunity.furms.api.validation.exceptions.UserWithoutFenixIdValidationError)2 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)2