From 88583362ad07791b14c3579d06f5b76256bd9939 Mon Sep 17 00:00:00 2001 From: wyvie Date: Wed, 18 May 2016 14:46:20 +0200 Subject: [PATCH] KEYCLOAK-3000: fixed the saml brokering tests --- .../testsuite/broker/AbstractBrokerTest.java | 47 +++++++++++++++---- .../testsuite/broker/KcSamlBrokerTest.java | 2 - 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/AbstractBrokerTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/AbstractBrokerTest.java index a6a5c06639..aa44d85de2 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/AbstractBrokerTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/AbstractBrokerTest.java @@ -14,6 +14,8 @@ import org.keycloak.testsuite.Assert; import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.UpdateAccountInformationPage; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.List; import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient; @@ -113,22 +115,37 @@ public abstract class AbstractBrokerTest extends AbstractKeycloakTest { return identityProviderRepresentation; } + private void waitForPage(String title) { + long startAt = System.currentTimeMillis(); + + while (!driver.getTitle().toLowerCase().contains(title) + && System.currentTimeMillis() - startAt < 200) { + try { + Thread.sleep(5); + } catch (InterruptedException ignore) {} + } + } + @Test public void logInAsUserInIDP() { - driver.navigate().to(getAuthRoot() + "/auth/realms/" + consumerRealmName() + "/account"); + driver.navigate().to(getAccountUrl(consumerRealmName())); log.debug("Clicking social " + getIDPAlias()); accountLoginPage.clickSocial(getIDPAlias()); + if (!driver.getCurrentUrl().contains("/auth/realms/" + providerRealmName() + "/")) { + log.debug("Not on provider realm page, url: " + driver.getCurrentUrl()); + } + Assert.assertTrue("Driver should be on the provider realm page right now", driver.getCurrentUrl().contains("/auth/realms/" + providerRealmName() + "/")); log.debug("Logging in"); accountLoginPage.login(getUserLogin(), getUserPassword()); - Assert.assertTrue("We must be on update user profile page right now", - updateAccountInformationPage.isCurrent()); + waitForPage("update account information"); + Assert.assertTrue(updateAccountInformationPage.isCurrent()); Assert.assertTrue("We must be on correct realm right now", driver.getCurrentUrl().contains("/auth/realms/" + consumerRealmName() + "/")); @@ -157,23 +174,33 @@ public abstract class AbstractBrokerTest extends AbstractKeycloakTest { protected void testSingleLogout() { log.debug("Testing single log out"); - driver.navigate().to(getAuthRoot() + "/auth/realms/" + providerRealmName() + "/account"); + driver.navigate().to(getAccountUrl(providerRealmName())); Assert.assertTrue("Should be logged in the account page", driver.getTitle().endsWith("Account Management")); + String encodedAccount; + try { + encodedAccount = URLEncoder.encode(getAccountUrl(providerRealmName()), "UTF-8"); + } catch (UnsupportedEncodingException e) { + encodedAccount = getAccountUrl(providerRealmName()); + } + driver.navigate().to(getAuthRoot() + "/auth/realms/" + providerRealmName() + "/protocol/" + "openid-connect" - + "/logout"); + + "/logout?redirect_uri=" + encodedAccount); - driver.navigate().to(getAuthRoot() + "/auth/realms/" + providerRealmName() + "/account"); + waitForPage("log in to " + providerRealmName()); - Assert.assertTrue("Should be on login page", driver.getTitle().startsWith("Log in to")); Assert.assertTrue("Should be on " + providerRealmName() + " realm", driver.getCurrentUrl().contains("/auth/realms/" + providerRealmName())); - driver.navigate().to(getAuthRoot() + "/auth/realms/" + consumerRealmName() + "/account"); + driver.navigate().to(getAccountUrl(consumerRealmName())); - Assert.assertTrue("Should be on login page", driver.getTitle().startsWith("Log in to")); - Assert.assertTrue("Should be on " + consumerRealmName() + " realm", driver.getCurrentUrl().contains("/auth/realms/" + consumerRealmName())); + Assert.assertTrue("Should be on " + consumerRealmName() + " realm on login page", + driver.getCurrentUrl().contains("/auth/realms/" + consumerRealmName() + "/protocol/openid-connect/")); + } + + private String getAccountUrl(String realmName) { + return getAuthRoot() + "/auth/realms/" + realmName + "/account"; } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcSamlBrokerTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcSamlBrokerTest.java index 7a8fb9ceb3..cdacaa7874 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcSamlBrokerTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/broker/KcSamlBrokerTest.java @@ -1,6 +1,5 @@ package org.keycloak.testsuite.broker; -import org.junit.Ignore; import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.IdentityProviderRepresentation; import org.keycloak.representations.idm.ProtocolMapperRepresentation; @@ -13,7 +12,6 @@ import java.util.Map; import static org.keycloak.testsuite.broker.BrokerTestConstants.*; -@Ignore public class KcSamlBrokerTest extends AbstractBrokerTest { @Override