KEYCLOAK-5225 (#4577)

KEYCLOAK-5225 fix test

Fix
This commit is contained in:
Stian Thorgersen 2017-10-19 08:23:16 +02:00 committed by GitHub
parent fea4c54adc
commit d9ffc4fa21
2 changed files with 80 additions and 6 deletions

View file

@ -292,12 +292,9 @@ public class AdminConsole {
URI baseUri = uriInfo.getBaseUri(); URI baseUri = uriInfo.getBaseUri();
String authUrl = baseUri.toString(); map.put("authUrl", session.getContext().getContextPath());
authUrl = authUrl.substring(0, authUrl.length() - 1); map.put("consoleBaseUrl", Urls.adminConsoleRoot(baseUri, realm.getName()).getPath());
map.put("resourceUrl", Urls.themeRoot(baseUri).getPath() + "/admin/" + theme.getName());
map.put("authUrl", authUrl);
map.put("consoleBaseUrl", Urls.adminConsoleRoot(baseUri, realm.getName()));
map.put("resourceUrl", Urls.themeRoot(baseUri) + "/admin/" + theme.getName());
map.put("masterRealm", Config.getAdminRealm()); map.put("masterRealm", Config.getAdminRealm());
map.put("resourceVersion", Version.RESOURCES_VERSION); map.put("resourceVersion", Version.RESOURCES_VERSION);
map.put("properties", theme.getProperties()); map.put("properties", theme.getProperties());

View file

@ -0,0 +1,77 @@
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 java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AdminConsoleLandingPageTest extends AbstractKeycloakTest {
private CloseableHttpClient client;
@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<RealmRepresentation> testRealms) {
}
@Test
public void landingPage() throws IOException {
String body = SimpleHttp.doGet(suiteContext.getAuthServerInfo().getContextRoot() + "/auth/admin/master/console", client).asString();
String authUrl = body.substring(body.indexOf("var authUrl = '") + 15);
authUrl = authUrl.substring(0, authUrl.indexOf("'"));
Assert.assertEquals("/auth", authUrl);
String resourceUrl = body.substring(body.indexOf("var resourceUrl = '") + 19);
resourceUrl = resourceUrl.substring(0, resourceUrl.indexOf("'"));
Assert.assertTrue(resourceUrl.matches("/auth/resources/[^/]*/admin/([a-z]*|[a-z]*-[a-z]*)"));
String consoleBaseUrl = body.substring(body.indexOf("var consoleBaseUrl = '") + 22);
consoleBaseUrl = consoleBaseUrl.substring(0, consoleBaseUrl.indexOf("'"));
Assert.assertEquals(consoleBaseUrl, "/auth/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/"));
}
p = Pattern.compile("script src=\"([^\"]*)\"");
m = p.matcher(body);
while(m.find()) {
String url = m.group(1);
if (url.contains("keycloak.js")) {
Assert.assertTrue(url, url.startsWith("/auth/js/"));
} else {
Assert.assertTrue(url, url.startsWith("/auth/resources/"));
}
}
}
}