forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from miquelsi/main-move5
Main move5
- Loading branch information
Showing
2 changed files
with
78 additions
and
94 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
tests/base/src/test/java/org/keycloak/test/admin/AdminConsoleLandingPageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
@KeycloakIntegrationTest | ||
public class AdminConsoleLandingPageTest { | ||
|
||
@InjectKeycloakUrls | ||
KeycloakUrls keycloakUrls; | ||
|
||
@InjectHttpClient | ||
HttpClient httpClient; | ||
|
||
@Test | ||
public void landingPage() throws IOException { | ||
String body = EntityUtils.toString(httpClient.execute(new HttpGet(keycloakUrls.getBaseUrl().toString() + "/admin/master/console")).getEntity()); | ||
|
||
Map<String, String> config = getConfig(body); | ||
String authUrl = config.get("authUrl"); | ||
Assertions.assertEquals(keycloakUrls.getBaseUrl().toString()+ "", authUrl); | ||
|
||
String resourceUrl = config.get("resourceUrl"); | ||
Assertions.assertTrue(resourceUrl.matches("/resources/[^/]*/admin/keycloak.v2")); | ||
|
||
String consoleBaseUrl = config.get("consoleBaseUrl"); | ||
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); | ||
Assertions.assertTrue(url.startsWith("/resources/")); | ||
} | ||
|
||
p = Pattern.compile("script src=\"([^\"]*)\""); | ||
m = p.matcher(body); | ||
|
||
while(m.find()) { | ||
String url = m.group(1); | ||
if (url.contains("keycloak.js")) { | ||
Assertions.assertTrue(url.startsWith("/js/"), url); | ||
} else { | ||
Assertions.assertTrue(url.startsWith("/resources/"), url); | ||
} | ||
} | ||
} | ||
|
||
private static Map<String, String> getConfig(String body) { | ||
Map<String, String> variables = new HashMap<>(); | ||
String start = "<script id=\"environment\" type=\"application/json\">"; | ||
String end = "</script>"; | ||
|
||
String config = body.substring(body.indexOf(start) + start.length()); | ||
config = config.substring(0, config.indexOf(end)).trim(); | ||
|
||
Matcher matcher = Pattern.compile(".*\"(.*)\": \"(.*)\"").matcher(config); | ||
while (matcher.find()) { | ||
variables.put(matcher.group(1), matcher.group(2)); | ||
} | ||
|
||
return variables; | ||
} | ||
} |
94 changes: 0 additions & 94 deletions
94
...an/tests/base/src/test/java/org/keycloak/testsuite/admin/AdminConsoleLandingPageTest.java
This file was deleted.
Oops, something went wrong.