From 1a541889f48083f26205f8adb14d1a6d6b031146 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 14 Dec 2017 15:36:06 -0200 Subject: [PATCH] [KEYCLOAK-6015] replyTo can be empty string in DB --- .../keycloak/email/DefaultEmailSenderProvider.java | 4 ++-- .../keycloak/testsuite/admin/SMTPConnectionTest.java | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java index ca3575c7a9..23efd9048c 100644 --- a/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java +++ b/services/src/main/java/org/keycloak/email/DefaultEmailSenderProvider.java @@ -120,10 +120,10 @@ public class DefaultEmailSenderProvider implements EmailSenderProvider { msg.setFrom(toInternetAddress(from, fromDisplayName)); msg.setReplyTo(new Address[]{toInternetAddress(from, fromDisplayName)}); - if (replyTo != null) { + if (replyTo != null && !replyTo.isEmpty()) { msg.setReplyTo(new Address[]{toInternetAddress(replyTo, replyToDisplayName)}); } - if (envelopeFrom != null) { + if (envelopeFrom != null && !envelopeFrom.isEmpty()) { msg.setEnvelopeFrom(envelopeFrom); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/SMTPConnectionTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/SMTPConnectionTest.java index ac7a947fab..d06679f905 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/SMTPConnectionTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/SMTPConnectionTest.java @@ -61,11 +61,12 @@ public class SMTPConnectionTest extends AbstractKeycloakTest { private String settings(String host, String port, String from, String auth, String ssl, String starttls, String username, String password) throws Exception { - Map config = smtpMap(host, port, from, auth, ssl, starttls, username, password); + Map config = smtpMap(host, port, from, auth, ssl, starttls, username, password, "", ""); return writeValueAsPrettyString(config); } - private Map smtpMap(String host, String port, String from, String auth, String ssl, String starttls, String username, String password) { + private Map smtpMap(String host, String port, String from, String auth, String ssl, String starttls, + String username, String password, String replyTo, String envelopeFrom) { Map config = new HashMap<>(); config.put("host", host); config.put("port", port); @@ -75,11 +76,13 @@ public class SMTPConnectionTest extends AbstractKeycloakTest { config.put("starttls", starttls); config.put("user", username); config.put("password", password); + config.put("replyTo", replyTo); + config.put("envelopeFrom", envelopeFrom); return config; } @Test - public void testWithEmptySettings() throws Exception { + public void testWithNullSettings() throws Exception { Response response = realm.testSMTPConnection(settings(null, null, null, null, null, null, null, null)); assertStatus(response, 500); @@ -114,7 +117,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest { Map oldSmtp = realmRep.getSmtpServer(); try { realmRep.setSmtpServer(smtpMap("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null, - "admin@localhost", "admin")); + "admin@localhost", "admin", null, null)); realm.update(realmRep); greenMailRule.credentials("admin@localhost", "admin");