From bf54329d2e822767d9fb58a5686ef4c0bd6e4477 Mon Sep 17 00:00:00 2001 From: Miquel Simon Date: Sat, 23 Nov 2024 08:32:01 +0100 Subject: [PATCH 1/2] Migrate AdminConsoleLandingPageTest to the new framework Part of #34494 Signed-off-by: Miquel Simon --- .../org/keycloak/test}/admin/AdminConsoleLandingPageTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite => tests/base/src/test/java/org/keycloak/test}/admin/AdminConsoleLandingPageTest.java (100%) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/AdminConsoleLandingPageTest.java b/tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java similarity index 100% rename from testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/AdminConsoleLandingPageTest.java rename to tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java From 86aca687cb4d1abdcbe992827c768b966ed0ac37 Mon Sep 17 00:00:00 2001 From: Miquel Simon Date: Sat, 23 Nov 2024 08:32:30 +0100 Subject: [PATCH 2/2] Migrate AdminConsoleLandingPageTest to the new framework Part of #34494 Signed-off-by: Miquel Simon --- .../admin/AdminConsoleLandingPageTest.java | 66 +++++++------------ 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java b/tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java index 6d849c10ce60..cf1426929af5 100644 --- a/tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java +++ b/tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java @@ -1,65 +1,50 @@ -package org.keycloak.testsuite.admin; - -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.keycloak.broker.provider.util.SimpleHttp; -import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.testsuite.AbstractKeycloakTest; -import org.keycloak.testsuite.broker.util.SimpleHttpDefault; +package org.keycloak.test.admin; + +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.util.EntityUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.keycloak.test.framework.annotations.InjectHttpClient; +import org.keycloak.test.framework.annotations.InjectKeycloakUrls; +import org.keycloak.test.framework.annotations.KeycloakIntegrationTest; +import org.keycloak.test.framework.server.KeycloakUrls; import java.io.IOException; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class AdminConsoleLandingPageTest extends AbstractKeycloakTest { +@KeycloakIntegrationTest +public class AdminConsoleLandingPageTest { - private CloseableHttpClient client; + @InjectKeycloakUrls + KeycloakUrls keycloakUrls; - @Before - public void before() { - client = HttpClientBuilder.create().build(); - } - - @After - public void after() { - try { - client.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void addTestRealms(List testRealms) { - } + @InjectHttpClient + HttpClient httpClient; @Test public void landingPage() throws IOException { - String body = SimpleHttpDefault.doGet(suiteContext.getAuthServerInfo().getContextRoot() + "/auth/admin/master/console", client).asString(); + String body = EntityUtils.toString(httpClient.execute(new HttpGet(keycloakUrls.getBaseUrl().toString() + "/admin/master/console")).getEntity()); Map config = getConfig(body); String authUrl = config.get("authUrl"); - Assert.assertEquals(suiteContext.getAuthServerInfo().getContextRoot() + "/auth", authUrl); + Assertions.assertEquals(keycloakUrls.getBaseUrl().toString()+ "", authUrl); String resourceUrl = config.get("resourceUrl"); - Assert.assertTrue(resourceUrl.matches("/auth/resources/[^/]*/admin/keycloak.v2")); + Assertions.assertTrue(resourceUrl.matches("/resources/[^/]*/admin/keycloak.v2")); String consoleBaseUrl = config.get("consoleBaseUrl"); - Assert.assertEquals(consoleBaseUrl, "/auth/admin/master/console/"); + Assertions.assertEquals(consoleBaseUrl, "/admin/master/console/"); Pattern p = Pattern.compile("link href=\"([^\"]*)\""); Matcher m = p.matcher(body); while(m.find()) { - String url = m.group(1); - Assert.assertTrue(url.startsWith("/auth/resources/")); + String url = m.group(1); + Assertions.assertTrue(url.startsWith("/resources/")); } p = Pattern.compile("script src=\"([^\"]*)\""); @@ -68,9 +53,9 @@ public void landingPage() throws IOException { while(m.find()) { String url = m.group(1); if (url.contains("keycloak.js")) { - Assert.assertTrue(url, url.startsWith("/auth/js/")); + Assertions.assertTrue(url.startsWith("/js/"), url); } else { - Assert.assertTrue(url, url.startsWith("/auth/resources/")); + Assertions.assertTrue(url.startsWith("/resources/"), url); } } } @@ -90,5 +75,4 @@ private static Map getConfig(String body) { return variables; } - }