[KEYCLOAK-5486] Test email connection feature does not work the second time (#4517)
This commit is contained in:
1 parent
b17cbadaf3
commit
bb0bccc3c0
2 files changed
+30
-1
No files matched your search
@@ -833,6 +833,9 @@ public class RealmAdminResource {
|
||||
if (user.getEmail() == null) {
|
||||
return ErrorResponse.error("Logged in user does not have an e-mail.", Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
if (ComponentRepresentation.SECRET_VALUE.equals(settings.get("password"))) {
|
||||
settings.put("password", realm.getSmtpConfig().get("password"));
|
||||
}
|
||||
session.getProvider(EmailTemplateProvider.class).sendSmtpTestEmail(settings, user);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
+27
-1
@@ -35,6 +35,7 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.keycloak.representations.idm.ComponentRepresentation.SECRET_VALUE;
|
||||
import static org.keycloak.util.JsonSerialization.writeValueAsPrettyString;
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,11 @@ 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<String, String> config = smtpMap(host, port, from, auth, ssl, starttls, username, password);
|
||||
return writeValueAsPrettyString(config);
|
||||
}
|
||||
|
||||
private Map<String, String> smtpMap(String host, String port, String from, String auth, String ssl, String starttls, String username, String password) {
|
||||
Map<String, String> config = new HashMap<>();
|
||||
config.put("host", host);
|
||||
config.put("port", port);
|
||||
@@ -69,7 +75,7 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||
config.put("starttls", starttls);
|
||||
config.put("user", username);
|
||||
config.put("password", password);
|
||||
return writeValueAsPrettyString(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,6 +108,26 @@ public class SMTPConnectionTest extends AbstractKeycloakTest {
|
||||
assertStatus(response, 204);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthEnabledAndSavedCredentials() throws Exception {
|
||||
RealmRepresentation realmRep = realm.toRepresentation();
|
||||
Map<String, String> oldSmtp = realmRep.getSmtpServer();
|
||||
try {
|
||||
realmRep.setSmtpServer(smtpMap("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
|
||||
"admin@localhost", "admin"));
|
||||
realm.update(realmRep);
|
||||
|
||||
greenMailRule.credentials("admin@localhost", "admin");
|
||||
Response response = realm.testSMTPConnection(settings("127.0.0.1", "3025", "auto@keycloak.org", "true", null, null,
|
||||
"admin@localhost", SECRET_VALUE));
|
||||
assertStatus(response, 204);
|
||||
} finally {
|
||||
// Revert SMTP back
|
||||
realmRep.setSmtpServer(oldSmtp);
|
||||
realm.update(realmRep);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertStatus(Response response, int status) {
|
||||
assertEquals(status, response.getStatus());
|
||||
response.close();
|
||||
|
||||
Reference in new issue
Block a user