mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 03:20:46 +02:00
Add configurable SMTP TLS/SSL options (#5204)
## Summary - add optional STARTTLS and SSL-related fields to mail settings with defaults matching prior behavior - apply the new mail properties in the SMTP JavaMail configuration, including trust and hostname verification overrides - update mail settings template and tests to cover default behavior and explicit TLS/SSL overrides - clarify STARTTLS naming and sslTrust usage with examples in property comments and the settings template - default sslTrust to a wildcard when unset so TLS connections accept any host by default unless tightened ## Testing - ./gradlew :proprietary:test --tests stirling.software.proprietary.security.service.MailConfigTest --console plain ------ [Codex Task](https://chatgpt.com/codex/tasks/task_b_693864b2a6648328ae75c7e88a726a65)
This commit is contained in:
+32
-1
@@ -27,6 +27,11 @@ class MailConfigTest {
|
||||
when(mailProps.getPort()).thenReturn(587);
|
||||
when(mailProps.getUsername()).thenReturn("[email protected]");
|
||||
when(mailProps.getPassword()).thenReturn("password");
|
||||
when(mailProps.getStartTlsEnable()).thenReturn(null);
|
||||
when(mailProps.getStartTlsRequired()).thenReturn(null);
|
||||
when(mailProps.getSslEnable()).thenReturn(null);
|
||||
when(mailProps.getSslTrust()).thenReturn(null);
|
||||
when(mailProps.getSslCheckServerIdentity()).thenReturn(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,6 +55,32 @@ class MailConfigTest {
|
||||
() -> assertEquals("password", impl.getPassword()),
|
||||
() -> assertEquals("UTF-8", impl.getDefaultEncoding()),
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.auth")),
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.starttls.enable")));
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.starttls.enable")),
|
||||
() -> assertEquals(null, props.getProperty("mail.smtp.starttls.required")),
|
||||
() -> assertEquals(null, props.getProperty("mail.smtp.ssl.enable")),
|
||||
() -> assertEquals("*", props.getProperty("mail.smtp.ssl.trust")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRespectExplicitTlsOverrides() {
|
||||
ApplicationProperties appProps = mock(ApplicationProperties.class);
|
||||
when(mailProps.getStartTlsEnable()).thenReturn(false);
|
||||
when(mailProps.getStartTlsRequired()).thenReturn(true);
|
||||
when(mailProps.getSslEnable()).thenReturn(true);
|
||||
when(mailProps.getSslTrust()).thenReturn("*");
|
||||
when(mailProps.getSslCheckServerIdentity()).thenReturn(true);
|
||||
when(appProps.getMail()).thenReturn(mailProps);
|
||||
|
||||
MailConfig config = new MailConfig(appProps);
|
||||
JavaMailSenderImpl impl = (JavaMailSenderImpl) config.javaMailSender();
|
||||
|
||||
Properties props = impl.getJavaMailProperties();
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals("false", props.getProperty("mail.smtp.starttls.enable")),
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.starttls.required")),
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.ssl.enable")),
|
||||
() -> assertEquals("*", props.getProperty("mail.smtp.ssl.trust")),
|
||||
() -> assertEquals("true", props.getProperty("mail.smtp.ssl.checkserveridentity")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user