Search in sources :

Example 66 with Cookie

use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.

the class BaseTest method waitForResourceOwnerAndGrantLoginForm.

/**
 * Try to open login form (via the user-agent)
 */
public String waitForResourceOwnerAndGrantLoginForm(String authorizeUrl, AuthorizationRequest authorizationRequest, boolean cleanupCookies) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("waitForResourceOwnerAndGrantLoginForm: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    if (cleanupCookies) {
        System.out.println("waitForResourceOwnerAndGrantLoginForm: Cleaning cookies");
        deleteAllCookies();
    }
    navigateToAuhorizationUrl(driver, authorizationRequestUrl);
    WebElement usernameElement = driver.findElement(By.id(loginFormUsername));
    WebElement passwordElement = driver.findElement(By.id(loginFormPassword));
    WebElement loginButton = driver.findElement(By.id(loginFormLoginButton));
    if ((usernameElement == null) || (passwordElement == null) || (loginButton == null)) {
        return null;
    }
    Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
    String sessionState = null;
    if (sessionStateCookie != null) {
        sessionState = sessionStateCookie.getValue();
    }
    System.out.println("waitForResourceOwnerAndGrantLoginForm: sessionState:" + sessionState);
    stopSelenium();
    showClientUserAgent(authorizeClient);
    return sessionState;
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement) AuthorizeClient(org.gluu.oxauth.client.AuthorizeClient)

Example 67 with Cookie

use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.

the class BaseTest method authenticateResourceOwnerAndDenyAccess.

public AuthorizationResponse authenticateResourceOwnerAndDenyAccess(String authorizeUrl, AuthorizationRequest authorizationRequest, String userId, String userSecret) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authenticateResourceOwnerAndDenyAccess: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    navigateToAuhorizationUrl(driver, authorizationRequestUrl);
    WebElement usernameElement = driver.findElement(By.id(loginFormUsername));
    WebElement passwordElement = driver.findElement(By.id(loginFormPassword));
    WebElement loginButton = driver.findElement(By.id(loginFormLoginButton));
    if (userId != null) {
        usernameElement.sendKeys(userId);
    }
    passwordElement.sendKeys(userSecret);
    String previousUrl = driver.getCurrentUrl();
    loginButton.click();
    if (ENABLE_REDIRECT_TO_LOGIN_PAGE) {
        waitForPageSwitch(driver, previousUrl);
    }
    String authorizationResponseStr = driver.getCurrentUrl();
    WebElement doNotAllowButton = driver.findElement(By.id(authorizeFormDoNotAllowButton));
    final String previousUrl2 = driver.getCurrentUrl();
    doNotAllowButton.click();
    waitForPageSwitch(driver, previousUrl2);
    authorizationResponseStr = driver.getCurrentUrl();
    Cookie sessionIdCookie = driver.manage().getCookieNamed("session_id");
    String sessionId = null;
    if (sessionIdCookie != null) {
        sessionId = sessionIdCookie.getValue();
    }
    System.out.println("authenticateResourceOwnerAndDenyAccess: sessionId:" + sessionId);
    stopSelenium();
    AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
    if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
        authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
    }
    authorizationResponse.setSessionId(sessionId);
    authorizeClient.setResponse(authorizationResponse);
    showClientUserAgent(authorizeClient);
    return authorizationResponse;
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement) AuthorizeClient(org.gluu.oxauth.client.AuthorizeClient) AuthorizationResponse(org.gluu.oxauth.client.AuthorizationResponse)

Example 68 with Cookie

use of org.openqa.selenium.Cookie in project keycloak by keycloak.

the class AbstractFailoverClusterTest method verifyLoggedOut.

protected void verifyLoggedOut() {
    // verify on target page
    oauth.openLoginForm();
    driver.navigate().refresh();
    assertTrue(loginPage.isCurrent());
    Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
    assertNull(sessionCookie);
}
Also used : Cookie(org.openqa.selenium.Cookie)

Example 69 with Cookie

use of org.openqa.selenium.Cookie in project keycloak by keycloak.

the class AbstractFailoverClusterTest method verifyLoggedIn.

protected Cookie verifyLoggedIn(Cookie sessionCookieForVerification) {
    // verify on realm path
    URLUtils.navigateToUri(AUTH_SERVER_ROOT + "/realms/test");
    Cookie sessionCookieOnRealmPath = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
    assertNotNull(sessionCookieOnRealmPath);
    assertEquals(sessionCookieOnRealmPath.getValue(), sessionCookieForVerification.getValue());
    // verify on target page
    appPage.open();
    assertTrue(appPage.isCurrent());
    Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
    assertNotNull(sessionCookie);
    assertEquals(sessionCookie.getValue(), sessionCookieForVerification.getValue());
    return sessionCookie;
}
Also used : Cookie(org.openqa.selenium.Cookie)

Example 70 with Cookie

use of org.openqa.selenium.Cookie in project keycloak by keycloak.

the class DemoServletsAdapterTest method testInvalidTokenCookie.

// KEYCLOAK-702
@Test
public void testInvalidTokenCookie() {
    // Login
    String tokenCookie = loginToCustomerCookiePortal();
    String changedTokenCookie = tokenCookie.replace("a", "b");
    // change cookie to invalid value
    driver.manage().addCookie(new Cookie(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE, changedTokenCookie, "/customer-cookie-portal"));
    // visit page and assert re-logged and cookie was refreshed
    customerCookiePortal.navigateTo();
    assertCurrentUrlEquals(customerCookiePortal);
    String currentCookie = driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE).getValue();
    assertNotEquals(currentCookie, tokenCookie);
    assertNotEquals(currentCookie, changedTokenCookie);
    // logout
    logoutFromCustomerCookiePortal();
}
Also used : Cookie(org.openqa.selenium.Cookie) BasicClientCookie(org.apache.http.impl.cookie.BasicClientCookie) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) AbstractServletsAdapterTest(org.keycloak.testsuite.adapter.AbstractServletsAdapterTest)

Aggregations

Cookie (org.openqa.selenium.Cookie)73 Test (org.junit.Test)26 WebElement (org.openqa.selenium.WebElement)16 WebDriver (org.openqa.selenium.WebDriver)14 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 Date (java.util.Date)8 App (com.coveros.selenified.application.App)7 IOException (java.io.IOException)7 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)7 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)6 Test (org.testng.annotations.Test)6 Collectors (java.util.stream.Collectors)5 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)5 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)5 Matchers (org.hamcrest.Matchers)5 Page (org.jboss.arquillian.graphene.page.Page)5 Assert (org.junit.Assert)5 AdminRoles (org.keycloak.models.AdminRoles)5