KEYCLOAK-11754 Prevent AbstractKeycloakTest from inititating backchannel logout on cleanup

This commit is contained in:
stianst 2019-10-16 10:42:10 +02:00 committed by Stian Thorgersen
parent 9cb2f1afdc
commit 31ed01a6de
2 changed files with 15 additions and 5 deletions

View file

@ -77,6 +77,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Scanner; import java.util.Scanner;
import java.util.stream.Collectors;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -210,11 +211,8 @@ public abstract class AbstractKeycloakTest {
} }
} else { } else {
log.info("calling all TestCleanup"); log.info("calling all TestCleanup");
// Logout all users after the test // Remove all sessions
List<RealmRepresentation> realms = testContext.getTestRealmReps(); testContext.getTestRealmReps().stream().forEach((r)->testingClient.testing().removeUserSessions(r.getRealm()));
for (RealmRepresentation realm : realms) {
adminClient.realm(realm.getRealm()).logoutAll();
}
// Cleanup objects // Cleanup objects
for (TestCleanup cleanup : testContext.getCleanups().values()) { for (TestCleanup cleanup : testContext.getCleanups().values()) {

View file

@ -95,6 +95,8 @@ public class MultiTenancyTest extends AbstractServletsAdapterTest {
doTenantRequests("tenant1", false); doTenantRequests("tenant1", false);
doTenantRequests("tenant2", true); doTenantRequests("tenant2", true);
logout("tenant1");
} }
/** /**
@ -125,6 +127,8 @@ public class MultiTenancyTest extends AbstractServletsAdapterTest {
driver.navigate().to(tenantPage.getTenantRealmUrl("tenant2")); driver.navigate().to(tenantPage.getTenantRealmUrl("tenant2"));
URLAssert.assertCurrentUrlStartsWith(authServerPage.toString()); URLAssert.assertCurrentUrlStartsWith(authServerPage.toString());
logout("tenant1");
} }
private void doTenantRequests(String tenant, boolean logout) { private void doTenantRequests(String tenant, boolean logout) {
@ -150,4 +154,12 @@ public class MultiTenancyTest extends AbstractServletsAdapterTest {
} }
log.debug("---------------------------------------------------------------------------------------"); log.debug("---------------------------------------------------------------------------------------");
} }
private void logout(String tenant) {
String tenantLoginUrl = OIDCLoginProtocolService.authUrl(UriBuilder.fromUri(authServerPage.getAuthRoot())).build(tenant).toString();
URL tenantUrl = tenantPage.getTenantRealmUrl(tenant);
driver.navigate().to(tenantUrl + "/logout");
Assert.assertFalse(driver.getPageSource().contains("Username: bburke@redhat.com"));
Assert.assertTrue(driver.getCurrentUrl().startsWith(tenantLoginUrl));
}
} }