diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cookies/CookieTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cookies/CookieTest.java index 82f034e9a2..508541bcf1 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cookies/CookieTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cookies/CookieTest.java @@ -30,15 +30,13 @@ import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; import org.jboss.arquillian.graphene.page.Page; import org.junit.Test; -import org.keycloak.admin.client.resource.UsersResource; -import org.keycloak.common.Profile; import org.keycloak.models.Constants; import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.AbstractKeycloakTest; -import org.keycloak.testsuite.arquillian.annotation.DisableFeature; import org.keycloak.testsuite.auth.page.AuthRealm; +import org.keycloak.testsuite.pages.AppPage; import org.keycloak.testsuite.pages.LoginPage; +import org.keycloak.testsuite.util.AccountHelper; import org.keycloak.testsuite.util.ContainerAssume; import org.keycloak.testsuite.util.OAuthClient; import org.keycloak.testsuite.util.OAuthClient.AuthorizationEndpointResponse; @@ -62,7 +60,6 @@ import static org.keycloak.services.managers.AuthenticationManager.KEYCLOAK_SESS import static org.keycloak.services.managers.AuthenticationSessionManager.AUTH_SESSION_ID; import static org.keycloak.services.util.CookieHelper.LEGACY_COOKIE; import static org.keycloak.testsuite.admin.AbstractAdminTest.loadJson; -import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf; import jakarta.ws.rs.core.HttpHeaders; @@ -71,12 +68,14 @@ import jakarta.ws.rs.core.HttpHeaders; * @author hmlnarik * @author Vaclav Muzikar */ -@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228) public class CookieTest extends AbstractKeycloakTest { @Page protected LoginPage loginPage; + @Page + protected AppPage appPage; + @Override public void addTestRealms(List testRealms) { RealmRepresentation realmRepresentation = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class); @@ -88,7 +87,6 @@ public class CookieTest extends AbstractKeycloakTest { @Override public void setDefaultPageUriParameters() { super.setDefaultPageUriParameters(); - accountPage.setAuthRealm(AuthRealm.TEST); } @Test @@ -102,15 +100,15 @@ public class CookieTest extends AbstractKeycloakTest { } private void testCookieValue(String cookieName) throws Exception { - final String accountClientId = realmsResouce().realm("test").clients().findByClientId("account").get(0).getId(); + final String accountClientId = realmsResouce().realm("test").clients().findByClientId("test-app").get(0).getId(); final String clientSecret = realmsResouce().realm("test").clients().get(accountClientId).getSecret().getValue(); - AuthorizationEndpointResponse codeResponse = oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).doLogin("test-user@localhost", "password"); + AuthorizationEndpointResponse codeResponse = oauth.clientId("test-app").redirectUri(oauth.APP_AUTH_ROOT).doLogin("test-user@localhost", "password"); OAuthClient.AccessTokenResponse accTokenResp = oauth.doAccessTokenRequest(codeResponse.getCode(), clientSecret); String accessToken = accTokenResp.getAccessToken(); - accountPage.navigateTo(); - accountPage.assertCurrent(); + appPage.open(); + appPage.assertCurrent(); try (CloseableHttpClient hc = OAuthClient.newCloseableHttpClient()) { BasicCookieStore cookieStore = new BasicCookieStore(); @@ -122,7 +120,7 @@ public class CookieTest extends AbstractKeycloakTest { HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); - HttpGet get = new HttpGet(oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).getLoginFormUrl()); + HttpGet get = new HttpGet(oauth.clientId("test-app").redirectUri(oauth.APP_AUTH_ROOT).getLoginFormUrl()); try (CloseableHttpResponse resp = hc.execute(get, localContext)) { final String pageContent = EntityUtils.toString(resp.getEntity()); @@ -139,16 +137,16 @@ public class CookieTest extends AbstractKeycloakTest { @Test public void testCookieValueLoggedOut() throws Exception { - final String accountClientId = realmsResouce().realm("test").clients().findByClientId("account").get(0).getId(); + final String accountClientId = realmsResouce().realm("test").clients().findByClientId("test-app").get(0).getId(); final String clientSecret = realmsResouce().realm("test").clients().get(accountClientId).getSecret().getValue(); - AuthorizationEndpointResponse codeResponse = oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).doLogin("test-user@localhost", "password"); + AuthorizationEndpointResponse codeResponse = oauth.clientId("test-app").redirectUri(oauth.APP_AUTH_ROOT).doLogin("test-user@localhost", "password"); OAuthClient.AccessTokenResponse accTokenResp = oauth.doAccessTokenRequest(codeResponse.getCode(), clientSecret); String accessToken = accTokenResp.getAccessToken(); - accountPage.navigateTo(); - accountPage.assertCurrent(); - accountPage.logOut(); + appPage.open(); + appPage.assertCurrent(); + AccountHelper.logout(realmsResouce().realm("test"), "test-user@localhost"); try (CloseableHttpClient hc = OAuthClient.newCloseableHttpClient()) { BasicCookieStore cookieStore = new BasicCookieStore(); @@ -160,7 +158,7 @@ public class CookieTest extends AbstractKeycloakTest { HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); - HttpGet get = new HttpGet(oauth.clientId("account").redirectUri(accountPage.buildUri().toString()).getLoginFormUrl()); + HttpGet get = new HttpGet(oauth.clientId("test-app").redirectUri(oauth.APP_AUTH_ROOT).getLoginFormUrl()); try (CloseableHttpResponse resp = hc.execute(get, localContext)) { final String pageContent = EntityUtils.toString(resp.getEntity()); @@ -179,10 +177,13 @@ public class CookieTest extends AbstractKeycloakTest { public void legacyCookiesTest() { ContainerAssume.assumeAuthServerSSL(); - accountPage.navigateTo(); - assertCurrentUrlStartsWithLoginUrlOf(accountPage); + loginPage.open(); + loginPage.assertCurrent(); loginPage.login("test-user@localhost", "password"); + appPage.assertCurrent(); + + driver.navigate().to(oauth.AUTH_SERVER_ROOT + "/realms/test/login-actions/authenticate/"); Cookie sameSiteIdentityCookie = driver.manage().getCookieNamed(KEYCLOAK_IDENTITY_COOKIE); Cookie legacyIdentityCookie = driver.manage().getCookieNamed(KEYCLOAK_IDENTITY_COOKIE + LEGACY_COOKIE); @@ -200,15 +201,13 @@ public class CookieTest extends AbstractKeycloakTest { public void testNoDuplicationsWhenExpiringCookies() throws IOException { ContainerAssume.assumeAuthServerSSL(); - accountPage.navigateTo(); - assertCurrentUrlStartsWithLoginUrlOf(accountPage); + loginPage.open(); + loginPage.assertCurrent(); loginPage.login("test-user@localhost", "password"); + appPage.assertCurrent(); - UsersResource usersResource = realmsResouce().realm(AuthRealm.TEST).users(); - UserRepresentation user = usersResource.search("test-user@localhost").get(0); - - usersResource.get(user.getId()).logout(); + driver.navigate().to(oauth.AUTH_SERVER_ROOT + "/realms/test/login-actions/authenticate/"); Cookie invalidIdentityCookie = driver.manage().getCookieNamed(KEYCLOAK_IDENTITY_COOKIE); CookieStore cookieStore = new BasicCookieStore();