forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor improvements to invitation email templates
Signed-off-by: Pedro Igor <[email protected]>
- Loading branch information
Showing
8 changed files
with
33 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,14 @@ | |
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.internet.MimeMessage; | ||
import jakarta.ws.rs.core.Response; | ||
import org.jboss.arquillian.graphene.page.Page; | ||
|
@@ -33,8 +35,6 @@ | |
import org.keycloak.admin.client.resource.OrganizationResource; | ||
import org.keycloak.common.Profile.Feature; | ||
import org.keycloak.common.util.UriUtils; | ||
import org.keycloak.cookie.CookieProvider; | ||
import org.keycloak.cookie.CookieScope; | ||
import org.keycloak.cookie.CookieType; | ||
import org.keycloak.representations.idm.RealmRepresentation; | ||
import org.keycloak.representations.idm.UserRepresentation; | ||
|
@@ -46,6 +46,7 @@ | |
import org.keycloak.testsuite.pages.RegisterPage; | ||
import org.keycloak.testsuite.util.GreenMailRule; | ||
import org.keycloak.testsuite.util.MailUtils; | ||
import org.keycloak.testsuite.util.MailUtils.EmailBody; | ||
import org.keycloak.testsuite.util.UserBuilder; | ||
|
||
@EnableFeature(Feature.ORGANIZATION) | ||
|
@@ -71,7 +72,7 @@ public void configureTestRealm(RealmRepresentation testRealm) { | |
} | ||
|
||
@Test | ||
public void testInviteExistingUser() throws IOException { | ||
public void testInviteExistingUser() throws IOException, MessagingException { | ||
UserRepresentation user = UserBuilder.create() | ||
.username("invited") | ||
.email("[email protected]") | ||
|
@@ -88,7 +89,9 @@ public void testInviteExistingUser() throws IOException { | |
|
||
MimeMessage message = greenMail.getLastReceivedMessage(); | ||
Assert.assertNotNull(message); | ||
String link = MailUtils.getPasswordResetEmailLink(message); | ||
Assert.assertEquals("Invitation to join the " + organizationName + " organization", message.getSubject()); | ||
EmailBody body = MailUtils.getBody(message); | ||
String link = MailUtils.getLink(body.getHtml()); | ||
driver.navigate().to(link.trim()); | ||
// not yet a member | ||
Assert.assertFalse(organization.members().getAll().stream().anyMatch(actual -> user.getId().equals(actual.getId()))); | ||
|
@@ -100,7 +103,7 @@ public void testInviteExistingUser() throws IOException { | |
} | ||
|
||
@Test | ||
public void testInviteNewUserRegistration() throws IOException { | ||
public void testInviteNewUserRegistration() throws IOException, MessagingException { | ||
UserRepresentation user = UserBuilder.create() | ||
.username("invitedUser") | ||
.email("inviteduser@email") | ||
|
@@ -112,7 +115,14 @@ public void testInviteNewUserRegistration() throws IOException { | |
|
||
MimeMessage message = greenMail.getLastReceivedMessage(); | ||
Assert.assertNotNull(message); | ||
String link = MailUtils.getPasswordResetEmailLink(message); | ||
Assert.assertEquals("Invitation to join the " + organizationName + " organization", message.getSubject()); | ||
EmailBody body = MailUtils.getBody(message); | ||
String link = MailUtils.getLink(body.getHtml()); | ||
String text = body.getHtml(); | ||
assertTrue(text.contains("<p>You were invited to join the " + organizationName + " organization. Click the link below to join. </p>")); | ||
assertTrue(text.contains("<a href=\"" + link + "\" rel=\"nofollow\">Link to join the organization</a></p>")); | ||
assertTrue(text.contains("Link to join the organization")); | ||
assertTrue(text.contains("<p>If you dont want to join the organization, just ignore this message.</p>")); | ||
String orgToken = UriUtils.parseQueryParameters(link, false).values().stream().map(strings -> strings.get(0)).findFirst().orElse(null); | ||
Assert.assertNotNull(orgToken); | ||
driver.navigate().to(link.trim()); | ||
|
@@ -144,7 +154,8 @@ public void testEmailDoesNotChangeOnRegistration() throws IOException { | |
|
||
MimeMessage message = greenMail.getLastReceivedMessage(); | ||
Assert.assertNotNull(message); | ||
String link = MailUtils.getPasswordResetEmailLink(message); | ||
EmailBody body = MailUtils.getBody(message); | ||
String link = MailUtils.getLink(body.getHtml()); | ||
String orgToken = UriUtils.parseQueryParameters(link, false).values().stream().map(strings -> strings.get(0)).findFirst().orElse(null); | ||
Assert.assertNotNull(orgToken); | ||
driver.navigate().to(link.trim()); | ||
|
@@ -173,7 +184,8 @@ public void testLinkExpired() throws IOException { | |
setTimeOffset((int) TimeUnit.DAYS.toSeconds(1)); | ||
MimeMessage message = greenMail.getLastReceivedMessage(); | ||
Assert.assertNotNull(message); | ||
String link = MailUtils.getPasswordResetEmailLink(message); | ||
EmailBody body = MailUtils.getBody(message); | ||
String link = MailUtils.getLink(body.getHtml()); | ||
String orgToken = UriUtils.parseQueryParameters(link, false).values().stream().map(strings -> strings.get(0)).findFirst().orElse(null); | ||
Assert.assertNotNull(orgToken); | ||
driver.navigate().to(link.trim()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<#import "template.ftl" as layout> | ||
<@layout.emailLayout> | ||
${kcSanitize(msg("orgInviteBodyHtml", link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))?no_esc} | ||
${kcSanitize(msg("orgInviteBodyHtml", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration)))?no_esc} | ||
</@layout.emailLayout> |
4 changes: 3 additions & 1 deletion
4
themes/src/main/resources/theme/base/email/messages/messages_en.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<#ftl output_format="plainText"> | ||
${kcSanitize(msg("orgInviteBodyHtml", link, linkExpiration, realmName, linkExpirationFormatter(linkExpiration)))} | ||
${kcSanitize(msg("orgInviteBody", link, linkExpiration, realmName, organization.name, linkExpirationFormatter(linkExpiration)))} |