diff --git a/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java b/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java index d367991..5c4cb24 100644 --- a/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java +++ b/src/main/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCode.java @@ -71,7 +71,7 @@ private static void createFormChallenge(RequiredActionContext context, FormMessa loginFormsProvider = loginFormsProvider.addError(new FormMessage(EMAIL_CODE, INVALID_CODE)); } Response challenge = loginFormsProvider - .setAttribute("user", new ProfileBean(context.getUser())) + .setAttribute("user", new ProfileBean(context.getUser(), context.getSession())) .createForm(LOGIN_VERIFY_EMAIL_CODE_TEMPLATE); context.challenge(challenge); } @@ -182,7 +182,6 @@ private void sendVerifyEmailAndCreateForm(RequiredActionContext context) throws @Override public String getDisplayText() { - logger.info("Retrieved display text for VerifyEmailByCode"); return "Verify Email by code"; } diff --git a/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java b/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java index 3f8c515..a59d352 100644 --- a/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java +++ b/src/test/java/fr/redfroggy/keycloak/requiredactions/VerifyEmailByCodeTest.java @@ -21,6 +21,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.sessions.AuthenticationSessionModel; +import org.keycloak.userprofile.UserProfileProvider; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -38,6 +39,8 @@ class VerifyEmailByCodeTest { @Mock private UserModel user; @Mock + private UserProfileProvider provider; + @Mock private KeycloakSession session; @Mock private EventBuilder event; @@ -167,7 +170,7 @@ public void shouldGenerateCodeWithSixDigits() { private void mockChallenge() { when(requiredActionContext.getUser()).thenReturn(user); when(user.getEmail()).thenReturn("keycloak@redfroggy.fr"); - + when(session.getProvider(UserProfileProvider.class)).thenReturn(provider); when(requiredActionContext.getSession()).thenReturn(session); when(requiredActionContext.getEvent()).thenReturn(event); @@ -235,6 +238,8 @@ public void shouldChallengeOnProcessActionWhenCodeIsNull() throws EmailException public void shouldChallengeWithErrorOnProcessActionWhenCodeIsNotValid() { initAction(); when(requiredActionContext.getUser()).thenReturn(user); + when(session.getProvider(UserProfileProvider.class)).thenReturn(provider); + when(requiredActionContext.getSession()).thenReturn(session); when(user.getEmail()).thenReturn("keycloak@redfroggy.fr"); when(requiredActionContext.getEvent()).thenReturn(event); @@ -243,6 +248,7 @@ public void shouldChallengeWithErrorOnProcessActionWhenCodeIsNotValid() { when(event.detail(Details.EMAIL, user.getEmail())).thenReturn(event); when(requiredActionContext.getAuthenticationSession()).thenReturn(authSession); + when(authSession.getAuthNote(VerifyEmailByCode.VERIFY_EMAIL_CODE)).thenReturn("code is valid"); HttpRequest request = mock(HttpRequest.class);