Fixed & enabled SessionFailoverClusterTest by default
This commit is contained in:
parent
73b6751219
commit
e107a403cf
4 changed files with 142 additions and 67 deletions
|
@ -18,8 +18,8 @@ package org.keycloak.testsuite.auth.page.account;
|
||||||
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
import org.jboss.arquillian.graphene.findby.FindByJQuery;
|
import org.jboss.arquillian.graphene.findby.FindByJQuery;
|
||||||
import org.keycloak.admin.client.resource.RealmResource;
|
|
||||||
import org.keycloak.testsuite.auth.page.AuthRealm;
|
import org.keycloak.testsuite.auth.page.AuthRealm;
|
||||||
|
import org.keycloak.testsuite.page.PageWithLogOutAction;
|
||||||
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
@ -29,7 +29,7 @@ import org.openqa.selenium.support.FindBy;
|
||||||
* @author <a href="mailto:pmensik@redhat.com">Petr Mensik</a>
|
* @author <a href="mailto:pmensik@redhat.com">Petr Mensik</a>
|
||||||
* @author tkyjovsk
|
* @author tkyjovsk
|
||||||
*/
|
*/
|
||||||
public class AccountManagement extends AuthRealm {
|
public class AccountManagement extends AuthRealm implements PageWithLogOutAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UriBuilder createUriBuilder() {
|
public UriBuilder createUriBuilder() {
|
||||||
|
@ -77,6 +77,11 @@ public class AccountManagement extends AuthRealm {
|
||||||
signOutLink.click();
|
signOutLink.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void logOut() {
|
||||||
|
signOut();
|
||||||
|
}
|
||||||
|
|
||||||
public void account() {
|
public void account() {
|
||||||
accountLink.click();
|
accountLink.click();
|
||||||
}
|
}
|
||||||
|
@ -108,4 +113,5 @@ public class AccountManagement extends AuthRealm {
|
||||||
public void waitForAccountLinkPresent() {
|
public void waitForAccountLinkPresent() {
|
||||||
waitUntilElement(accountLink, "account link should be present").is().present();
|
waitUntilElement(accountLink, "account link should be present").is().present();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import static org.keycloak.testsuite.auth.page.AuthRealm.MASTER;
|
||||||
import org.keycloak.testsuite.auth.page.login.PageWithLoginUrl;
|
import org.keycloak.testsuite.auth.page.login.PageWithLoginUrl;
|
||||||
import org.keycloak.testsuite.console.page.fragment.Menu;
|
import org.keycloak.testsuite.console.page.fragment.Menu;
|
||||||
import org.keycloak.testsuite.console.page.fragment.ModalDialog;
|
import org.keycloak.testsuite.console.page.fragment.ModalDialog;
|
||||||
|
import org.keycloak.testsuite.page.PageWithLogOutAction;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ import org.openqa.selenium.support.FindBy;
|
||||||
*
|
*
|
||||||
* @author Petr Mensik
|
* @author Petr Mensik
|
||||||
*/
|
*/
|
||||||
public class AdminConsole extends AuthServer implements PageWithLoginUrl {
|
public class AdminConsole extends AuthServer implements PageWithLoginUrl, PageWithLogOutAction {
|
||||||
|
|
||||||
public static final String ADMIN_REALM = "adminRealm";
|
public static final String ADMIN_REALM = "adminRealm";
|
||||||
|
|
||||||
|
@ -80,6 +81,7 @@ public class AdminConsole extends AuthServer implements PageWithLoginUrl {
|
||||||
@FindBy(css = "navbar-brand")
|
@FindBy(css = "navbar-brand")
|
||||||
protected WebElement brandLink;
|
protected WebElement brandLink;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void logOut() {
|
public void logOut() {
|
||||||
menu.logOut();
|
menu.logOut();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package org.keycloak.testsuite.page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author tkyjovsk
|
||||||
|
*/
|
||||||
|
public interface PageWithLogOutAction {
|
||||||
|
|
||||||
|
public void logOut();
|
||||||
|
|
||||||
|
}
|
|
@ -1,17 +1,19 @@
|
||||||
package org.keycloak.testsuite.cluster;
|
package org.keycloak.testsuite.cluster;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
|
import static org.keycloak.testsuite.auth.page.AuthRealm.ADMIN;
|
||||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlDoesntStartWith;
|
|
||||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
|
|
||||||
import static org.keycloak.testsuite.util.WaitUtils.pause;
|
import static org.keycloak.testsuite.util.WaitUtils.pause;
|
||||||
import org.openqa.selenium.Cookie;
|
import org.openqa.selenium.Cookie;
|
||||||
|
import org.keycloak.testsuite.page.AbstractPage;
|
||||||
|
import org.keycloak.testsuite.page.PageWithLogOutAction;
|
||||||
|
import org.junit.Before;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -20,77 +22,131 @@ import org.openqa.selenium.Cookie;
|
||||||
public class SessionFailoverClusterTest extends AbstractClusterTest {
|
public class SessionFailoverClusterTest extends AbstractClusterTest {
|
||||||
|
|
||||||
public static final String KEYCLOAK_SESSION_COOKIE = "KEYCLOAK_SESSION";
|
public static final String KEYCLOAK_SESSION_COOKIE = "KEYCLOAK_SESSION";
|
||||||
public static final String KEYCLOAK_IDENTITY_COOKIE = "KEYCLOAK_IDENTITY";
|
|
||||||
|
public static final Integer SESSION_CACHE_OWNERS = Integer.parseInt(System.getProperty("session.cache.owners", "1"));
|
||||||
|
public static final Integer OFFLINE_SESSION_CACHE_OWNERS = Integer.parseInt(System.getProperty("offline.session.cache.owners", "1"));
|
||||||
|
public static final Integer LOGIN_FAILURES_CACHE_OWNERS = Integer.parseInt(System.getProperty("login.failure.cache.owners", "1"));
|
||||||
|
|
||||||
|
public static final Integer REBALANCE_WAIT = Integer.parseInt(System.getProperty("rebalance.wait", "5000"));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void beforeSessionFailover() {
|
||||||
|
log.info("Initial node failure");
|
||||||
|
failure();
|
||||||
|
pause(REBALANCE_WAIT);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("work in progress") // only works with owners="2" at the moment
|
|
||||||
public void sessionFailover() {
|
public void sessionFailover() {
|
||||||
|
|
||||||
|
boolean expectSuccessfulFailover = SESSION_CACHE_OWNERS >= getClusterSize();
|
||||||
|
|
||||||
|
log.info("SESSION FAILOVER TEST: cluster size = " + getClusterSize() + ", session-cache owners = " + SESSION_CACHE_OWNERS
|
||||||
|
+ " --> Testsing for " + (expectSuccessfulFailover ? "" : "UN") + "SUCCESSFUL session failover.");
|
||||||
|
|
||||||
|
assertEquals(2, getClusterSize());
|
||||||
|
|
||||||
|
sessionFailover(expectSuccessfulFailover);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sessionFailover(boolean expectSuccessfulFailover) {
|
||||||
|
|
||||||
// LOGIN
|
// LOGIN
|
||||||
accountPage.navigateTo();
|
Cookie sessionCookie = login(accountPage);
|
||||||
driver.navigate().refresh();
|
|
||||||
pause(3000);
|
|
||||||
loginPage.form().login(ADMIN, ADMIN);
|
|
||||||
assertCurrentUrlStartsWith(accountPage);
|
|
||||||
|
|
||||||
Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
switchFailedNode();
|
||||||
assertNotNull(sessionCookie);
|
|
||||||
|
|
||||||
failure();
|
// VERIFY
|
||||||
|
if (expectSuccessfulFailover) {
|
||||||
|
verifyLoggedIn(accountPage, sessionCookie);
|
||||||
|
} else {
|
||||||
|
verifyLoggedOut(accountPage);
|
||||||
|
// FIXME test fails if I put re-login here
|
||||||
|
}
|
||||||
|
|
||||||
// check if session survived backend failure
|
switchFailedNode();
|
||||||
|
|
||||||
driver.navigate().refresh();
|
// VERIFY again
|
||||||
pause(3000);
|
if (expectSuccessfulFailover) {
|
||||||
|
verifyLoggedIn(accountPage, sessionCookie);
|
||||||
assertCurrentUrlStartsWith(accountPage);
|
} else {
|
||||||
Cookie sessionCookieAfterFailover = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
verifyLoggedOut(accountPage);
|
||||||
assertNotNull(sessionCookieAfterFailover);
|
login(accountPage);
|
||||||
assertEquals(sessionCookieAfterFailover.getValue(), sessionCookie.getValue());
|
}
|
||||||
|
|
||||||
failback();
|
|
||||||
iterateCurrentFailNode();
|
|
||||||
|
|
||||||
// check if session survived backend failback
|
|
||||||
driver.navigate().refresh();
|
|
||||||
pause(3000);
|
|
||||||
assertCurrentUrlStartsWith(accountPage);
|
|
||||||
Cookie sessionCookieAfterFailback = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
|
||||||
assertNotNull(sessionCookieAfterFailback);
|
|
||||||
assertEquals(sessionCookieAfterFailover.getValue(), sessionCookie.getValue());
|
|
||||||
|
|
||||||
// LOGOUT
|
// LOGOUT
|
||||||
accountPage.navigateTo();
|
logout(accountPage);
|
||||||
accountPage.signOut();
|
verifyLoggedOut(accountPage);
|
||||||
|
|
||||||
assertCurrentUrlDoesntStartWith(accountPage);
|
switchFailedNode();
|
||||||
masterRealmPage.navigateTo();
|
|
||||||
sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
|
||||||
assertNull(sessionCookie);
|
|
||||||
|
|
||||||
failure();
|
// VERIFY
|
||||||
|
verifyLoggedOut(accountPage);
|
||||||
|
|
||||||
// check if session survived backend failure
|
}
|
||||||
driver.navigate().refresh();
|
|
||||||
pause(3000);
|
/**
|
||||||
assertCurrentUrlDoesntStartWith(accountPage);
|
* failure --> failback --> failure of next node
|
||||||
masterRealmPage.navigateTo();
|
*/
|
||||||
sessionCookieAfterFailover = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
protected void switchFailedNode() {
|
||||||
assertNull(sessionCookieAfterFailover);
|
assertFalse(controller.isStarted(getCurrentFailNode().getQualifier()));
|
||||||
|
|
||||||
failback();
|
failback();
|
||||||
|
pause(REBALANCE_WAIT);
|
||||||
|
|
||||||
// check if session survived backend failback
|
iterateCurrentFailNode();
|
||||||
driver.navigate().refresh();
|
|
||||||
pause(3000);
|
failure();
|
||||||
assertCurrentUrlDoesntStartWith(accountPage);
|
pause(REBALANCE_WAIT);
|
||||||
|
|
||||||
|
assertFalse(controller.isStarted(getCurrentFailNode().getQualifier()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Cookie login(AbstractPage targetPage) {
|
||||||
|
targetPage.navigateTo();
|
||||||
|
assertCurrentUrlStartsWith(loginPage);
|
||||||
|
loginPage.form().login(ADMIN, ADMIN);
|
||||||
|
assertCurrentUrlStartsWith(targetPage);
|
||||||
|
Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
||||||
|
assertNotNull(sessionCookie);
|
||||||
|
return sessionCookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void logout(AbstractPage targetPage) {
|
||||||
|
if (!(targetPage instanceof PageWithLogOutAction)) {
|
||||||
|
throw new IllegalArgumentException(targetPage.getClass().getSimpleName() + " must implement PageWithLogOutAction interface");
|
||||||
|
}
|
||||||
|
targetPage.navigateTo();
|
||||||
|
assertCurrentUrlStartsWith(targetPage);
|
||||||
|
((PageWithLogOutAction) targetPage).logOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Cookie verifyLoggedIn(AbstractPage targetPage, Cookie sessionCookieForVerification) {
|
||||||
|
// verify on realm path
|
||||||
masterRealmPage.navigateTo();
|
masterRealmPage.navigateTo();
|
||||||
sessionCookieAfterFailback = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
Cookie sessionCookieOnRealmPath = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
||||||
assertNull(sessionCookieAfterFailback);
|
assertNotNull(sessionCookieOnRealmPath);
|
||||||
|
assertEquals(sessionCookieOnRealmPath.getValue(), sessionCookieForVerification.getValue());
|
||||||
|
// verify on target page
|
||||||
|
targetPage.navigateTo();
|
||||||
|
assertCurrentUrlStartsWith(targetPage);
|
||||||
|
Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
||||||
|
assertNotNull(sessionCookie);
|
||||||
|
assertEquals(sessionCookie.getValue(), sessionCookieForVerification.getValue());
|
||||||
|
return sessionCookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void verifyLoggedOut(AbstractPage targetPage) {
|
||||||
|
// verify on target page
|
||||||
|
targetPage.navigateTo();
|
||||||
|
driver.navigate().refresh();
|
||||||
|
assertCurrentUrlStartsWith(loginPage);
|
||||||
|
Cookie sessionCookie = driver.manage().getCookieNamed(KEYCLOAK_SESSION_COOKIE);
|
||||||
|
assertNull(sessionCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue