KEYCLOAK-6000 Fix output in execute actions email
This commit is contained in:
parent
867de9de50
commit
dac6c6bd7e
13 changed files with 67 additions and 35 deletions
|
@ -42,30 +42,49 @@ public class MailUtils {
|
|||
}
|
||||
|
||||
public static String getPasswordResetEmailLink(MimeMessage message) throws IOException, MessagingException {
|
||||
Multipart multipart = (Multipart) message.getContent();
|
||||
return getPasswordResetEmailLink(new EmailBody(message));
|
||||
}
|
||||
|
||||
final String textContentType = multipart.getBodyPart(0).getContentType();
|
||||
|
||||
assertEquals("text/plain; charset=UTF-8", textContentType);
|
||||
|
||||
final String textBody = (String) multipart.getBodyPart(0).getContent();
|
||||
final String textChangePwdUrl = getLink(textBody);
|
||||
|
||||
final String htmlContentType = multipart.getBodyPart(1).getContentType();
|
||||
|
||||
assertEquals("text/html; charset=UTF-8", htmlContentType);
|
||||
|
||||
final String htmlBody = (String) multipart.getBodyPart(1).getContent();
|
||||
final String htmlChangePwdUrl = MailUtils.getLink(htmlBody);
|
||||
// .replace() accounts for escaping the ampersand
|
||||
// It's not escaped in the html version because html retrieved from a
|
||||
// message bundle is considered safe and it must be unescaped to display
|
||||
// properly.
|
||||
final String htmlChangePwdUrlToCompare = htmlChangePwdUrl.replace("&", "&");
|
||||
|
||||
assertEquals(htmlChangePwdUrlToCompare, textChangePwdUrl);
|
||||
public static String getPasswordResetEmailLink(EmailBody body) throws IOException, MessagingException {
|
||||
final String textChangePwdUrl = getLink(body.getText());
|
||||
final String htmlChangePwdUrl = getLink(body.getHtml());
|
||||
assertEquals(htmlChangePwdUrl, textChangePwdUrl);
|
||||
|
||||
return htmlChangePwdUrl;
|
||||
}
|
||||
|
||||
public static EmailBody getBody(MimeMessage message) throws IOException, MessagingException {
|
||||
return new EmailBody(message);
|
||||
}
|
||||
|
||||
public static class EmailBody {
|
||||
|
||||
private String text;
|
||||
private String html;
|
||||
|
||||
private EmailBody(MimeMessage message) throws IOException, MessagingException {
|
||||
Multipart multipart = (Multipart) message.getContent();
|
||||
|
||||
String textContentType = multipart.getBodyPart(0).getContentType();
|
||||
|
||||
assertEquals("text/plain; charset=UTF-8", textContentType);
|
||||
|
||||
text = (String) multipart.getBodyPart(0).getContent();
|
||||
|
||||
String htmlContentType = multipart.getBodyPart(1).getContentType();
|
||||
|
||||
assertEquals("text/html; charset=UTF-8", htmlContentType);
|
||||
|
||||
html = (String) multipart.getBodyPart(1).getContent();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String getHtml() {
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -681,7 +681,17 @@ public class UserTest extends AbstractAdminTest {
|
|||
|
||||
MimeMessage message = greenMail.getReceivedMessages()[0];
|
||||
|
||||
String link = MailUtils.getPasswordResetEmailLink(message);
|
||||
MailUtils.EmailBody body = MailUtils.getBody(message);
|
||||
|
||||
assertTrue(body.getText().contains("Update Password"));
|
||||
assertTrue(body.getText().contains("your Admin-client-test account"));
|
||||
assertTrue(body.getText().contains("This link will expire within 720 minutes"));
|
||||
|
||||
assertTrue(body.getHtml().contains("Update Password"));
|
||||
assertTrue(body.getHtml().contains("your Admin-client-test account"));
|
||||
assertTrue(body.getHtml().contains("This link will expire within 720 minutes"));
|
||||
|
||||
String link = MailUtils.getPasswordResetEmailLink(body);
|
||||
|
||||
driver.navigate().to(link);
|
||||
|
||||
|
|
|
@ -358,13 +358,7 @@ public abstract class AbstractIdentityProviderTest {
|
|||
final String htmlBody = (String) multipart.getBodyPart(1).getContent();
|
||||
|
||||
final String htmlChangePwdUrl = MailUtil.getLink(htmlBody);
|
||||
// .replace() accounts for escaping the ampersand
|
||||
// It's not escaped in the html version because html retrieved from a
|
||||
// message bundle is considered safe and it must be unescaped to display
|
||||
// properly.
|
||||
final String htmlChangePwdUrlToCompare = htmlChangePwdUrl.replace("&", "&");
|
||||
|
||||
assertEquals(htmlChangePwdUrlToCompare, textVerificationUrl);
|
||||
assertEquals(htmlChangePwdUrl, textVerificationUrl);
|
||||
|
||||
return htmlChangePwdUrl;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<#assign requiredActionsText>
|
||||
<#if requiredActions??><#list requiredActions><b><#items as reqActionItem>${msg("requiredAction.${reqActionItem}")}<#sep>, </#items></b></#list><#else></#if>
|
||||
</#assign>
|
||||
<#outputformat "plainText">
|
||||
<#assign requiredActionsText><#if requiredActions??><#list requiredActions><#items as reqActionItem>${msg("requiredAction.${reqActionItem}")}<#sep>, </#sep></#items></#list></#if></#assign>
|
||||
</#outputformat>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
${msg("executeActionsBodyHtml",link, linkExpiration, realmName, requiredActionsText)?no_esc}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("emailTestBody", realmName)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("emailVerificationBody",link, linkExpiration, realmName)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("eventLoginErrorBody",event.date,event.ipAddress)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("eventRemoveTotpBody",event.date, event.ipAddress)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("eventUpdatePasswordBody",event.date, event.ipAddress)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("eventUpdateTotpBody",event.date, event.ipAddress)}
|
|
@ -1,4 +1,4 @@
|
|||
<#assign requiredActionsText>
|
||||
<#if requiredActions??><#list requiredActions><#items as reqActionItem>${msg("requiredAction.${reqActionItem}")}<#sep>, </#items></#list><#else></#if>
|
||||
</#assign>
|
||||
<#ftl output_format="plainText">
|
||||
<#assign requiredActionsText><#if requiredActions??><#list requiredActions><#items as reqActionItem>${msg("requiredAction.${reqActionItem}")}<#sep>, </#items></#list><#else></#if></#assign>
|
||||
|
||||
${msg("executeActionsBody",link, linkExpiration, realmName, requiredActionsText)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("identityProviderLinkBody", identityProviderAlias, realmName, identityProviderContext.username, link, linkExpiration)}
|
|
@ -1 +1,2 @@
|
|||
<#ftl output_format="plainText">
|
||||
${msg("passwordResetBody",link, linkExpiration, realmName)}
|
Loading…
Reference in a new issue