Merge pull request #731 from stianst/master
Add login test with multiple sessions for same user
This commit is contained in:
commit
53489cd556
2 changed files with 64 additions and 11 deletions
|
@ -453,6 +453,7 @@ public class AccountTest {
|
|||
|
||||
// Create second session
|
||||
WebDriver driver2 = WebRule.createWebDriver();
|
||||
try {
|
||||
OAuthClient oauth2 = new OAuthClient(driver2);
|
||||
oauth2.state("mystate");
|
||||
oauth2.doLogin("view-sessions", "password");
|
||||
|
@ -467,6 +468,9 @@ public class AccountTest {
|
|||
|
||||
events.expectLogout(registerEvent.getSessionId());
|
||||
events.expectLogout(login2Event.getSessionId());
|
||||
} finally {
|
||||
driver2.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.OAuthClient;
|
||||
import org.keycloak.testsuite.pages.AccountUpdateProfilePage;
|
||||
|
@ -40,6 +41,7 @@ import org.openqa.selenium.WebDriver;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
@ -88,7 +90,7 @@ public class SSOTest {
|
|||
|
||||
profilePage.open();
|
||||
|
||||
Assert.assertTrue(profilePage.isCurrent());
|
||||
assertTrue(profilePage.isCurrent());
|
||||
|
||||
String sessionId2 = events.expectLogin().detail(Details.AUTH_METHOD, "sso").removeDetail(Details.USERNAME).client("test-app").assertEvent().getSessionId();
|
||||
|
||||
|
@ -105,4 +107,51 @@ public class SSOTest {
|
|||
events.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleSessions() {
|
||||
loginPage.open();
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
Assert.assertNotNull(oauth.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
|
||||
Event login1 = events.expectLogin().assertEvent();
|
||||
|
||||
WebDriver driver2 = WebRule.createWebDriver();
|
||||
try {
|
||||
OAuthClient oauth2 = new OAuthClient(driver2);
|
||||
oauth2.state("mystate");
|
||||
oauth2.doLogin("test-user@localhost", "password");
|
||||
|
||||
Event login2 = events.expectLogin().assertEvent();
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
|
||||
assertNotEquals(login1.getSessionId(), login2.getSessionId());
|
||||
|
||||
oauth.openLogout();
|
||||
events.expectLogout(login1.getSessionId()).assertEvent();
|
||||
|
||||
oauth.openLoginForm();
|
||||
|
||||
assertTrue(loginPage.isCurrent());
|
||||
|
||||
oauth2.openLoginForm();
|
||||
|
||||
events.expectLogin().session(login2.getSessionId()).detail(Details.AUTH_METHOD, "sso").removeDetail(Details.USERNAME).assertEvent();
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
|
||||
oauth2.openLogout();
|
||||
events.expectLogout(login2.getSessionId()).assertEvent();
|
||||
|
||||
oauth2.openLoginForm();
|
||||
|
||||
assertTrue(driver2.getTitle().equals("Log in to test"));
|
||||
} finally {
|
||||
driver2.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue