KEYCLOAK-1731 - patched user attribute handling for

login-update-profile.ftl form. Relevant tests added. Tests for user
attributes handling from register.ftl also added.
This commit is contained in:
Vlastimil Elias 2015-08-05 17:07:21 +02:00
parent a46a7a42a1
commit 2e52d8ea7a
15 changed files with 235 additions and 42 deletions

View file

@ -33,6 +33,53 @@
</div> </div>
</div> </div>
<div class="form-group">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.street" class="${properties.kcLabelClass!}">${msg("street")}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.street" name="user.attributes.street" value="${(user.attributes.street!'')?html}"/>
</div>
</div>
<div class="form-group">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.locality" class="${properties.kcLabelClass!}">${msg("locality")}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.locality" name="user.attributes.locality" value="${(user.attributes.locality!'')?html}"/>
</div>
</div>
<div class="form-group">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.region" class="${properties.kcLabelClass!}">${msg("region")}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.region" name="user.attributes.region" value="${(user.attributes.region!'')?html}"/>
</div>
</div>
<div class="form-group">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.postal_code" class="${properties.kcLabelClass!}">${msg("postal_code")}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.postal_code" name="user.attributes.postal_code" value="${(user.attributes.postal_code!'')?html}"/>
</div>
</div>
<div class="form-group">
<div class="${properties.kcLabelWrapperClass!}">
<label for="user.attributes.country" class="${properties.kcLabelClass!}">${msg("country")}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.country" name="user.attributes.country" value="${(user.attributes.country!'')?html}"/>
</div>
</div>
<div class="${properties.kcFormGroupClass!}"> <div class="${properties.kcFormGroupClass!}">
<div id="kc-form-options" class="${properties.kcFormOptionsClass!}"> <div id="kc-form-options" class="${properties.kcFormOptionsClass!}">
<div class="${properties.kcFormOptionsWrapperClass!}"> <div class="${properties.kcFormOptionsWrapperClass!}">

View file

@ -68,7 +68,7 @@
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.street" name="user.attributes.street"/> <input type="text" class="${properties.kcInputClass!}" id="user.attributes.street" name="user.attributes.street" value="${(register.formData['user.attributes.street']!'')?html}"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -77,7 +77,7 @@
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.locality" name="user.attributes.locality"/> <input type="text" class="${properties.kcInputClass!}" id="user.attributes.locality" name="user.attributes.locality" value="${(register.formData['user.attributes.locality']!'')?html}"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -86,7 +86,7 @@
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.region" name="user.attributes.region"/> <input type="text" class="${properties.kcInputClass!}" id="user.attributes.region" name="user.attributes.region" value="${(register.formData['user.attributes.region']!'')?html}"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -95,7 +95,7 @@
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.postal_code" name="user.attributes.postal_code"/> <input type="text" class="${properties.kcInputClass!}" id="user.attributes.postal_code" name="user.attributes.postal_code" value="${(register.formData['user.attributes.postal_code']!'')?html}"/>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -104,7 +104,7 @@
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcInputWrapperClass!}">
<input type="text" class="${properties.kcInputClass!}" id="user.attributes.country" name="user.attributes.country"/> <input type="text" class="${properties.kcInputClass!}" id="user.attributes.country" name="user.attributes.country" value="${(register.formData['user.attributes.country']!'')?html}"/>
</div> </div>
</div> </div>
<#if recaptchaRequired??> <#if recaptchaRequired??>

View file

@ -244,7 +244,7 @@ public class FreeMarkerLoginFormsProvider implements LoginFormsProvider {
attributes.put("totp", new TotpBean(realm, user, baseUri)); attributes.put("totp", new TotpBean(realm, user, baseUri));
break; break;
case LOGIN_UPDATE_PROFILE: case LOGIN_UPDATE_PROFILE:
attributes.put("user", new ProfileBean(user)); attributes.put("user", new ProfileBean(user, formData));
break; break;
case REGISTER: case REGISTER:
attributes.put("register", new RegisterBean(formData)); attributes.put("register", new RegisterBean(formData));

View file

@ -21,29 +21,68 @@
*/ */
package org.keycloak.login.freemarker.model; package org.keycloak.login.freemarker.model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.MultivaluedMap;
import org.jboss.logging.Logger;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
* @author Vlastimil Elias (velias at redhat dot com)
*/ */
public class ProfileBean { public class ProfileBean {
private UserModel user; private static final Logger logger = Logger.getLogger(ProfileBean.class);
public ProfileBean(UserModel user){ private UserModel user;
private MultivaluedMap<String, String> formData;
private final Map<String, String> attributes = new HashMap<>();
public ProfileBean(UserModel user, MultivaluedMap<String, String> formData) {
this.user = user; this.user = user;
this.formData = formData;
if (user.getAttributes() != null) {
for (Map.Entry<String, List<String>> attr : user.getAttributes().entrySet()) {
List<String> attrValue = attr.getValue();
if (attrValue != null && attrValue.size() > 0) {
attributes.put(attr.getKey(), attrValue.get(0));
}
if (attrValue != null && attrValue.size() > 1) {
logger.warnf("There are more values for attribute '%s' of user '%s' . Will display just first value", attr.getKey(), user.getUsername());
}
}
}
if (formData != null) {
for (String key : formData.keySet()) {
if (key.startsWith("user.attributes.")) {
String attribute = key.substring("user.attributes.".length());
attributes.put(attribute, formData.getFirst(key));
}
}
}
} }
public String getFirstName() { public String getFirstName() {
return user.getFirstName(); return formData != null ? formData.getFirst("firstName") : user.getFirstName();
} }
public String getLastName() { public String getLastName() {
return user.getLastName(); return formData != null ? formData.getFirst("lastName") : user.getLastName();
} }
public String getEmail() { public String getEmail() {
return user.getEmail(); return formData != null ? formData.getFirst("email") : user.getEmail();
} }
public Map<String, String> getAttributes() {
return attributes;
}
} }

View file

@ -499,6 +499,7 @@ public class LoginActionsService {
.setClientSessionCode(accessCode.getCode()) .setClientSessionCode(accessCode.getCode())
.setUser(user) .setUser(user)
.setErrors(errors) .setErrors(errors)
.setFormData(formData)
.createResponse(RequiredAction.UPDATE_PROFILE); .createResponse(RequiredAction.UPDATE_PROFILE);
} }
@ -519,6 +520,7 @@ public class LoginActionsService {
.setUser(user) .setUser(user)
.setError(Messages.EMAIL_EXISTS) .setError(Messages.EMAIL_EXISTS)
.setClientSessionCode(accessCode.getCode()) .setClientSessionCode(accessCode.getCode())
.setFormData(formData)
.createResponse(RequiredAction.UPDATE_PROFILE); .createResponse(RequiredAction.UPDATE_PROFILE);
} }

View file

