Merge pull request #3940 from pdrozd/KEYCLOAK-4304

KEYCLOAK-4304 Updated Kerberos tests to be able to run them on differ…
This commit is contained in:
Pavel Drozd 2017-03-13 15:49:01 +01:00 committed by GitHub
commit 71a9d51c56
4 changed files with 25 additions and 6 deletions

View file

@ -73,4 +73,8 @@ public class KerberosRule extends LDAPRule {
public boolean isCaseSensitiveLogin() {
return ldapTestConfiguration.isCaseSensitiveLogin();
}
public boolean isStartEmbeddedLdapServer() {
return ldapTestConfiguration.isStartEmbeddedLdapServer();
}
}

View file

@ -17,6 +17,9 @@
package org.keycloak.testsuite.federation.kerberos;
import static org.keycloak.testsuite.admin.AbstractAdminTest.loadJson;
import static org.keycloak.testsuite.admin.ApiUtil.findClientByClientId;
import java.net.URI;
import java.security.Principal;
import java.util.Hashtable;
@ -44,6 +47,7 @@ import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -75,8 +79,6 @@ import org.keycloak.testsuite.auth.page.AuthRealm;
import org.keycloak.testsuite.pages.AccountPasswordPage;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.util.OAuthClient;
import static org.keycloak.testsuite.admin.AbstractAdminTest.loadJson;
import static org.keycloak.testsuite.admin.ApiUtil.findClientByClientId;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -102,6 +104,8 @@ public abstract class AbstractKerberosTest extends AbstractAuthTest {
protected abstract void setKrb5ConfPath();
protected abstract boolean isStartEmbeddedLdapServer();
@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation realmRep = loadJson(getClass().getResourceAsStream("/kerberos/kerberosrealm.json"), RealmRepresentation.class);
@ -256,7 +260,8 @@ public abstract class AbstractKerberosTest extends AbstractAuthTest {
@Test
public void credentialDelegationTest() throws Exception {
// Add kerberos delegation credential mapper
Assume.assumeTrue("Ignoring test as the embedded server is not started", isStartEmbeddedLdapServer());
// Add kerberos delegation credential mapper
ProtocolMapperModel protocolMapper = UserSessionNoteMapper.createClaimMapper(KerberosConstants.GSS_DELEGATION_CREDENTIAL_DISPLAY_NAME,
KerberosConstants.GSS_DELEGATION_CREDENTIAL,
KerberosConstants.GSS_DELEGATION_CREDENTIAL, "String",

View file

@ -76,6 +76,11 @@ public class KerberosLdapTest extends AbstractKerberosTest {
return kerberosRule.isCaseSensitiveLogin();
}
@Override
protected boolean isStartEmbeddedLdapServer() {
return kerberosRule.isStartEmbeddedLdapServer();
}
@Override
protected void setKrb5ConfPath() {

View file

@ -79,6 +79,11 @@ public class KerberosStandaloneTest extends AbstractKerberosTest {
return kerberosRule.isCaseSensitiveLogin();
}
@Override
protected boolean isStartEmbeddedLdapServer() {
return kerberosRule.isStartEmbeddedLdapServer();
}
@Override
protected void setKrb5ConfPath() {
@ -90,7 +95,7 @@ public class KerberosStandaloneTest extends AbstractKerberosTest {
spnegoLoginTestImpl();
// Assert user was imported and hasn't any required action on him. Profile info is synced from LDAP
assertUser("hnelson", "hnelson@keycloak.org", null, null, false);
assertUser("hnelson", "hnelson@" + kerberosRule.getConfig().get(KerberosConstants.KERBEROS_REALM).toLowerCase(), null, null, false);
}
@ -108,11 +113,11 @@ public class KerberosStandaloneTest extends AbstractKerberosTest {
Assert.assertEquals(200, spnegoResponse.getStatus());
String responseText = spnegoResponse.readEntity(String.class);
Assert.assertTrue(responseText.contains("You need to update your user profile to activate your account."));
Assert.assertTrue(responseText.contains("hnelson@keycloak.org"));
Assert.assertTrue(responseText.contains("hnelson@" + kerberosRule.getConfig().get(KerberosConstants.KERBEROS_REALM).toLowerCase()));
spnegoResponse.close();
// Assert user was imported and has required action on him
assertUser("hnelson", "hnelson@keycloak.org", null, null, true);
assertUser("hnelson", "hnelson@" + kerberosRule.getConfig().get(KerberosConstants.KERBEROS_REALM).toLowerCase(), null, null, true);
// Switch updateProfileOnFirstLogin to off
kerberosProvider.getConfig().putSingle(KerberosConstants.UPDATE_PROFILE_FIRST_LOGIN, "false");