KEYCLOAK-6627 Closing admin clients and testing clients in testsuite

This commit is contained in:
mposolda 2019-02-15 18:36:44 +01:00 committed by Pavel Drozd
parent 195aeaca68
commit 362faf3adb
13 changed files with 164 additions and 96 deletions

View file

@ -1192,8 +1192,8 @@ public class OAuthClient {
private JSONWebKeySet getRealmKeys(String realm) {
String certUrl = baseUrl + "/realms/" + realm + "/protocol/openid-connect/certs";
try {
return SimpleHttp.doGet(certUrl, httpClient.get()).asJson(JSONWebKeySet.class);
try (CloseableHttpClient client = httpClient.get()){
return SimpleHttp.doGet(certUrl, client).asJson(JSONWebKeySet.class);
} catch (IOException e) {
throw new RuntimeException("Failed to retrieve keys", e);
}

View file

@ -17,6 +17,7 @@
package org.keycloak.testsuite.admin;
import org.junit.AfterClass;
import org.junit.Test;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.resource.RealmResource;
@ -48,6 +49,9 @@ public class CrossRealmPermissionsTest extends AbstractKeycloakTest {
private static final String REALM_NAME = "crossrealm-test";
private static final String REALM2_NAME = "crossrealm2-test";
private static Keycloak adminClient1;
private static Keycloak adminClient2;
private RealmResource realm1;
private RealmResource realm2;
@ -62,7 +66,8 @@ public class CrossRealmPermissionsTest extends AbstractKeycloakTest {
.addPassword("password"));
testRealms.add(builder.build());
realm1 = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", REALM_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS()).realm(REALM_NAME);
adminClient1 = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", REALM_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS());
realm1 = adminClient1.realm(REALM_NAME);
builder = RealmBuilder.create().name(REALM2_NAME).testMail();
builder.client(ClientBuilder.create().clientId("test-client").publicClient().directAccessGrants());
@ -74,9 +79,18 @@ public class CrossRealmPermissionsTest extends AbstractKeycloakTest {
testRealms.add(builder.build());
realm2 = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", REALM2_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS()).realm(REALM2_NAME);
adminClient2 = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", REALM2_NAME, AdminRoles.REALM_ADMIN, "password", "test-client", "secret", TLSUtils.initializeTLS());
realm2 = adminClient2.realm(REALM2_NAME);
}
@AfterClass
public static void afterClass() {
adminClient1.close();
adminClient2.close();
}
@Test
public void users() {
UserRepresentation user = UserBuilder.create().username("randomuser-" + Time.currentTimeMillis()).build();

View file

@ -893,10 +893,10 @@ public class FineGrainAdminUnitTest extends AbstractKeycloakTest {
String exchanged = oauth.doTokenExchange("master", token, "admin-cli", "kcinit", "password").getAccessToken();
Assert.assertNotNull(exchanged);
Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
AuthRealm.MASTER, Constants.ADMIN_CLI_CLIENT_ID, exchanged, TLSUtils.initializeTLS());
Assert.assertNotNull(client.realm("master").roles().get("offline_access"));
try (Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
AuthRealm.MASTER, Constants.ADMIN_CLI_CLIENT_ID, exchanged, TLSUtils.initializeTLS())) {
Assert.assertNotNull(client.realm("master").roles().get("offline_access"));
}
}
@Test
@ -949,42 +949,45 @@ public class FineGrainAdminUnitTest extends AbstractKeycloakTest {
}
});
Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "customer-a-manager", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS());
try (Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "customer-a-manager", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS())) {
List<UserRepresentation> result = client.realm("test").users().search(null, "test", null, null, -1, 20);
List<UserRepresentation> result = client.realm("test").users().search(null, "test", null, null, -1, 20);
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("b"))));
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("b"))));
result = client.realm("test").users().search(null, "test", null, null, 20, 40);
result = client.realm("test").users().search(null, "test", null, null, 20, 40);
Assert.assertEquals(0, result.size());
Assert.assertEquals(0, result.size());
}
client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "regular-admin-user", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS());
try (Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "regular-admin-user", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS())) {
result = client.realm("test").users().search(null, "test", null, null, -1, 20);
List<UserRepresentation> result = client.realm("test").users().search(null, "test", null, null, -1, 20);
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("a"))));
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("a"))));
client.realm("test").users().search(null, null, null, null, -1, -1);
client.realm("test").users().search(null, null, null, null, -1, -1);
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("a"))));
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("a"))));
}
client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "customer-a-manager", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS());
try (Keycloak client = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
"test", "customer-a-manager", "password", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS())) {
result = client.realm("test").users().search(null, null, null, null, -1, 20);
List<UserRepresentation> result = client.realm("test").users().search(null, null, null, null, -1, 20);
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("b"))));
Assert.assertEquals(20, result.size());
Assert.assertThat(result, Matchers.everyItem(Matchers.hasProperty("username", Matchers.startsWith("b"))));
result = client.realm("test").users().search("a", -1, 20, false);
result = client.realm("test").users().search("a", -1, 20, false);
Assert.assertEquals(0, result.size());
Assert.assertEquals(0, result.size());
}
}
}

View file

@ -25,9 +25,12 @@ import org.keycloak.testsuite.AbstractKeycloakTest;
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
import org.keycloak.testsuite.arquillian.undertow.TLSUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
@ -78,11 +81,18 @@ public abstract class AbstractConcurrencyTest extends AbstractTestRealmKeycloakT
Collection<Callable<Void>> tasks = new LinkedList<>();
Collection<Throwable> failures = new ConcurrentLinkedQueue<>();
final List<Callable<Void>> runnablesToTasks = new LinkedList<>();
// Track all used admin clients, so they can be closed after the test
Set<Keycloak> usedKeycloaks = Collections.synchronizedSet(new HashSet<>());
for (KeycloakRunnable runnable : runnables) {
runnablesToTasks.add(() -> {
int arrayIndex = currentThreadIndex.getAndIncrement() % numThreads;
try {
runnable.run(arrayIndex % numThreads, keycloaks.get(), keycloaks.get().realm(REALM_NAME));
Keycloak keycloak = keycloaks.get();
usedKeycloaks.add(keycloak);
runnable.run(arrayIndex % numThreads, keycloak, keycloak.realm(REALM_NAME));
} catch (Throwable ex) {
failures.add(ex);
}
@ -99,6 +109,14 @@ public abstract class AbstractConcurrencyTest extends AbstractTestRealmKeycloakT
service.awaitTermination(3, TimeUnit.MINUTES);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
} finally {
for (Keycloak keycloak : usedKeycloaks) {
try {
keycloak.close();
} catch (Exception e) {
failures.add(e);
}
}
}
if (! failures.isEmpty()) {

View file

@ -569,11 +569,12 @@ public class GroupTest extends AbstractGroupTest {
RoleMappingResource mappings = realm.users().get(userId).roles();
mappings.realmLevel().add(Collections.singletonList(adminRole));
Keycloak userClient = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
realmName, userName, "pwd", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS());
try (Keycloak userClient = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth",
realmName, userName, "pwd", Constants.ADMIN_CLI_CLIENT_ID, TLSUtils.initializeTLS())) {
assertThat(userClient.realms().findAll(), // Any admin operation will do
not(empty()));
assertThat(userClient.realms().findAll(), // Any admin operation will do
not(empty()));
}
}
/**

View file

@ -28,6 +28,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.keycloak.admin.client.resource.AuthorizationResource;
@ -195,7 +197,8 @@ public class GroupNamePolicyTest extends AbstractAuthzTest {
policy.setGroupsClaim("groups");
policy.addGroupPath(groupPath, extendChildren);
getClient().authorization().policies().group().create(policy);
Response response = getClient().authorization().policies().group().create(policy);
response.close();
}
private void createResourcePermission(String name, String resource, String... policies) {
@ -205,19 +208,21 @@ public class GroupNamePolicyTest extends AbstractAuthzTest {
permission.addResource(resource);
permission.addPolicy(policies);
getClient().authorization().permissions().resource().create(permission);
Response response = getClient().authorization().permissions().resource().create(permission);
response.close();
}
private void createResource(String name) {
AuthorizationResource authorization = getClient().authorization();
ResourceRepresentation resource = new ResourceRepresentation(name);
authorization.resources().create(resource);
Response response = authorization.resources().create(resource);
response.close();
}
private RealmResource getRealm() {
try {
return AdminClientUtil.createAdminClient().realm("authz-test");
return getAdminClient().realm("authz-test");
} catch (Exception e) {
throw new RuntimeException("Failed to create admin client");
}

View file

@ -28,6 +28,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.keycloak.admin.client.resource.AuthorizationResource;
@ -179,7 +181,8 @@ public class GroupPathPolicyTest extends AbstractAuthzTest {
policy.setGroupsClaim("groups");
policy.addGroupPath(groupPath, extendChildren);
getClient().authorization().policies().group().create(policy);
Response response = getClient().authorization().policies().group().create(policy);
response.close();
}
private void createResourcePermission(String name, String resource, String... policies) {
@ -189,19 +192,21 @@ public class GroupPathPolicyTest extends AbstractAuthzTest {
permission.addResource(resource);
permission.addPolicy(policies);
getClient().authorization().permissions().resource().create(permission);
Response response = getClient().authorization().permissions().resource().create(permission);
response.close();
}
private void createResource(String name) {
AuthorizationResource authorization = getClient().authorization();
ResourceRepresentation resource = new ResourceRepresentation(name);
authorization.resources().create(resource);
Response response = authorization.resources().create(resource);
response.close();
}
private RealmResource getRealm() {
try {
return AdminClientUtil.createAdminClient().realm("authz-test");
return getAdminClient().realm("authz-test");
} catch (Exception e) {
throw new RuntimeException("Failed to create admin client");
}

View file

@ -23,6 +23,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.keycloak.admin.client.resource.AuthorizationResource;
@ -177,7 +179,8 @@ public class RolePolicyTest extends AbstractAuthzTest {
policy.addRole(role);
}
getClient().authorization().policies().role().create(policy);
Response response = getClient().authorization().policies().role().create(policy);
response.close();
}
private void createResourcePermission(String name, String resource, String... policies) {
@ -187,19 +190,21 @@ public class RolePolicyTest extends AbstractAuthzTest {
permission.addResource(resource);
permission.addPolicy(policies);
getClient().authorization().permissions().resource().create(permission);
Response response = getClient().authorization().permissions().resource().create(permission);
response.close();
}
private void createResource(String name) {
AuthorizationResource authorization = getClient().authorization();
ResourceRepresentation resource = new ResourceRepresentation(name);
authorization.resources().create(resource);
Response response = authorization.resources().create(resource);
response.close();
}
private RealmResource getRealm() {
try {
return AdminClientUtil.createAdminClient().realm("authz-test");
return getAdminClient().realm("authz-test");
} catch (Exception e) {
throw new RuntimeException("Failed to create admin client");
}

View file

@ -2,6 +2,7 @@ package org.keycloak.testsuite.cluster;
import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.keycloak.admin.client.Keycloak;
@ -38,9 +39,9 @@ public abstract class AbstractClusterTest extends AbstractKeycloakTest {
@ArquillianResource
protected ContainerController controller;
protected Map<ContainerInfo, Keycloak> backendAdminClients = new HashMap<>();
protected static Map<ContainerInfo, Keycloak> backendAdminClients = new HashMap<>();
protected Map<ContainerInfo, KeycloakTestingClient> backendTestingClients = new HashMap<>();
protected static Map<ContainerInfo, KeycloakTestingClient> backendTestingClients = new HashMap<>();
private int currentFailNodeIndex = 0;
@ -165,6 +166,16 @@ public abstract class AbstractClusterTest extends AbstractKeycloakTest {
ContainerAssume.assumeClusteredContainer();
}
@AfterClass
public static void closeClients() {
backendAdminClients.values().forEach(Keycloak::close);
backendAdminClients.clear();
backendTestingClients.values().forEach(KeycloakTestingClient::close);
backendTestingClients.clear();
}
@Before
public void beforeClusterTest() {
failback();

View file

@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -42,8 +43,6 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
private String authServerUrl;
private Keycloak testAdminClient;
@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation realm = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
@ -62,11 +61,10 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
public void fixedHostname() throws Exception {
authServerUrl = oauth.AUTH_SERVER_ROOT;
oauth.baseUrl(authServerUrl);
testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), AuthServerTestEnricher.getAuthServerContextRoot());
oauth.clientId("direct-grant");
try {
try (Keycloak testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), AuthServerTestEnricher.getAuthServerContextRoot())) {
assertWellKnown("test", AUTH_SERVER_SCHEME + "://localhost:" + AUTH_SERVER_PORT);
configureFixedHostname(-1, -1, false);
@ -77,8 +75,8 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
assertTokenIssuer("test", AUTH_SERVER_SCHEME + "://keycloak.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
assertTokenIssuer("hostname", AUTH_SERVER_SCHEME + "://custom-domain.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
assertInitialAccessTokenFromMasterRealm("test", AUTH_SERVER_SCHEME + "://keycloak.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
assertInitialAccessTokenFromMasterRealm("hostname", AUTH_SERVER_SCHEME + "://custom-domain.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
assertInitialAccessTokenFromMasterRealm(testAdminClient,"test", AUTH_SERVER_SCHEME + "://keycloak.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
assertInitialAccessTokenFromMasterRealm(testAdminClient,"hostname", AUTH_SERVER_SCHEME + "://custom-domain.127.0.0.1.nip.io:" + AUTH_SERVER_PORT);
} finally {
clearFixedHostname();
}
@ -89,11 +87,10 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
// Make sure request are always sent with http
authServerUrl = "http://localhost:8180/auth";
oauth.baseUrl(authServerUrl);
testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), "http://localhost:8180");
oauth.clientId("direct-grant");
try {
try (Keycloak testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), "http://localhost:8180")) {
assertWellKnown("test", "http://localhost:8180");
configureFixedHostname(80, -1, false);
@ -104,8 +101,8 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
assertTokenIssuer("test", "http://keycloak.127.0.0.1.nip.io");
assertTokenIssuer("hostname", "http://custom-domain.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm("test", "http://keycloak.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm("hostname", "http://custom-domain.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm(testAdminClient,"test", "http://keycloak.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm(testAdminClient,"hostname", "http://custom-domain.127.0.0.1.nip.io");
} finally {
clearFixedHostname();
}
@ -116,11 +113,10 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
// Make sure request are always sent with http
authServerUrl = "http://localhost:8180/auth";
oauth.baseUrl(authServerUrl);
testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), "http://localhost:8180");
oauth.clientId("direct-grant");
try {
try (Keycloak testAdminClient = AdminClientUtil.createAdminClient(suiteContext.isAdapterCompatTesting(), "http://localhost:8180")) {
assertWellKnown("test", "http://localhost:8180");
configureFixedHostname(-1, 443, true);
@ -131,14 +127,14 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
assertTokenIssuer("test", "https://keycloak.127.0.0.1.nip.io");
assertTokenIssuer("hostname", "https://custom-domain.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm("test", "https://keycloak.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm("hostname", "https://custom-domain.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm(testAdminClient, "test", "https://keycloak.127.0.0.1.nip.io");
assertInitialAccessTokenFromMasterRealm(testAdminClient, "hostname", "https://custom-domain.127.0.0.1.nip.io");
} finally {
clearFixedHostname();
}
}
private void assertInitialAccessTokenFromMasterRealm(String realm, String expectedBaseUrl) throws JWSInputException, ClientRegistrationException {
private void assertInitialAccessTokenFromMasterRealm(Keycloak testAdminClient, String realm, String expectedBaseUrl) throws JWSInputException, ClientRegistrationException {
ClientInitialAccessCreatePresentation rep = new ClientInitialAccessCreatePresentation();
rep.setCount(1);
rep.setExpiration(10000);

View file

@ -17,6 +17,7 @@
package org.keycloak.testsuite.broker;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@ -33,7 +34,6 @@ import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.services.managers.RealmManager;
import org.keycloak.testsuite.KeycloakServer;
import org.keycloak.testsuite.rule.AbstractKeycloakRule;
import org.openqa.selenium.NoSuchElementException;
import java.util.List;
@ -97,6 +97,12 @@ public class OIDCKeycloakServerBrokerWithConsentTest extends AbstractIdentityPro
realmWithBroker.update(realmRep);
}
@AfterClass
public static void after() {
keycloak1.close();
keycloak2.close();
}
@Override
protected String getProviderId() {

View file

@ -113,21 +113,22 @@ public class BrokenUserStorageTest {
// make sure we can list components and delete provider as this is an admin console operation
Keycloak keycloakAdmin = Keycloak.getInstance(AUTH_SERVER_URL, "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID);
RealmResource master = keycloakAdmin.realms().realm("master");
List<ComponentRepresentation> components = master.components().query(masterId, UserStorageProvider.class.getName());
boolean found = false;
for (ComponentRepresentation rep : components) {
if (rep.getName().equals("bad-provider-id")) {
found = true;
try (Keycloak keycloakAdmin = Keycloak.getInstance(AUTH_SERVER_URL, "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID)) {
RealmResource master = keycloakAdmin.realms().realm("master");
List<ComponentRepresentation> components = master.components().query(masterId, UserStorageProvider.class.getName());
boolean found = false;
for (ComponentRepresentation rep : components) {
if (rep.getName().equals("bad-provider-id")) {
found = true;
}
}
Assert.assertTrue(found);
master.components().component(component.getId()).remove();
List<ComponentRepresentation> components2 = master.components().query(masterId, UserStorageProvider.class.getName());
Assert.assertEquals(components.size() - 1, components2.size());
}
Assert.assertTrue(found);
master.components().component(component.getId()).remove();
List<ComponentRepresentation> components2 = master.components().query(masterId, UserStorageProvider.class.getName());
Assert.assertEquals(components.size() - 1, components2.size());
}
@After

View file

@ -202,18 +202,20 @@ public class AdapterTestStrategy extends ExternalResource {
Assert.assertTrue(pageSource.contains("iPhone") && pageSource.contains("iPad"));
// View stats
List<Map<String, String>> stats = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID).realm("demo").getClientSessionStats();
Map<String, String> customerPortalStats = null;
Map<String, String> productPortalStats = null;
for (Map<String, String> s : stats) {
if (s.get("clientId").equals("customer-portal")) {
customerPortalStats = s;
} else if (s.get("clientId").equals("product-portal")) {
productPortalStats = s;
try (Keycloak adminClient = Keycloak.getInstance("http://localhost:8081/auth", "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID)) {
List<Map<String, String>> stats = adminClient.realm("demo").getClientSessionStats();
Map<String, String> customerPortalStats = null;
Map<String, String> productPortalStats = null;
for (Map<String, String> s : stats) {
if (s.get("clientId").equals("customer-portal")) {
customerPortalStats = s;
} else if (s.get("clientId").equals("product-portal")) {
productPortalStats = s;
}
}
Assert.assertEquals(1, Integer.parseInt(customerPortalStats.get("active")));
Assert.assertEquals(1, Integer.parseInt(productPortalStats.get("active")));
}
Assert.assertEquals(1, Integer.parseInt(customerPortalStats.get("active")));
Assert.assertEquals(1, Integer.parseInt(productPortalStats.get("active")));
// test logout
String logoutUri = OIDCLoginProtocolService.logoutUrl(UriBuilder.fromUri(AUTH_SERVER_URL))
@ -603,15 +605,16 @@ public class AdapterTestStrategy extends ExternalResource {
loginAndCheckSession(driver, loginPage);
// logout mposolda with admin client
Keycloak keycloakAdmin = Keycloak.getInstance(AUTH_SERVER_URL, "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID);
UserRepresentation mposolda = keycloakAdmin.realm("demo").users().search("mposolda", null, null, null, null, null).get(0);
keycloakAdmin.realm("demo").users().get(mposolda.getId()).logout();
try (Keycloak keycloakAdmin = Keycloak.getInstance(AUTH_SERVER_URL, "master", "admin", "admin", Constants.ADMIN_CLI_CLIENT_ID)) {
UserRepresentation mposolda = keycloakAdmin.realm("demo").users().search("mposolda", null, null, null, null, null).get(0);
keycloakAdmin.realm("demo").users().get(mposolda.getId()).logout();
// bburke should be still logged with original httpSession in our browser window
driver.navigate().to(APP_SERVER_BASE_URL + "/session-portal");
Assert.assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/session-portal" + slash);
String pageSource = driver.getPageSource();
Assert.assertTrue(pageSource.contains("Counter=3"));
// bburke should be still logged with original httpSession in our browser window
driver.navigate().to(APP_SERVER_BASE_URL + "/session-portal");
Assert.assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/session-portal" + slash);
String pageSource = driver.getPageSource();
Assert.assertTrue(pageSource.contains("Counter=3"));
}
}
/**