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.
Fix credential_type in update/remove credential email template
Closes keycloak#34687 Signed-off-by: Achim Rolle <[email protected]> Signed-off-by: rmartinc <[email protected]> Co-authored-by: rmartinc <[email protected]> (cherry picked from commit 83065b8)
- Loading branch information
1 parent
8df4e88
commit 5aa874e
Showing
7 changed files
with
121 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,17 +19,21 @@ | |
|
||
package org.keycloak.testsuite.actions; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.mail.internet.MimeMessage; | ||
import jakarta.ws.rs.core.Response; | ||
import java.util.List; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.arquillian.graphene.page.Page; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.keycloak.authentication.requiredactions.DeleteCredentialAction; | ||
import org.keycloak.events.Details; | ||
import org.keycloak.events.Errors; | ||
import org.keycloak.events.EventType; | ||
import org.keycloak.events.email.EmailEventListenerProviderFactory; | ||
import org.keycloak.models.credential.OTPCredentialModel; | ||
import org.keycloak.models.credential.PasswordCredentialModel; | ||
import org.keycloak.models.utils.TimeBasedOTP; | ||
|
@@ -41,13 +45,19 @@ | |
import org.keycloak.testsuite.pages.ErrorPage; | ||
import org.keycloak.testsuite.pages.LoginConfigTotpPage; | ||
import org.keycloak.testsuite.pages.LoginTotpPage; | ||
import org.keycloak.testsuite.updaters.RealmAttributeUpdater; | ||
import org.keycloak.testsuite.util.GreenMailRule; | ||
import org.keycloak.testsuite.util.MailUtils; | ||
import org.keycloak.testsuite.util.UserBuilder; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Marek Posolda</a> | ||
*/ | ||
public class AppInitiatedActionDeleteCredentialTest extends AbstractAppInitiatedActionTest { | ||
|
||
@Rule | ||
public GreenMailRule greenMail = new GreenMailRule(); | ||
|
||
@Override | ||
protected String getAiaAction() { | ||
return DeleteCredentialAction.PROVIDER_ID; | ||
|
@@ -76,9 +86,11 @@ public void configureTestRealm(RealmRepresentation testRealm) { | |
|
||
@Before | ||
public void beforeTest() { | ||
ApiUtil.removeUserByUsername(testRealm(), "test-user@localhost"); | ||
UserRepresentation user = UserBuilder.create() | ||
.username("john") | ||
.email("[email protected]") | ||
.email("test-user@localhost") | ||
.emailVerified(true) | ||
.firstName("John") | ||
.lastName("Bar") | ||
.enabled(true) | ||
|
@@ -92,33 +104,48 @@ public void beforeTest() { | |
|
||
@Test | ||
public void removeOtpSuccess() throws Exception { | ||
String credentialId = getCredentialIdByType(OTPCredentialModel.TYPE); | ||
oauth.kcAction(getKcActionParamForDeleteCredential(credentialId)); | ||
|
||
loginPasswordAndOtp(); | ||
|
||
deleteCredentialPage.assertCurrent(); | ||
deleteCredentialPage.assertCredentialInMessage(OTPCredentialModel.TYPE); | ||
|
||
deleteCredentialPage.confirm(); | ||
|
||
appPage.assertCurrent(); | ||
assertKcActionStatus("success"); | ||
|
||
Assert.assertNull(getCredentialIdByType(OTPCredentialModel.TYPE)); | ||
|
||
events.expect(EventType.REMOVE_TOTP) | ||
.user(userId) | ||
.detail(Details.CREDENTIAL_TYPE, OTPCredentialModel.TYPE) | ||
.detail(Details.CREDENTIAL_ID, credentialId) | ||
.detail(Details.CUSTOM_REQUIRED_ACTION, DeleteCredentialAction.PROVIDER_ID) | ||
.assertEvent(); | ||
events.expect(EventType.REMOVE_CREDENTIAL) | ||
.user(userId) | ||
.detail(Details.CREDENTIAL_TYPE, OTPCredentialModel.TYPE) | ||
.detail(Details.CREDENTIAL_ID, credentialId) | ||
.detail(Details.CUSTOM_REQUIRED_ACTION, DeleteCredentialAction.PROVIDER_ID) | ||
.assertEvent(); | ||
try (RealmAttributeUpdater updater = new RealmAttributeUpdater(testRealm()) | ||
.addEventsListener(EmailEventListenerProviderFactory.ID) | ||
.update()) { | ||
|
||
String credentialId = getCredentialIdByType(OTPCredentialModel.TYPE); | ||
oauth.kcAction(getKcActionParamForDeleteCredential(credentialId)); | ||
|
||
loginPasswordAndOtp(); | ||
|
||
deleteCredentialPage.assertCurrent(); | ||
deleteCredentialPage.assertCredentialInMessage(OTPCredentialModel.TYPE); | ||
|
||
deleteCredentialPage.confirm(); | ||
|
||
appPage.assertCurrent(); | ||
assertKcActionStatus("success"); | ||
|
||
Assert.assertNull(getCredentialIdByType(OTPCredentialModel.TYPE)); | ||
|
||
events.expect(EventType.REMOVE_TOTP) | ||
.user(userId) | ||
.detail(Details.CREDENTIAL_TYPE, OTPCredentialModel.TYPE) | ||
.detail(Details.CREDENTIAL_ID, credentialId) | ||
.detail(Details.CUSTOM_REQUIRED_ACTION, DeleteCredentialAction.PROVIDER_ID) | ||
.assertEvent(); | ||
events.expect(EventType.REMOVE_CREDENTIAL) | ||
.user(userId) | ||
.detail(Details.CREDENTIAL_TYPE, OTPCredentialModel.TYPE) | ||
.detail(Details.CREDENTIAL_ID, credentialId) | ||
.detail(Details.CUSTOM_REQUIRED_ACTION, DeleteCredentialAction.PROVIDER_ID) | ||
.assertEvent(); | ||
|
||
MimeMessage[] receivedMessages = greenMail.getReceivedMessages(); | ||
Assert.assertEquals(2, receivedMessages.length); | ||
|
||
Assert.assertEquals("Remove OTP", receivedMessages[0].getSubject()); | ||
Assert.assertEquals("Remove credential", receivedMessages[1].getSubject()); | ||
MatcherAssert.assertThat(MailUtils.getBody(receivedMessages[1]).getText(), | ||
Matchers.startsWith("Credential otp was removed from your account")); | ||
MatcherAssert.assertThat(MailUtils.getBody(receivedMessages[1]).getHtml(), | ||
Matchers.containsString("Credential otp was removed from your account")); | ||
} | ||
} | ||
|
||
@Test | ||
|
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
2 changes: 1 addition & 1 deletion
2
themes/src/main/resources/theme/base/email/html/event-remove_credential.ftl
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("eventRemoveCredentialBodyHtml", event.details.credential_type!"unknown", event.date, event.ipAddress))?no_esc} | ||
${kcSanitize(msg("eventRemoveCredentialBodyHtml", event.getDetail("credential_type")!"unknown", event.date, event.ipAddress))?no_esc} | ||
</@layout.emailLayout> |
2 changes: 1 addition & 1 deletion
2
themes/src/main/resources/theme/base/email/html/event-update_credential.ftl
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("eventUpdateCredentialBodyHtml", event.details.credential_type!"unknown", event.date, event.ipAddress))?no_esc} | ||
${kcSanitize(msg("eventUpdateCredentialBodyHtml", event.getDetail("credential_type")!"unknown", event.date, event.ipAddress))?no_esc} | ||
</@layout.emailLayout> |
2 changes: 1 addition & 1 deletion
2
themes/src/main/resources/theme/base/email/text/event-remove_credential.ftl
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"> | ||
${msg("eventRemoveCredentialBody", event.details.credential_type!"unknown", event.date, event.ipAddress)} | ||
${msg("eventRemoveCredentialBody", event.getDetail("credential_type")!"unknown", event.date, event.ipAddress)} |
2 changes: 1 addition & 1 deletion
2
themes/src/main/resources/theme/base/email/text/event-update_credential.ftl
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"> | ||
${msg("eventUpdateCredentialBody", event.details.credential_type!"unknown", event.date, event.ipAddress)} | ||
${msg("eventUpdateCredentialBody", event.getDetail("credential_type")!"unknown", event.date, event.ipAddress)} |