check if email is null
This commit is contained in:
parent
25daf5c45e
commit
3be74cda30
3 changed files with 44 additions and 2 deletions
|
@ -41,4 +41,5 @@ public interface Errors {
|
||||||
String USER_SESSION_NOT_FOUND = "user_session_not_found";
|
String USER_SESSION_NOT_FOUND = "user_session_not_found";
|
||||||
|
|
||||||
String EMAIL_SEND_FAILED = "email_send_failed";
|
String EMAIL_SEND_FAILED = "email_send_failed";
|
||||||
|
String INVALID_EMAIL = "invalid_email";
|
||||||
}
|
}
|
||||||
|
|
|
@ -826,7 +826,10 @@ public class LoginActionsService {
|
||||||
event.error(Errors.USER_NOT_FOUND);
|
event.error(Errors.USER_NOT_FOUND);
|
||||||
} else if(!user.isEnabled()) {
|
} else if(!user.isEnabled()) {
|
||||||
event.user(user).error(Errors.USER_DISABLED);
|
event.user(user).error(Errors.USER_DISABLED);
|
||||||
} else {
|
}
|
||||||
|
else if(user.getEmail() == null || user.getEmail().trim().length() == 0) {
|
||||||
|
event.user(user).error(Errors.INVALID_EMAIL);
|
||||||
|
} else{
|
||||||
event.user(user);
|
event.user(user);
|
||||||
|
|
||||||
UserSessionModel userSession = session.sessions().createUserSession(realm, user, username, clientConnection.getRemoteAddr(), "form", false);
|
UserSessionModel userSession = session.sessions().createUserSession(realm, user, username, clientConnection.getRemoteAddr(), "form", false);
|
||||||
|
|
|
@ -271,6 +271,44 @@ public class ResetPasswordTest {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
loginPage.open();
|
||||||
|
loginPage.resetPassword();
|
||||||
|
|
||||||
|
resetPasswordPage.assertCurrent();
|
||||||
|
|
||||||
|
resetPasswordPage.changePassword("login-test");
|
||||||
|
|
||||||
|
resetPasswordPage.assertCurrent();
|
||||||
|
|
||||||
|
Assert.assertEquals("You should receive an email shortly with further instructions.", resetPasswordPage.getSuccessMessage());
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, greenMail.getReceivedMessages().length);
|
||||||
|
|
||||||
|
events.expectRequiredAction(EventType.SEND_RESET_PASSWORD_ERROR).session((String) null).user(userId).detail(Details.USERNAME, "login-test").removeDetail(Details.CODE_ID).error("invalid_email").assertEvent();
|
||||||
|
} finally {
|
||||||
|
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||||
|
@Override
|
||||||
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
|
session.users().getUserByUsername("login-test", appRealm).setEmail(email[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void resetPasswordWrongSmtp() throws IOException, MessagingException, InterruptedException {
|
||||||
|
final String[] host = new String[1];
|
||||||
|
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||||
|
@Override
|
||||||
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
|
host[0] = appRealm.getSmtpConfig().get("host");
|
||||||
|
appRealm.getSmtpConfig().put("host", "invalid_host");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loginPage.open();
|
loginPage.open();
|
||||||
loginPage.resetPassword();
|
loginPage.resetPassword();
|
||||||
|
@ -292,7 +330,7 @@ public class ResetPasswordTest {
|
||||||
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
keycloakRule.configure(new KeycloakRule.KeycloakSetup() {
|
||||||
@Override
|
@Override
|
||||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||||
session.users().getUserByUsername("login-test", appRealm).setEmail(email[0]);
|
appRealm.getSmtpConfig().put("host",host[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue