-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #496 from gessnerfl/feature/489_tls_support
closes #489; simplified TLS support added to fake smtp server. automated test added, documentation update
- Loading branch information
Showing
13 changed files
with
4,134 additions
and
1,592 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/test/java/de/gessnerfl/fakesmtp/TLSIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.gessnerfl.fakesmtp; | ||
|
||
import de.gessnerfl.fakesmtp.repository.EmailRepository; | ||
import de.gessnerfl.fakesmtp.smtp.server.SmtpServer; | ||
import jakarta.transaction.Transactional; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSenderImpl; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@DirtiesContext | ||
@Transactional | ||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest | ||
@ActiveProfiles({"integrationtest_with_tls_required", "integrationtest", "default"}) | ||
class TLSIntegrationTest { | ||
|
||
@Autowired | ||
private EmailRepository emailRepository; | ||
@Autowired | ||
private SmtpServer smtpServer; | ||
|
||
@Test | ||
void shouldSendMailViaTLS() { | ||
var mailSender = new JavaMailSenderImpl(); | ||
mailSender.setHost("localhost"); | ||
mailSender.setPort(smtpServer.getPort()); | ||
|
||
var props = mailSender.getJavaMailProperties(); | ||
props.setProperty("mail.transport.protocol", "smtp"); | ||
props.setProperty("mail.smtp.auth", "false"); | ||
props.setProperty("mail.smtp.starttls.enable", "true"); | ||
props.setProperty("mail.smtp.ssl.protocols", "TLSv1.2"); | ||
props.setProperty("mail.smtp.ssl.trust", "*"); | ||
props.setProperty("mail.debug", "false"); | ||
|
||
var uniqueRandomName = "Test-Mail-" + RandomStringUtils.randomAlphanumeric(24); | ||
var message = new SimpleMailMessage(); | ||
message.setTo("[email protected]"); | ||
message.setFrom("[email protected]"); | ||
message.setSubject(uniqueRandomName); | ||
message.setText("This is the test mail"); | ||
mailSender.send(message); | ||
|
||
var mails = emailRepository.findBySubject(uniqueRandomName); | ||
assertThat(mails, hasSize(1)); | ||
assertEquals(uniqueRandomName, mails.get(0).getSubject()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,7 @@ fakesmtp: | |
blockedRecipientAddresses: | ||
- [email protected] | ||
requireTLS: true | ||
tls-keystore: | ||
location: classpath:tls-keystore.p12 | ||
password: changeit | ||
type: PKCS12 |
Oops, something went wrong.