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);
}
Aggregations