From a5aa1da841c1b3c2f0668d52d314080b73021184 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 3 Oct 2014 10:01:30 +0200 Subject: [PATCH] Add login test with multiple sessions for same user --- .../testsuite/account/AccountTest.java | 24 +++++---- .../org/keycloak/testsuite/forms/SSOTest.java | 51 ++++++++++++++++++- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java index 4fe0131178..5aa52c3c86 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java @@ -453,20 +453,24 @@ public class AccountTest { // Create second session WebDriver driver2 = WebRule.createWebDriver(); - OAuthClient oauth2 = new OAuthClient(driver2); - oauth2.state("mystate"); - oauth2.doLogin("view-sessions", "password"); + try { + OAuthClient oauth2 = new OAuthClient(driver2); + oauth2.state("mystate"); + oauth2.doLogin("view-sessions", "password"); - Event login2Event = events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent(); + Event login2Event = events.expectLogin().user(userId).detail(Details.USERNAME, "view-sessions").assertEvent(); - sessionsPage.open(); - sessions = sessionsPage.getSessions(); - Assert.assertEquals(2, sessions.size()); + sessionsPage.open(); + sessions = sessionsPage.getSessions(); + Assert.assertEquals(2, sessions.size()); - sessionsPage.logoutAll(); + sessionsPage.logoutAll(); - events.expectLogout(registerEvent.getSessionId()); - events.expectLogout(login2Event.getSessionId()); + events.expectLogout(registerEvent.getSessionId()); + events.expectLogout(login2Event.getSessionId()); + } finally { + driver2.close(); + } } } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/SSOTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/SSOTest.java index 30c10a7628..2f78c6dc8e 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/SSOTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/forms/SSOTest.java @@ -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 Stian Thorgersen @@ -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(); + } + } + }