use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.
the class ResetPasswordIT method resetForgottenPassword.
@Test
public void resetForgottenPassword() throws Exception {
String userName = "testUser" + RandomStringUtils.randomAlphanumeric(6);
String password = "password";
String newPassword = "newPassword";
// Create a user
getUtil().createUser(userName, password, null);
// Make sure we are not logged in and go to the reset password page
getUtil().forceGuestUser();
ResetPasswordPage resetPasswordPage = ResetPasswordPage.gotoPage();
// Try to reset the password of a non existent user
resetPasswordPage.setUserName("SomeUserThatDoesNotExist");
resetPasswordPage.clickResetPassword();
Assert.assertFalse(resetPasswordPage.isResetPasswordSent());
Assert.assertTrue(resetPasswordPage.getMessage().contains("user does not exist"));
// Try again
resetPasswordPage = resetPasswordPage.clickRetry();
// Try to reset the password of our user, when he has no email set
resetPasswordPage.setUserName(userName);
resetPasswordPage.clickResetPassword();
Assert.assertFalse(resetPasswordPage.isResetPasswordSent());
Assert.assertTrue(resetPasswordPage.getMessage().contains("email address not provided"));
// Try again. This time, set the user's email address in the profile
getUtil().loginAsSuperAdmin();
getUtil().updateObject("XWiki", userName, "XWiki.XWikiUsers", 0, "email", "foo@bar.com", "form_token", getUtil().getSecretToken());
getUtil().forceGuestUser();
// Actually reset the user's password
resetPasswordPage = ResetPasswordPage.gotoPage();
resetPasswordPage.setUserName(userName);
resetPasswordPage.clickResetPassword();
// Check the result
Assert.assertTrue(resetPasswordPage.isResetPasswordSent());
// Check the emails received by the user
MimeMessage[] receivedEmails = this.mail.getReceivedMessages();
Assert.assertEquals(1, receivedEmails.length);
MimeMessage receivedEmail = receivedEmails[0];
Assert.assertEquals("Password reset request for " + userName, receivedEmail.getSubject());
String receivedMailContent = getMessageContent(receivedEmail).get("textPart");
String passwordResetLink = getResetLink(receivedMailContent, userName);
Assert.assertNotNull(passwordResetLink);
// Use the password reset link
getUtil().gotoPage(passwordResetLink);
// We should now be on the ResetPasswordComplete page
ResetPasswordCompletePage resetPasswordCompletePage = new ResetPasswordCompletePage();
// Check that the link was valid
Assert.assertTrue(resetPasswordCompletePage.isResetLinkValid());
resetPasswordCompletePage.setPassword(newPassword);
resetPasswordCompletePage.setPasswordConfirmation(newPassword);
resetPasswordCompletePage = resetPasswordCompletePage.clickSave();
// Check the result
Assert.assertTrue(resetPasswordCompletePage.isPasswordSuccessfullyReset());
LoginPage loginPage = resetPasswordCompletePage.clickLogin();
// Check the new password
loginPage.loginAs(userName, newPassword);
Assert.assertEquals(userName, getUtil().getLoggedInUserName());
}
use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.
the class LoginTest method testLoginWithInvalidUsername.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testLoginWithInvalidUsername() {
LoginPage loginPage = this.vp.login();
loginPage.loginAs("non existent user", "admin");
Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage());
}
use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.
the class LoginTest method testDataIsPreservedAfterLogin.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testDataIsPreservedAfterLogin() {
getUtil().gotoPage("Test", "TestData", "save", "content=this+should+not+be+saved");
getUtil().gotoPage("Test", "TestData", "save", "content=this+should+be+saved+instead&parent=Main.WebHome");
LoginPage loginPage = new LoginPage();
loginPage.loginAsAdmin();
// we switched to another user, CSRF protection (if enabled) will ask for confirmation
ResubmissionPage resubmissionPage = new ResubmissionPage();
if (resubmissionPage.isOnResubmissionPage()) {
resubmissionPage.resubmit();
}
Assert.assertTrue(getDriver().getCurrentUrl().contains("/xwiki/bin/view/Test/TestData"));
ViewPage viewPage = new ViewPage();
Assert.assertEquals("this should be saved instead", viewPage.getContent());
}
use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.
the class LoginTest method testLoginLogoutAsAdmin.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testLoginLogoutAsAdmin() {
LoginPage loginPage = this.vp.login();
loginPage.loginAsAdmin();
// Verify that after logging in we're redirected to the page on which the login button was clicked, i.e. the
// non existent page here.
Assert.assertEquals(this.nonExistentPageURL, getDriver().getCurrentUrl());
Assert.assertTrue(this.vp.isAuthenticated());
Assert.assertEquals("Administrator", this.vp.getCurrentUser());
// Test Logout and verify we stay on the same page
this.vp.logout();
Assert.assertFalse(this.vp.isAuthenticated());
Assert.assertEquals(this.nonExistentPageURL, getDriver().getCurrentUrl());
}
use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.
the class LoginTest method testCorrectUrlIsAccessedAfterLogin.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testCorrectUrlIsAccessedAfterLogin() {
// We will choose the Scheduler.WebHome page to make our testing
// since it can't be viewed without being logged in
getUtil().gotoPage("Scheduler", "WebHome");
LoginPage loginPage = new LoginPage();
Assert.assertFalse(loginPage.isAuthenticated());
loginPage.loginAsAdmin();
// We should be redirected back to Scheduler.WebHome
Assert.assertTrue(getDriver().getCurrentUrl().contains("/xwiki/bin/view/Scheduler/WebHome"));
Assert.assertTrue(getDriver().getTitle().contains("Job Scheduler"));
}
Aggregations