Logout confirm page is failing to log the user out on auth-server-wildfly
Fixes #11753
This commit is contained in:
parent
3aefb59d40
commit
0fef4305b6
2 changed files with 66 additions and 19 deletions
|
@ -23,7 +23,7 @@ import org.keycloak.common.util.KeycloakUriBuilder;
|
||||||
import org.keycloak.testsuite.arquillian.SuiteContext;
|
import org.keycloak.testsuite.arquillian.SuiteContext;
|
||||||
import org.keycloak.testsuite.util.DroneUtils;
|
import org.keycloak.testsuite.util.DroneUtils;
|
||||||
import org.keycloak.testsuite.util.OAuthClient;
|
import org.keycloak.testsuite.util.OAuthClient;
|
||||||
import org.openqa.selenium.By;
|
import org.keycloak.testsuite.util.WaitUtils;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -44,6 +44,7 @@ public abstract class AbstractPage {
|
||||||
protected OAuthClient oauth;
|
protected OAuthClient oauth;
|
||||||
|
|
||||||
public void assertCurrent() {
|
public void assertCurrent() {
|
||||||
|
WaitUtils.waitForPageToLoad();
|
||||||
String name = getClass().getSimpleName();
|
String name = getClass().getSimpleName();
|
||||||
Assert.assertTrue("Expected " + name + " but was " + DroneUtils.getCurrentDriver().getTitle() + " (" + DroneUtils.getCurrentDriver().getCurrentUrl() + ")",
|
Assert.assertTrue("Expected " + name + " but was " + DroneUtils.getCurrentDriver().getTitle() + " (" + DroneUtils.getCurrentDriver().getCurrentUrl() + ")",
|
||||||
isCurrent());
|
isCurrent());
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.keycloak.testsuite.broker;
|
package org.keycloak.testsuite.broker;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.jboss.arquillian.graphene.page.Page;
|
import org.jboss.arquillian.graphene.page.Page;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
@ -65,9 +64,11 @@ import javax.ws.rs.core.UriBuilderException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID;
|
||||||
import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient;
|
import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient;
|
||||||
import static org.keycloak.testsuite.admin.ApiUtil.resetUserPassword;
|
import static org.keycloak.testsuite.admin.ApiUtil.resetUserPassword;
|
||||||
import static org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL;
|
import static org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL;
|
||||||
|
@ -75,6 +76,8 @@ import static org.keycloak.testsuite.broker.BrokerTestTools.encodeUrl;
|
||||||
import static org.keycloak.testsuite.broker.BrokerTestTools.getConsumerRoot;
|
import static org.keycloak.testsuite.broker.BrokerTestTools.getConsumerRoot;
|
||||||
import static org.keycloak.testsuite.broker.BrokerTestTools.getProviderRoot;
|
import static org.keycloak.testsuite.broker.BrokerTestTools.getProviderRoot;
|
||||||
import static org.keycloak.testsuite.broker.BrokerTestTools.waitForPage;
|
import static org.keycloak.testsuite.broker.BrokerTestTools.waitForPage;
|
||||||
|
import static org.keycloak.testsuite.util.ServerURLs.getAuthServerContextRoot;
|
||||||
|
import static org.keycloak.testsuite.util.ServerURLs.removeDefaultPorts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No test methods there. Just some useful common functionality
|
* No test methods there. Just some useful common functionality
|
||||||
|
@ -314,28 +317,71 @@ public abstract class AbstractBaseBrokerTest extends AbstractKeycloakTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void logoutFromRealm(String contextRoot, String realm, String initiatingIdp, String idTokenHint) {
|
protected void logoutFromRealm(String contextRoot, String realm, String initiatingIdp, String idTokenHint) {
|
||||||
OAuthClient.LogoutUrlBuilder builder = oauth.realm(realm)
|
logoutFromRealm(contextRoot, realm, initiatingIdp, idTokenHint, null);
|
||||||
.getLogoutUrl()
|
}
|
||||||
.initiatingIdp(initiatingIdp);
|
|
||||||
|
|
||||||
if (idTokenHint != null) {
|
protected void logoutFromRealm(String contextRoot, String realm, String initiatingIdp, String idTokenHint, String clientId) {
|
||||||
builder
|
logoutFromRealm(contextRoot, realm, initiatingIdp, idTokenHint, clientId, null);
|
||||||
.postLogoutRedirectUri(encodeUrl(getAccountUrl(contextRoot, realm)))
|
}
|
||||||
.idTokenHint(idTokenHint);
|
|
||||||
|
// Completely logout from realm and confirm logout if present
|
||||||
|
protected void logoutFromRealm(String contextRoot, String realm, String initiatingIdp, String idTokenHint, String clientId, String redirectUri) {
|
||||||
|
final String defaultRedirectUri = redirectUri != null ? redirectUri : getAccountUrl(contextRoot, realm);
|
||||||
|
final String defaultClientId = (idTokenHint == null && clientId == null) ? ACCOUNT_MANAGEMENT_CLIENT_ID : clientId;
|
||||||
|
|
||||||
|
executeLogoutFromRealm(contextRoot, realm, initiatingIdp, idTokenHint, defaultClientId, defaultRedirectUri);
|
||||||
|
checkLogoutConfirmation(realm, idTokenHint, defaultClientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only execute the logout without logout confirmation
|
||||||
|
protected void executeLogoutFromRealm(String contextRoot, String realm, String initiatingIdp, String idTokenHint, String clientId, String redirectUri) {
|
||||||
|
final boolean isDifferentContext = !Objects.equals(OAuthClient.SERVER_ROOT, removeDefaultPorts(contextRoot));
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (isDifferentContext) {
|
||||||
|
OAuthClient.updateURLs(contextRoot);
|
||||||
|
OAuthClient.updateAppRootRealm(realm);
|
||||||
|
oauth.init(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
final OAuthClient.LogoutUrlBuilder builder = oauth.realm(realm)
|
||||||
|
.getLogoutUrl()
|
||||||
|
.idTokenHint(idTokenHint)
|
||||||
|
.clientId(clientId)
|
||||||
|
.initiatingIdp(initiatingIdp);
|
||||||
|
|
||||||
|
if (clientId != null || idTokenHint != null) {
|
||||||
|
builder.postLogoutRedirectUri(encodeUrl(redirectUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
String logoutUrl = builder.build();
|
||||||
|
driver.navigate().to(logoutUrl);
|
||||||
|
} finally {
|
||||||
|
if (isDifferentContext) {
|
||||||
|
OAuthClient.updateURLs(getAuthServerContextRoot());
|
||||||
|
oauth.init(driver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String logoutUrl = builder.build();
|
// Check whether the logout confirmation is present; if yes, confirm the logout and verify the current page
|
||||||
driver.navigate().to(logoutUrl);
|
private void checkLogoutConfirmation(String realm, String idTokenHint, String clientId) {
|
||||||
|
if (logoutConfirmPage.isCurrent()) {
|
||||||
// Needs to confirm logout if id_token_hint was not provided
|
confirmLogout();
|
||||||
if (idTokenHint == null) {
|
if (idTokenHint != null || clientId != null) {
|
||||||
logoutConfirmPage.assertCurrent();
|
assertLoginPage(realm);
|
||||||
logoutConfirmPage.confirmLogout();
|
} else {
|
||||||
infoPage.assertCurrent();
|
infoPage.assertCurrent();
|
||||||
driver.navigate().to(getAccountUrl(contextRoot, realm));
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void confirmLogout() {
|
||||||
|
logoutConfirmPage.assertCurrent();
|
||||||
|
logoutConfirmPage.confirmLogout();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertLoginPage(String realm) {
|
||||||
try {
|
try {
|
||||||
Retry.execute(() -> {
|
Retry.execute(() -> {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue