Search in sources :

Example 36 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent in project simba-os by cegeka.

the class ResetPasswordServiceTest method sendMessage_WillGenerateTokenAndLinkAndSendMail_WillTriggerAuditloggingForForgotPassword.

@Test
public void sendMessage_WillGenerateTokenAndLinkAndSendMail_WillTriggerAuditloggingForForgotPassword() throws Exception {
    EmailAddress email = emailFactory.email("something@mail.com");
    User user = aDefaultUser().withUserName("test").withEmail(email).withLanguage(en_US).build();
    Token token = Token.generateToken();
    when(tokenManagerMock.generateToken(user, forgotPasswordReason)).thenReturn(token);
    URL link = new URL("http://www.google.com");
    List<URL> links = Collections.singletonList(link);
    when(linkGeneratorMock.generateResetPasswordLinks(email, token)).thenReturn(links);
    when(templateServiceMock.createMailBodyWithLink(new TemplateWithLinks(forgotPasswordReason.getTemplate(), links), en_US)).thenReturn("someBody");
    when(templateServiceMock.createMailSubject(forgotPasswordReason.getSubjectTemplate(), en_US)).thenReturn("Reset password");
    resetPasswordService.sendResetPasswordMessageTo(user, forgotPasswordReason);
    verify(mailServiceMock).sendMail(mail().from(emailFactory.email("bla@hotmail.com")).to(email).subject("Reset password").body("someBody"));
    ArgumentCaptor<AuditLogEvent> captor = ArgumentCaptor.forClass(AuditLogEvent.class);
    verify(auditMock).log(captor.capture());
    assertThat(captor.getValue()).extracting(AuditLogEvent::getUsername, AuditLogEvent::getMessage, AuditLogEvent::getCategory).containsExactly("test", "Email has been sent to user for following reason: ForgotPassword", AUTHENTICATION);
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) UserTestBuilder.aDefaultUser(org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser) User(org.simbasecurity.core.domain.User) Token(org.simbasecurity.core.domain.communication.token.Token) EmailAddress(org.simbasecurity.core.domain.user.EmailAddress) URL(java.net.URL) TemplateWithLinks(org.simbasecurity.core.service.communication.mail.template.TemplateWithLinks) Test(org.junit.Test)

Aggregations

AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)36 Test (org.junit.Test)32 Command (org.simbasecurity.core.chain.Command)9 User (org.simbasecurity.core.domain.User)8 State (org.simbasecurity.core.chain.Command.State)6 UserTestBuilder.aDefaultUser (org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser)6 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)4 Token (org.simbasecurity.core.domain.communication.token.Token)3 URL (java.net.URL)2 PolicyDecision (org.simbasecurity.api.service.thrift.PolicyDecision)2 Session (org.simbasecurity.core.domain.Session)2 EmailAddress (org.simbasecurity.core.domain.user.EmailAddress)2 TemplateWithLinks (org.simbasecurity.core.service.communication.mail.template.TemplateWithLinks)2 Optional (java.util.Optional)1 Audit (org.simbasecurity.core.audit.Audit)1 AuditLogEventFactory (org.simbasecurity.core.audit.AuditLogEventFactory)1 ChainContext (org.simbasecurity.core.chain.ChainContext)1 CONTINUE (org.simbasecurity.core.chain.Command.State.CONTINUE)1 FINISH (org.simbasecurity.core.chain.Command.State.FINISH)1 UserTestBuilder.aUser (org.simbasecurity.core.domain.UserTestBuilder.aUser)1