Search in sources :

Example 6 with LoginPage

use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.

the class LoginTest method testRedirectPreservesPOSTParameters.

@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 testRedirectPreservesPOSTParameters() {
    String test = "Test string " + System.currentTimeMillis();
    final String space = "Main";
    final String page = "POSTTest";
    LoginPage loginPage = this.vp.login();
    loginPage.loginAsAdmin();
    // start editing a page
    WikiEditPage editPage = WikiEditPage.gotoPage(space, page);
    editPage.setTitle(test);
    editPage.setContent(test);
    // emulate expired session: delete the cookies
    getDriver().manage().deleteAllCookies();
    // try to save
    editPage.clickSaveAndView();
    // we should have been redirected to login
    String wantUrl = getUtil().getURL("XWiki", "XWikiLogin", "login");
    if (wantUrl.indexOf('?') > 0) {
        // strip parameters
        wantUrl = wantUrl.substring(0, wantUrl.indexOf('?'));
    }
    Assert.assertTrue(getDriver().getCurrentUrl().startsWith(wantUrl));
    loginPage.loginAsAdmin();
    // we should have been redirected back to view, and the page should have been saved
    Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL(space, page)));
    editPage = WikiEditPage.gotoPage(space, page);
    Assert.assertEquals(test, editPage.getTitle());
    Assert.assertEquals(test, editPage.getContent());
}
Also used : WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) LoginPage(org.xwiki.test.ui.po.LoginPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Example 7 with LoginPage

use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.

the class LoginTest method testLoginWithInvalidCredentials.

@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 testLoginWithInvalidCredentials() {
    LoginPage loginPage = this.vp.login();
    loginPage.loginAs("Admin", "wrong password");
    Assert.assertTrue(loginPage.hasInvalidCredentialsErrorMessage());
}
Also used : LoginPage(org.xwiki.test.ui.po.LoginPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Example 8 with LoginPage

use of org.xwiki.test.ui.po.LoginPage in project xwiki-platform by xwiki.

the class LoginTest method testRedirectBackAfterLogin.

/**
 * Verify that the initial URL is not lost after logging in when the session has expired.
 * See XWIKI-5317.
 */
@Test
public void testRedirectBackAfterLogin() {
    try {
        // Test setup: disallow view right for unauthenticated users. We need to be logged as admin in order to
        // do that. Since this is not what we are testing use the fast way to log in
        GlobalRightsAdministrationSectionPage grasp = new GlobalRightsAdministrationSectionPage();
        getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL()));
        getUtil().recacheSecretToken();
        getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS);
        grasp.forceAuthenticatedView();
        // Go to a page, log out and expire session by removing cookies, log in again and verify that the user is
        // redirected to the initial page.
        ViewPage page = getUtil().gotoPage("SomeSpace", "SomePage");
        page.logout();
        // Since view is disallowed for unauthenticated users, at this point we see a log in page.
        LoginPage loginPage = new LoginPage();
        // Remove all cookie to simulate a session expiry
        getDriver().manage().deleteAllCookies();
        loginPage.loginAsAdmin();
        // We use startsWith since the URL contains a jsessionid and a srid.
        Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL("SomeSpace", "SomePage")));
    } finally {
        GlobalRightsAdministrationSectionPage grasp = GlobalRightsAdministrationSectionPage.gotoPage();
        if (!grasp.isAuthenticated()) {
            getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL()));
        }
        grasp.unforceAuthenticatedView();
    }
}
Also used : GlobalRightsAdministrationSectionPage(org.xwiki.administration.test.po.GlobalRightsAdministrationSectionPage) ViewPage(org.xwiki.test.ui.po.ViewPage) LoginPage(org.xwiki.test.ui.po.LoginPage) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 LoginPage (org.xwiki.test.ui.po.LoginPage)8 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)6 ViewPage (org.xwiki.test.ui.po.ViewPage)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 MimeMessage (javax.mail.internet.MimeMessage)1 GlobalRightsAdministrationSectionPage (org.xwiki.administration.test.po.GlobalRightsAdministrationSectionPage)1 ResetPasswordCompletePage (org.xwiki.administration.test.po.ResetPasswordCompletePage)1 ResetPasswordPage (org.xwiki.administration.test.po.ResetPasswordPage)1 AbstractTest (org.xwiki.test.ui.AbstractTest)1 ResubmissionPage (org.xwiki.test.ui.po.ResubmissionPage)1 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)1