Skip to content

Commit 88a7a44

Browse files
committed
Polish "Treat empty SSL bundle as unset"
Update Mail SSL configuration as well. See gh-50624
1 parent 39ed20b commit 88a7a44

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private void applyProperties(MailProperties properties, JavaMailSenderImpl sende
6969
if (ssl.isEnabled()) {
7070
javaMailProperties.setProperty("mail." + protocol + ".ssl.enable", "true");
7171
}
72-
if (ssl.getBundle() != null) {
72+
if (StringUtils.hasLength(ssl.getBundle())) {
7373
SslBundle sslBundle = sslBundles.getBundle(ssl.getBundle());
7474
javaMailProperties.put("mail." + protocol + ".ssl.socketFactory",
7575
sslBundle.createSslContext().getSocketFactory());

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mail/MailSenderAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ void connectionOnStartupNotCalled() {
245245
});
246246
}
247247

248+
@Test
249+
@WithPackageResources("test.jks")
250+
void sslIsNotEnabledWhenBundleIsEmpty() {
251+
this.contextRunner
252+
.withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.bundle: ",
253+
"spring.ssl.bundle.jks.test-bundle.keystore.location:classpath:test.jks",
254+
"spring.ssl.bundle.jks.test-bundle.keystore.password:secret",
255+
"spring.ssl.bundle.jks.test-bundle.key.password:password")
256+
.run((context) -> {
257+
assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
258+
JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
259+
assertThat(mailSender.getJavaMailProperties().get("mail.smtp.ssl.socketFactory")).isNull();
260+
});
261+
}
262+
248263
@Test
249264
void smtpSslEnabled() {
250265
this.contextRunner.withPropertyValues("spring.mail.host:localhost", "spring.mail.ssl.enabled:true")

0 commit comments

Comments
 (0)