@ -562,7 +562,7 @@ public class AccountTest {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("view", "log", "view-log@localhost", "view-log", "password", "password"); registerPage.register("view", "log", "view-log@localhost", "view-log", "password", "password", null);
expectedEvents.add(events.poll()); expectedEvents.add(events.poll());
expectedEvents.add(events.poll()); expectedEvents.add(events.poll());
@ -609,7 +609,7 @@ public class AccountTest {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("view", "sessions", "view-sessions@localhost", "view-sessions", "password", "password"); registerPage.register("view", "sessions", "view-sessions@localhost", "view-sessions", "password", "password", null);
Event registerEvent = events.expectRegister("view-sessions", "view-sessions@localhost").assertEvent(); Event registerEvent = events.expectRegister("view-sessions", "view-sessions@localhost").assertEvent();
String userId = registerEvent.getUserId(); String userId = registerEvent.getUserId();

View file

@ -145,7 +145,7 @@ public class RequiredActionEmailVerificationTest {
public void verifyEmailRegister() throws IOException, MessagingException { public void verifyEmailRegister() throws IOException, MessagingException {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("firstName", "lastName", "email@mail.com", "verifyEmail", "password", "password"); registerPage.register("firstName", "lastName", "email@mail.com", "verifyEmail", "password", "password", null);
String userId = events.expectRegister("verifyEmail", "email@mail.com").assertEvent().getUserId(); String userId = events.expectRegister("verifyEmail", "email@mail.com").assertEvent().getUserId();

View file

@ -121,7 +121,7 @@ public class RequiredActionMultipleActionsTest {
} }
public String updateProfile(String sessionId) { public String updateProfile(String sessionId) {
updateProfilePage.update("New first", "New last", "new@email.com"); updateProfilePage.update("New first", "New last", "new@email.com", null);
AssertEvents.ExpectedEvent expectedEvent = events.expectRequiredAction(EventType.UPDATE_PROFILE); AssertEvents.ExpectedEvent expectedEvent = events.expectRequiredAction(EventType.UPDATE_PROFILE);
if (sessionId != null) { if (sessionId != null) {

View file

@ -107,7 +107,7 @@ public class RequiredActionTotpSetupTest {
public void setupTotpRegister() { public void setupTotpRegister() {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("firstName", "lastName", "email@mail.com", "setupTotp", "password", "password"); registerPage.register("firstName", "lastName", "email@mail.com", "setupTotp", "password", "password", null);
String userId = events.expectRegister("setupTotp", "email@mail.com").assertEvent().getUserId(); String userId = events.expectRegister("setupTotp", "email@mail.com").assertEvent().getUserId();
@ -158,7 +158,7 @@ public class RequiredActionTotpSetupTest {
// Register new user // Register new user
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("firstName2", "lastName2", "email2@mail.com", "setupTotp2", "password2", "password2"); registerPage.register("firstName2", "lastName2", "email2@mail.com", "setupTotp2", "password2", "password2", null);
String userId = events.expectRegister("setupTotp2", "email2@mail.com").assertEvent().getUserId(); String userId = events.expectRegister("setupTotp2", "email2@mail.com").assertEvent().getUserId();

View file

@ -30,6 +30,7 @@ import org.keycloak.events.Details;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.pages.AppPage; import org.keycloak.testsuite.pages.AppPage;
@ -86,7 +87,7 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
updateProfilePage.update("New first", "New last", "new@email.com"); updateProfilePage.update("New first", "New last", "new@email.com", "mystreet");
String sessionId = events.expectRequiredAction(EventType.UPDATE_PROFILE).assertEvent().getSessionId(); String sessionId = events.expectRequiredAction(EventType.UPDATE_PROFILE).assertEvent().getSessionId();
events.expectRequiredAction(EventType.UPDATE_EMAIL).session(sessionId).detail(Details.PREVIOUS_EMAIL, "test-user@localhost").detail(Details.UPDATED_EMAIL, "new@email.com").assertEvent(); events.expectRequiredAction(EventType.UPDATE_EMAIL).session(sessionId).detail(Details.PREVIOUS_EMAIL, "test-user@localhost").detail(Details.UPDATED_EMAIL, "new@email.com").assertEvent();
@ -94,6 +95,13 @@ public class RequiredActionUpdateProfileTest {
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
events.expectLogin().session(sessionId).assertEvent(); events.expectLogin().session(sessionId).assertEvent();
// assert user is really updated in persistent store
UserRepresentation user = keycloakRule.getUser("test", "test-user@localhost");
Assert.assertEquals("New first", user.getFirstName());
Assert.assertEquals("New last", user.getLastName());
Assert.assertEquals("new@email.com", user.getEmail());
Assert.assertEquals("mystreet", user.getAttributesAsListValues().get("street").get(0));
} }
@Test @Test
@ -104,10 +112,16 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
updateProfilePage.update("", "New last", "new@email.com"); updateProfilePage.update("", "New last", "new@email.com", "mystreet");
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
// assert that form holds submitted values during validation error
Assert.assertEquals("", updateProfilePage.getFirstName());
Assert.assertEquals("New last", updateProfilePage.getLastName());
Assert.assertEquals("new@email.com", updateProfilePage.getEmail());
Assert.assertEquals("mystreet", updateProfilePage.getAttributeStreet());
Assert.assertEquals("Please specify first name.", updateProfilePage.getError()); Assert.assertEquals("Please specify first name.", updateProfilePage.getError());
events.assertEmpty(); events.assertEmpty();
@ -121,10 +135,16 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
updateProfilePage.update("New first", "", "new@email.com"); updateProfilePage.update("New first", "", "new@email.com", null);
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
// assert that form holds submitted values during validation error
Assert.assertEquals("New first", updateProfilePage.getFirstName());
Assert.assertEquals("", updateProfilePage.getLastName());
Assert.assertEquals("new@email.com", updateProfilePage.getEmail());
Assert.assertEquals("", updateProfilePage.getAttributeStreet());
Assert.assertEquals("Please specify last name.", updateProfilePage.getError()); Assert.assertEquals("Please specify last name.", updateProfilePage.getError());
events.assertEmpty(); events.assertEmpty();
@ -138,15 +158,44 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
updateProfilePage.update("New first", "New last", ""); updateProfilePage.update("New first", "New last", "", "mystreet");
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
// assert that form holds submitted values during validation error
Assert.assertEquals("New first", updateProfilePage.getFirstName());
Assert.assertEquals("New last", updateProfilePage.getLastName());
Assert.assertEquals("", updateProfilePage.getEmail());
Assert.assertEquals("mystreet", updateProfilePage.getAttributeStreet());
Assert.assertEquals("Please specify email.", updateProfilePage.getError()); Assert.assertEquals("Please specify email.", updateProfilePage.getError());
events.assertEmpty(); events.assertEmpty();
} }
@Test
public void updateProfileInvalidEmail() {
loginPage.open();
loginPage.login("test-user@localhost", "password");
updateProfilePage.assertCurrent();
updateProfilePage.update("New first", "New last", "invalidemail", null);
updateProfilePage.assertCurrent();
// assert that form holds submitted values during validation error
Assert.assertEquals("New first", updateProfilePage.getFirstName());
Assert.assertEquals("New last", updateProfilePage.getLastName());
Assert.assertEquals("invalidemail", updateProfilePage.getEmail());
Assert.assertEquals("", updateProfilePage.getAttributeStreet());
Assert.assertEquals("Invalid email address.", updateProfilePage.getError());
events.assertEmpty();
}
@Test @Test
public void updateProfileDuplicatedEmail() { public void updateProfileDuplicatedEmail() {
loginPage.open(); loginPage.open();
@ -155,10 +204,15 @@ public class RequiredActionUpdateProfileTest {
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
updateProfilePage.update("New first", "New last", "keycloak-user@localhost"); updateProfilePage.update("New first", "New last", "keycloak-user@localhost", null);
updateProfilePage.assertCurrent(); updateProfilePage.assertCurrent();
// assert that form holds submitted values during validation error
Assert.assertEquals("New first", updateProfilePage.getFirstName());
Assert.assertEquals("New last", updateProfilePage.getLastName());
Assert.assertEquals("keycloak-user@localhost", updateProfilePage.getEmail());
Assert.assertEquals("Email already exists.", updateProfilePage.getError()); Assert.assertEquals("Email already exists.", updateProfilePage.getError());
events.assertEmpty(); events.assertEmpty();

View file

@ -451,7 +451,7 @@ public abstract class AbstractIdentityProviderTest {
doAfterProviderAuthentication(); doAfterProviderAuthentication();
this.updateProfilePage.assertCurrent(); this.updateProfilePage.assertCurrent();
this.updateProfilePage.update("Test", "User", "psilva@redhat.com"); this.updateProfilePage.update("Test", "User", "psilva@redhat.com", null);
WebElement element = this.driver.findElement(By.className("kc-feedback-text")); WebElement element = this.driver.findElement(By.className("kc-feedback-text"));
@ -460,7 +460,7 @@ public abstract class AbstractIdentityProviderTest {
assertEquals("Email already exists.", element.getText()); assertEquals("Email already exists.", element.getText());
this.updateProfilePage.assertCurrent(); this.updateProfilePage.assertCurrent();
this.updateProfilePage.update("Test", "User", "test-user@redhat.com"); this.updateProfilePage.update("Test", "User", "test-user@redhat.com", null);
assertTrue(this.driver.getCurrentUrl().startsWith("http://localhost:8081/test-app")); assertTrue(this.driver.getCurrentUrl().startsWith("http://localhost:8081/test-app"));
@ -724,7 +724,7 @@ public abstract class AbstractIdentityProviderTest {
// update profile // update profile
this.updateProfilePage.assertCurrent(); this.updateProfilePage.assertCurrent();
this.updateProfilePage.update(userFirstName, userLastName, userEmail); this.updateProfilePage.update(userFirstName, userLastName, userEmail, null);
} }
} }

View file

@ -296,12 +296,12 @@ public class FederationProvidersIntegrationTest {
registerPage.assertCurrent(); registerPage.assertCurrent();
// check existing username // check existing username
registerPage.register("firstName", "lastName", "email@mail.cz", "existing", "Password1", "Password1"); registerPage.register("firstName", "lastName", "email@mail.cz", "existing", "Password1", "Password1", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Username already exists.", registerPage.getError()); Assert.assertEquals("Username already exists.", registerPage.getError());
// Check existing email // Check existing email
registerPage.register("firstName", "lastName", "existing@email.org", "nonExisting", "Password1", "Password1"); registerPage.register("firstName", "lastName", "existing@email.org", "nonExisting", "Password1", "Password1", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Email already exists.", registerPage.getError()); Assert.assertEquals("Email already exists.", registerPage.getError());
} }
@ -312,7 +312,7 @@ public class FederationProvidersIntegrationTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "email2@check.cz", "registerUserSuccess2", "Password1", "Password1"); registerPage.register("firstName", "lastName", "email2@check.cz", "registerUserSuccess2", "Password1", "Password1", null);
Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
KeycloakSession session = keycloakRule.startSession(); KeycloakSession session = keycloakRule.startSession();

View file

@ -30,11 +30,9 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.PasswordPolicy; import org.keycloak.models.PasswordPolicy;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.representations.IDToken;
import org.keycloak.services.managers.RealmManager; import org.keycloak.services.managers.RealmManager;
import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.OAuthClient; import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.broker.util.UserSessionStatusServlet.UserSessionStatus;
import org.keycloak.testsuite.pages.AppPage; import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType; import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.LoginPage;
@ -79,11 +77,20 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerExistingUser@email", "test-user@localhost", "password", "password"); registerPage.register("firstName", "lastName", "registerExistingUser@email", "test-user@localhost", "password", "password", "mystreet");
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Username already exists.", registerPage.getError()); Assert.assertEquals("Username already exists.", registerPage.getError());
// assert form keeps form fields on error
Assert.assertEquals("firstName", registerPage.getFirstName());
Assert.assertEquals("lastName", registerPage.getLastName());
Assert.assertEquals("", registerPage.getEmail());
Assert.assertEquals("", registerPage.getUsername());
Assert.assertEquals("", registerPage.getPassword());
Assert.assertEquals("", registerPage.getPasswordConfirm());
Assert.assertEquals("mystreet", registerPage.getAttributeStreet());
events.expectRegister("test-user@localhost", "registerExistingUser@email") events.expectRegister("test-user@localhost", "registerExistingUser@email")
.removeDetail(Details.EMAIL) .removeDetail(Details.EMAIL)
.user((String) null).error("username_in_use").assertEvent(); .user((String) null).error("username_in_use").assertEvent();
@ -95,11 +102,20 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerUserInvalidPasswordConfirm@email", "registerUserInvalidPasswordConfirm", "password", "invalid"); registerPage.register("firstName", "lastName", "registerUserInvalidPasswordConfirm@email", "registerUserInvalidPasswordConfirm", "password", "invalid", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Password confirmation doesn't match.", registerPage.getError()); Assert.assertEquals("Password confirmation doesn't match.", registerPage.getError());
// assert form keeps form fields on error
Assert.assertEquals("firstName", registerPage.getFirstName());
Assert.assertEquals("lastName", registerPage.getLastName());
Assert.assertEquals("registerUserInvalidPasswordConfirm@email", registerPage.getEmail());
Assert.assertEquals("registerUserInvalidPasswordConfirm", registerPage.getUsername());
Assert.assertEquals("", registerPage.getPassword());
Assert.assertEquals("", registerPage.getPasswordConfirm());
Assert.assertEquals("", registerPage.getAttributeStreet());
events.expectRegister("registerUserInvalidPasswordConfirm", "registerUserInvalidPasswordConfirm@email") events.expectRegister("registerUserInvalidPasswordConfirm", "registerUserInvalidPasswordConfirm@email")
.removeDetail(Details.USERNAME) .removeDetail(Details.USERNAME)
.removeDetail(Details.EMAIL) .removeDetail(Details.EMAIL)
@ -112,7 +128,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerUserMissingPassword@email", "registerUserMissingPassword", null, null); registerPage.register("firstName", "lastName", "registerUserMissingPassword@email", "registerUserMissingPassword", null, null, null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Please specify password.", registerPage.getError()); Assert.assertEquals("Please specify password.", registerPage.getError());
@ -137,7 +153,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerPasswordPolicy@email", "registerPasswordPolicy", "pass", "pass"); registerPage.register("firstName", "lastName", "registerPasswordPolicy@email", "registerPasswordPolicy", "pass", "pass", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Invalid password: minimum length 8.", registerPage.getError()); Assert.assertEquals("Invalid password: minimum length 8.", registerPage.getError());
@ -147,7 +163,7 @@ public class RegisterTest {
.removeDetail(Details.EMAIL) .removeDetail(Details.EMAIL)
.user((String) null).error("invalid_registration").assertEvent(); .user((String) null).error("invalid_registration").assertEvent();
registerPage.register("firstName", "lastName", "registerPasswordPolicy@email", "registerPasswordPolicy", "password", "password"); registerPage.register("firstName", "lastName", "registerPasswordPolicy@email", "registerPasswordPolicy", "password", "password", null);
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
String userId = events.expectRegister("registerPasswordPolicy", "registerPasswordPolicy@email").assertEvent().getUserId(); String userId = events.expectRegister("registerPasswordPolicy", "registerPasswordPolicy@email").assertEvent().getUserId();
@ -169,7 +185,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerUserMissingUsername@email", null, "password", "password"); registerPage.register("firstName", "lastName", "registerUserMissingUsername@email", null, "password", "password", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Please specify username.", registerPage.getError()); Assert.assertEquals("Please specify username.", registerPage.getError());
@ -186,14 +202,14 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", null, "registerUserMissingEmail", "password", "password"); registerPage.register("firstName", "lastName", null, "registerUserMissingEmail", "password", "password", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Please specify email.", registerPage.getError()); Assert.assertEquals("Please specify email.", registerPage.getError());
events.expectRegister("registerUserMissingEmail", null) events.expectRegister("registerUserMissingEmail", null)
.removeDetail("email") .removeDetail("email")
.error("invalid_registration").assertEvent(); .error("invalid_registration").assertEvent();
registerPage.register("firstName", "lastName", "registerUserInvalidEmailemail", "registerUserInvalidEmail", "password", "password"); registerPage.register("firstName", "lastName", "registerUserInvalidEmailemail", "registerUserInvalidEmail", "password", "password", null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Invalid email address.", registerPage.getError()); Assert.assertEquals("Invalid email address.", registerPage.getError());
events.expectRegister("registerUserInvalidEmail", "registerUserInvalidEmailemail") events.expectRegister("registerUserInvalidEmail", "registerUserInvalidEmailemail")
@ -206,7 +222,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("firstName", "lastName", "registerUserSuccess@email", "registerUserSuccess", "password", "password"); registerPage.register("firstName", "lastName", "registerUserSuccess@email", "registerUserSuccess", "password", "password", "myStreet");
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
@ -218,6 +234,12 @@ public class RegisterTest {
Assert.assertNotNull(user.getCreatedTimestamp()); Assert.assertNotNull(user.getCreatedTimestamp());
// test that timestamp is current with 10s tollerance // test that timestamp is current with 10s tollerance
Assert.assertTrue((System.currentTimeMillis() - user.getCreatedTimestamp()) < 10000); Assert.assertTrue((System.currentTimeMillis() - user.getCreatedTimestamp()) < 10000);
// test user info is set from form
Assert.assertEquals("registerusersuccess", user.getUsername());
Assert.assertEquals("registerusersuccess@email", user.getEmail());
Assert.assertEquals("firstName", user.getFirstName());
Assert.assertEquals("lastName", user.getLastName());
Assert.assertEquals("myStreet", user.getAttribute("street").get(0));
} }
protected UserModel getUser(String userId) { protected UserModel getUser(String userId) {

View file

@ -38,20 +38,25 @@ public class LoginUpdateProfilePage extends AbstractPage {
@FindBy(id = "email") @FindBy(id = "email")
private WebElement emailInput; private WebElement emailInput;
@FindBy(id = "user.attributes.street")
private WebElement attributeStreetInput;
@FindBy(css = "input[type=\"submit\"]") @FindBy(css = "input[type=\"submit\"]")
private WebElement submitButton; private WebElement submitButton;
@FindBy(className = "feedback-error") @FindBy(className = "feedback-error")
private WebElement loginErrorMessage; private WebElement loginErrorMessage;
public void update(String firstName, String lastName, String email) { public void update(String firstName, String lastName, String email, String attributeStreet) {
firstNameInput.clear(); firstNameInput.clear();
firstNameInput.sendKeys(firstName); firstNameInput.sendKeys(firstName);
lastNameInput.clear(); lastNameInput.clear();
lastNameInput.sendKeys(lastName); lastNameInput.sendKeys(lastName);
emailInput.clear(); emailInput.clear();
emailInput.sendKeys(email); emailInput.sendKeys(email);
attributeStreetInput.clear();
if (attributeStreet != null)
attributeStreetInput.sendKeys(attributeStreet);
submitButton.click(); submitButton.click();
} }
@ -71,6 +76,10 @@ public class LoginUpdateProfilePage extends AbstractPage {
return emailInput.getAttribute("value"); return emailInput.getAttribute("value");
} }
public String getAttributeStreet() {
return attributeStreetInput.getAttribute("value");
}
public boolean isCurrent() { public boolean isCurrent() {
return driver.getTitle().equals("Update Account Information"); return driver.getTitle().equals("Update Account Information");
} }

View file

@ -51,13 +51,16 @@ public class RegisterPage extends AbstractPage {
@FindBy(id = "password-confirm") @FindBy(id = "password-confirm")
private WebElement passwordConfirmInput; private WebElement passwordConfirmInput;
@FindBy(id = "user.attributes.street")
private WebElement attributeStreetInput;
@FindBy(css = "input[type=\"submit\"]") @FindBy(css = "input[type=\"submit\"]")
private WebElement submitButton; private WebElement submitButton;
@FindBy(className = "feedback-error") @FindBy(className = "feedback-error")
private WebElement loginErrorMessage; private WebElement loginErrorMessage;
public void register(String firstName, String lastName, String email, String username, String password, String passwordConfirm) { public void register(String firstName, String lastName, String email, String username, String password, String passwordConfirm, String attributeStreet) {
firstNameInput.clear(); firstNameInput.clear();
if (firstName != null) { if (firstName != null) {
firstNameInput.sendKeys(firstName); firstNameInput.sendKeys(firstName);
@ -88,6 +91,11 @@ public class RegisterPage extends AbstractPage {
passwordConfirmInput.sendKeys(passwordConfirm); passwordConfirmInput.sendKeys(passwordConfirm);
} }
attributeStreetInput.clear();
if (attributeStreet != null) {
attributeStreetInput.sendKeys(attributeStreet);
}
submitButton.click(); submitButton.click();
} }
@ -147,6 +155,18 @@ public class RegisterPage extends AbstractPage {
return usernameInput.getAttribute("value"); return usernameInput.getAttribute("value");
} }
public String getPassword() {
return passwordInput.getAttribute("value");
}
public String getPasswordConfirm() {
return passwordConfirmInput.getAttribute("value");
}
public String getAttributeStreet() {
return attributeStreetInput.getAttribute("value");
}
public boolean isCurrent() { public boolean isCurrent() {
return driver.getTitle().equals("Register with test"); return driver.getTitle().equals("Register with test");
} }