Skip to content

Commit

Permalink
Update: code
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius Spakovskij committed Apr 4, 2024
1 parent fec25f1 commit e645441
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +39,8 @@ class VerifyEmailByCodeTest {
@Mock
private UserModel user;
@Mock
private UserProfileProvider provider;
@Mock
private KeycloakSession session;
@Mock
private EventBuilder event;
Expand Down Expand Up @@ -167,7 +170,7 @@ public void shouldGenerateCodeWithSixDigits() {
private void mockChallenge() {
when(requiredActionContext.getUser()).thenReturn(user);
when(user.getEmail()).thenReturn("[email protected]");

when(session.getProvider(UserProfileProvider.class)).thenReturn(provider);
when(requiredActionContext.getSession()).thenReturn(session);

when(requiredActionContext.getEvent()).thenReturn(event);
Expand Down Expand Up @@ -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("[email protected]");

when(requiredActionContext.getEvent()).thenReturn(event);
Expand All @@ -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);
Expand Down

0 comments on commit e645441

Please sign in to comment.