KEYCLOAK-2197 Fix broker tests to work with sybase. Added LoggingRule

This commit is contained in:
mposolda 2015-12-03 11:52:46 +01:00
parent 73cf2404ff
commit 45c490b640
5 changed files with 74 additions and 13 deletions

View file

@ -51,6 +51,7 @@ import org.keycloak.testsuite.pages.LoginUpdateProfilePage;
import org.keycloak.testsuite.pages.OAuthGrantPage; import org.keycloak.testsuite.pages.OAuthGrantPage;
import org.keycloak.testsuite.pages.VerifyEmailPage; import org.keycloak.testsuite.pages.VerifyEmailPage;
import org.keycloak.testsuite.rule.GreenMailRule; import org.keycloak.testsuite.rule.GreenMailRule;
import org.keycloak.testsuite.rule.LoggingRule;
import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebResource;
import org.keycloak.testsuite.rule.WebRule; import org.keycloak.testsuite.rule.WebRule;
import org.keycloak.util.JsonSerialization; import org.keycloak.util.JsonSerialization;
@ -93,6 +94,9 @@ public abstract class AbstractIdentityProviderTest {
@ClassRule @ClassRule
public static BrokerKeyCloakRule brokerServerRule = new BrokerKeyCloakRule(); public static BrokerKeyCloakRule brokerServerRule = new BrokerKeyCloakRule();
@Rule
public LoggingRule loggingRule = new LoggingRule(this);
@Rule @Rule
public WebRule webRule = new WebRule(this); public WebRule webRule = new WebRule(this);

View file

@ -83,13 +83,15 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
*/ */
@Test @Test
public void testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled() throws IOException, MessagingException { public void testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled() throws IOException, MessagingException {
getRealm().setVerifyEmail(true); RealmModel realm = getRealm();
realm.setVerifyEmail(true);
setUpdateProfileFirstLogin(realm, IdentityProviderRepresentation.UPFLM_OFF);
brokerServerRule.stopSession(this.session, true); brokerServerRule.stopSession(this.session, true);
this.session = brokerServerRule.startSession(); this.session = brokerServerRule.startSession();
IdentityProviderModel identityProviderModel = getIdentityProviderModel(); IdentityProviderModel identityProviderModel = getIdentityProviderModel();
try { try {
setUpdateProfileFirstLogin(IdentityProviderRepresentation.UPFLM_OFF);
identityProviderModel.setTrustEmail(false); identityProviderModel.setTrustEmail(false);
UserModel federatedUser = assertSuccessfulAuthenticationWithEmailVerification(identityProviderModel, "test-user", "test-user@localhost", false); UserModel federatedUser = assertSuccessfulAuthenticationWithEmailVerification(identityProviderModel, "test-user", "test-user@localhost", false);
@ -152,13 +154,15 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
*/ */
@Test @Test
public void testSuccessfulAuthenticationWithoutUpdateProfile_emailNotProvided_emailVerifyEnabled() { public void testSuccessfulAuthenticationWithoutUpdateProfile_emailNotProvided_emailVerifyEnabled() {
getRealm().setVerifyEmail(true); RealmModel realm = getRealm();
realm.setVerifyEmail(true);
setUpdateProfileFirstLogin(realm, IdentityProviderRepresentation.UPFLM_OFF);
brokerServerRule.stopSession(this.session, true); brokerServerRule.stopSession(this.session, true);
this.session = brokerServerRule.startSession(); this.session = brokerServerRule.startSession();
try { try {
IdentityProviderModel identityProviderModel = getIdentityProviderModel(); IdentityProviderModel identityProviderModel = getIdentityProviderModel();
setUpdateProfileFirstLogin(IdentityProviderRepresentation.UPFLM_OFF);
UserModel federatedUser = assertSuccessfulAuthentication(identityProviderModel, "test-user-noemail", null, false); UserModel federatedUser = assertSuccessfulAuthentication(identityProviderModel, "test-user-noemail", null, false);
@ -174,8 +178,10 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
*/ */
@Test @Test
public void testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled_emailTrustEnabled() { public void testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled_emailTrustEnabled() {
getRealm().setVerifyEmail(true); RealmModel realmWithBroker = getRealm();
setUpdateProfileFirstLogin(IdentityProviderRepresentation.UPFLM_OFF); realmWithBroker.setVerifyEmail(true);
setUpdateProfileFirstLogin(realmWithBroker, IdentityProviderRepresentation.UPFLM_OFF);
brokerServerRule.stopSession(this.session, true); brokerServerRule.stopSession(this.session, true);
this.session = brokerServerRule.startSession(); this.session = brokerServerRule.startSession();
@ -201,13 +207,15 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
*/ */
@Test @Test
public void testSuccessfulAuthentication_emailTrustEnabled_emailVerifyEnabled_emailUpdatedOnFirstLogin() throws IOException, MessagingException { public void testSuccessfulAuthentication_emailTrustEnabled_emailVerifyEnabled_emailUpdatedOnFirstLogin() throws IOException, MessagingException {
getRealm().setVerifyEmail(true); RealmModel realm = getRealm();
realm.setVerifyEmail(true);
setUpdateProfileFirstLogin(realm, IdentityProviderRepresentation.UPFLM_ON);
brokerServerRule.stopSession(this.session, true); brokerServerRule.stopSession(this.session, true);
this.session = brokerServerRule.startSession(); this.session = brokerServerRule.startSession();
IdentityProviderModel identityProviderModel = getIdentityProviderModel(); IdentityProviderModel identityProviderModel = getIdentityProviderModel();
try { try {
setUpdateProfileFirstLogin(IdentityProviderRepresentation.UPFLM_ON);
identityProviderModel.setTrustEmail(true); identityProviderModel.setTrustEmail(true);
UserModel user = assertSuccessfulAuthenticationWithEmailVerification(identityProviderModel, "test-user", "new@email.com", true); UserModel user = assertSuccessfulAuthenticationWithEmailVerification(identityProviderModel, "test-user", "new@email.com", true);
@ -220,14 +228,15 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
@Test @Test
public void testSuccessfulAuthenticationWithoutUpdateProfile_newUser_emailAsUsername() { public void testSuccessfulAuthenticationWithoutUpdateProfile_newUser_emailAsUsername() {
RealmModel realm = getRealm();
realm.setRegistrationEmailAsUsername(true);
setUpdateProfileFirstLogin(realm, IdentityProviderRepresentation.UPFLM_OFF);
getRealm().setRegistrationEmailAsUsername(true);
brokerServerRule.stopSession(this.session, true); brokerServerRule.stopSession(this.session, true);
this.session = brokerServerRule.startSession(); this.session = brokerServerRule.startSession();
try { try {
IdentityProviderModel identityProviderModel = getIdentityProviderModel(); IdentityProviderModel identityProviderModel = getIdentityProviderModel();
setUpdateProfileFirstLogin(IdentityProviderRepresentation.UPFLM_OFF);
authenticateWithIdentityProvider(identityProviderModel, "test-user", false); authenticateWithIdentityProvider(identityProviderModel, "test-user", false);
@ -238,7 +247,7 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent
session = brokerServerRule.startSession(); session = brokerServerRule.startSession();
// check correct user is created with email as username and bound to correct federated identity // check correct user is created with email as username and bound to correct federated identity
RealmModel realm = getRealm(); realm = getRealm();
UserModel federatedUser = session.users().getUserByUsername("test-user@localhost", realm); UserModel federatedUser = session.users().getUserByUsername("test-user@localhost", realm);

View file

@ -11,6 +11,7 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.ClientSessionModel; import org.keycloak.models.ClientSessionModel;
@ -26,6 +27,7 @@ import org.keycloak.services.managers.UserManager;
import org.keycloak.services.managers.UserSessionManager; import org.keycloak.services.managers.UserSessionManager;
import org.keycloak.testsuite.rule.KeycloakRule; import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.common.util.Time; import org.keycloak.common.util.Time;
import org.keycloak.testsuite.rule.LoggingRule;
/** /**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -35,6 +37,9 @@ public class UserSessionProviderOfflineTest {
@ClassRule @ClassRule
public static KeycloakRule kc = new KeycloakRule(); public static KeycloakRule kc = new KeycloakRule();
@Rule
public LoggingRule loggingRule = new LoggingRule(this);
private KeycloakSession session; private KeycloakSession session;
private RealmModel realm; private RealmModel realm;
private UserSessionManager sessionManager; private UserSessionManager sessionManager;

View file

@ -0,0 +1,38 @@
package org.keycloak.testsuite.rule;
import org.jboss.logging.Logger;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
*/
public class LoggingRule implements TestRule {
private final Logger log;
public LoggingRule(Object test) {
log = Logger.getLogger(test.getClass());
}
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
log.debugf("Before %s", description.getMethodName());
try {
base.evaluate();
} finally {
log.debugf("After %s", description.getMethodName());
}
}
};
}
}

View file

@ -14,6 +14,10 @@ log4j.logger.org.keycloak=info
# log4j.logger.org.keycloak.provider.ProviderManager=debug # log4j.logger.org.keycloak.provider.ProviderManager=debug
# log4j.logger.org.keycloak.provider.FileSystemProviderLoaderFactory=debug # log4j.logger.org.keycloak.provider.FileSystemProviderLoaderFactory=debug
# Broker logging
keycloak.testsuite.logging.level=info
log4j.logger.org.keycloak.testsuite=${keycloak.testsuite.logging.level}
# Liquibase updates logged with "info" by default. Logging level can be changed by system property "keycloak.liquibase.logging.level" # Liquibase updates logged with "info" by default. Logging level can be changed by system property "keycloak.liquibase.logging.level"
keycloak.liquibase.logging.level=info keycloak.liquibase.logging.level=info
log4j.logger.org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider=${keycloak.liquibase.logging.level} log4j.logger.org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider=${keycloak.liquibase.logging.level}
@ -30,7 +34,7 @@ log4j.logger.org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterP
# log4j.logger.org.keycloak.migration.MigrationModelManager=debug # log4j.logger.org.keycloak.migration.MigrationModelManager=debug
# Enable to view kerberos/spnego logging # Enable to view kerberos/spnego logging
# log4j.logger.org.keycloak.broker.kerberos=trace # log4j.logger.org.keycloak.federation.kerberos=trace
# Enable to view detailed AS REQ and TGS REQ requests to embedded Kerberos server # Enable to view detailed AS REQ and TGS REQ requests to embedded Kerberos server
# log4j.logger.org.apache.directory.server.kerberos=debug # log4j.logger.org.apache.directory.server.kerberos=debug
@ -39,4 +43,5 @@ log4j.logger.org.xnio=off
log4j.logger.org.hibernate=off log4j.logger.org.hibernate=off
log4j.logger.org.jboss.resteasy=warn log4j.logger.org.jboss.resteasy=warn
log4j.logger.org.apache.directory.api=warn log4j.logger.org.apache.directory.api=warn
log4j.logger.org.apache.directory.server.core=warn log4j.logger.org.apache.directory.server.core=warn
log4j.logger.org.apache.directory.server.ldap.LdapProtocolHandler=error