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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations