use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.
the class DateTest method retrieveAndCheck.
/**
* Retrieve message from retriever and check content
*
* @param server Server to read from
* @param to Account to retrieve
* @param sentDate Desired 'sent' date of message
* @param checkReceivedDate True if received date should be checked. POP3 does not provide a received date
*/
private void retrieveAndCheck(AbstractServer server, String to, Date sentDate, boolean checkReceivedDate) throws MessagingException {
try (Retriever retriever = new Retriever(server)) {
Message[] messages = retriever.getMessages(to);
assertThat(messages.length).isEqualTo(1);
Message message = messages[0];
assertThat(milliSecondDateDiff(message.getSentDate(), sentDate)).isLessThan(3000L);
if (checkReceivedDate) {
assertThat(milliSecondDateDiff(message.getReceivedDate(), new Date())).isLessThan(3000L);
}
}
}
use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.
the class EscapingTest method retrieveAndCheck.
/**
* Retrieve message from retriever and check content
*
* @param server Server to read from
* @param to Account to retrieve
* @param subject Subject of message
*/
private void retrieveAndCheck(AbstractServer server, String to, String from, String subject) throws MessagingException {
try (Retriever retriever = new Retriever(server)) {
Message[] messages = retriever.getMessages(to);
assertThat(messages.length).isEqualTo(1);
Message message = messages[0];
// Message subject
assertThat(message.getSubject()).isEqualTo(subject);
assertThat(message.getAllRecipients()[0].toString()).isEqualTo(to);
assertThat(message.getFrom()[0].toString()).isEqualTo(from);
}
}
use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.
the class AuthenticationDisabledTest method testReceiveWithAuthDisabledAndProvisionedUser.
@Test
public void testReceiveWithAuthDisabledAndProvisionedUser() {
final String to = "to@localhost";
greenMail.setUser(to, "to", "secret");
greenMail.waitForIncomingEmail(500, 1);
try (Retriever retriever = new Retriever(greenMail.getImap())) {
Message[] messages = retriever.getMessages(to);
assertThat(messages.length).isEqualTo(0);
}
}
use of com.icegreen.greenmail.util.Retriever in project greenmail by greenmail-mail-test.
the class ReplyToTest method retrieveAndCheckReplyTo.
/**
* Retrieve message from retriever and check the ReplyTo address
*
* @param server Server to read from
* @param login Account to retrieve
*/
private void retrieveAndCheckReplyTo(AbstractServer server, String login, InternetAddress[] replyToAddrs) throws MessagingException {
try (Retriever retriever = new Retriever(server)) {
Message[] messages = retriever.getMessages(login);
assertThat(messages.length).isEqualTo(1);
Message message = messages[0];
assertThat(toInetAddr(message.getReplyTo())).isEqualTo(replyToAddrs);
}
}
use of com.icegreen.greenmail.util.Retriever in project videochat by nkonev.
the class RegistrationControllerTest method userCanRequestPasswordOnlyOnOwnEmail.
// scheme simplified, suspect that user's email doesn't stolen
@Test
public void userCanRequestPasswordOnlyOnOwnEmail() throws Exception {
final String user = TestConstants.USER_BOB;
final String email = user + "@example.com";
final String newPassword = "new-password";
// invoke resend, this sends url /password-reset?uuid=<uuid> and confirm code to email
mockMvc.perform(post(Constants.Urls.API + Constants.Urls.REQUEST_PASSWORD_RESET + "?email=" + email).with(csrf())).andExpect(status().isOk());
String passwordResetTokenUuidString;
try (Retriever r = new Retriever(greenMail.getImap())) {
Message[] messages = r.getMessages(email);
Assertions.assertEquals(1, messages.length, "backend should sent one email for password reset");
IMAPMessage imapMessage = (IMAPMessage) messages[0];
String content = (String) imapMessage.getContent();
String parsedUrl = UrlParser.parseUrlFromMessage(content);
passwordResetTokenUuidString = UriComponentsBuilder.fromUri(new URI(parsedUrl)).build().getQueryParams().get(Constants.Urls.UUID).get(0);
}
// after open link user see "input new password dialog"
// user inputs code, code compares with another in ResetPasswordToken
PasswordResetController.PasswordResetDto passwordResetDto = new PasswordResetController.PasswordResetDto(UUID.fromString(passwordResetTokenUuidString), newPassword);
// user click "set new password" button in modal
mockMvc.perform(post(Constants.Urls.API + Constants.Urls.PASSWORD_RESET_SET_NEW).content(objectMapper.writeValueAsString(passwordResetDto)).contentType(MediaType.APPLICATION_JSON_UTF8_VALUE).with(csrf())).andExpect(status().isOk());
// ... this is changes his password
// login with new password ok
mockMvc.perform(post(SecurityConfig.API_LOGIN_URL).contentType(MediaType.APPLICATION_FORM_URLENCODED).param(SecurityConfig.USERNAME_PARAMETER, user).param(SecurityConfig.PASSWORD_PARAMETER, newPassword).with(csrf())).andExpect(status().isOk());
}
Aggregations