Adding central time offset reset in model tests as it was missing for AuthenticationSessionTest and UserSessionPersisterProviderTest
Also adding try/finally in other places in the integration tests where it was missing. Closes #12530
This commit is contained in:
parent
39cff0750c
commit
71e7982a49
4 changed files with 46 additions and 36 deletions
|
@ -142,6 +142,7 @@ public class UserSessionProviderTest extends AbstractTestRealmKeycloakTest {
|
||||||
UserSessionModel[] sessions = createSessions(session);
|
UserSessionModel[] sessions = createSessions(session);
|
||||||
|
|
||||||
Time.setOffset(100);
|
Time.setOffset(100);
|
||||||
|
try {
|
||||||
|
|
||||||
UserSessionModel userSession = session.sessions().getUserSession(realm, sessions[0].getId());
|
UserSessionModel userSession = session.sessions().getUserSession(realm, sessions[0].getId());
|
||||||
assertSession(userSession, session.users().getUserByUsername(realm, "user1"), "127.0.0.1", started, started, "test-app", "third-party");
|
assertSession(userSession, session.users().getUserByUsername(realm, "user1"), "127.0.0.1", started, started, "test-app", "third-party");
|
||||||
|
@ -150,9 +151,10 @@ public class UserSessionProviderTest extends AbstractTestRealmKeycloakTest {
|
||||||
|
|
||||||
userSession = session.sessions().getUserSession(realm, sessions[0].getId());
|
userSession = session.sessions().getUserSession(realm, sessions[0].getId());
|
||||||
assertSession(userSession, session.users().getUserByUsername(realm, "user2"), "127.0.0.6", started + 100, started + 100);
|
assertSession(userSession, session.users().getUserByUsername(realm, "user2"), "127.0.0.6", started + 100, started + 100);
|
||||||
|
} finally {
|
||||||
Time.setOffset(0);
|
Time.setOffset(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ModelTest
|
@ModelTest
|
||||||
|
|
|
@ -1077,8 +1077,12 @@ public class ClientAuthSignedJWTTest extends AbstractKeycloakTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Time.setOffset(tokenTimeOffset);
|
Time.setOffset(tokenTimeOffset);
|
||||||
String jwt = jwtProvider.createSignedRequestToken(app1.getClientId(), getRealmInfoUrl());
|
String jwt;
|
||||||
|
try {
|
||||||
|
jwt = jwtProvider.createSignedRequestToken(app1.getClientId(), getRealmInfoUrl());
|
||||||
|
} finally {
|
||||||
Time.setOffset(0);
|
Time.setOffset(0);
|
||||||
|
}
|
||||||
return doClientCredentialsGrantRequest(jwt);
|
return doClientCredentialsGrantRequest(jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ public class LastSessionRefreshUnitTest extends AbstractKeycloakTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(KeycloakSession session) {
|
public void run(KeycloakSession session) {
|
||||||
|
try {
|
||||||
// Long timer interval. No message due the timer wasn't executed
|
// Long timer interval. No message due the timer wasn't executed
|
||||||
CrossDCLastSessionRefreshStore customStore1 = createStoreInstance(session, 100000, 10);
|
CrossDCLastSessionRefreshStore customStore1 = createStoreInstance(session, 100000, 10);
|
||||||
Time.setOffset(100);
|
Time.setOffset(100);
|
||||||
|
@ -146,10 +147,10 @@ public class LastSessionRefreshUnitTest extends AbstractKeycloakTest {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
Assert.assertEquals(1, counter.get());
|
Assert.assertEquals(1, counter.get());
|
||||||
|
} finally {
|
||||||
|
|
||||||
Time.setOffset(0);
|
Time.setOffset(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.keycloak.authorization.AuthorizationSpi;
|
||||||
import org.keycloak.authorization.DefaultAuthorizationProviderFactory;
|
import org.keycloak.authorization.DefaultAuthorizationProviderFactory;
|
||||||
import org.keycloak.authorization.store.StoreFactorySpi;
|
import org.keycloak.authorization.store.StoreFactorySpi;
|
||||||
import org.keycloak.cluster.ClusterSpi;
|
import org.keycloak.cluster.ClusterSpi;
|
||||||
|
import org.keycloak.common.util.Time;
|
||||||
import org.keycloak.component.ComponentFactoryProviderFactory;
|
import org.keycloak.component.ComponentFactoryProviderFactory;
|
||||||
import org.keycloak.component.ComponentFactorySpi;
|
import org.keycloak.component.ComponentFactorySpi;
|
||||||
import org.keycloak.events.EventStoreSpi;
|
import org.keycloak.events.EventStoreSpi;
|
||||||
|
@ -557,13 +558,15 @@ public abstract class KeycloakModelTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createEnvironment() {
|
public final void createEnvironment() {
|
||||||
|
Time.setOffset(0);
|
||||||
USE_DEFAULT_FACTORY = isUseSameKeycloakSessionFactoryForAllThreads();
|
USE_DEFAULT_FACTORY = isUseSameKeycloakSessionFactoryForAllThreads();
|
||||||
KeycloakModelUtils.runJobInTransaction(getFactory(), this::createEnvironment);
|
KeycloakModelUtils.runJobInTransaction(getFactory(), this::createEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanEnvironment() {
|
public final void cleanEnvironment() {
|
||||||
|
Time.setOffset(0);
|
||||||
if (getFactory() == null) {
|
if (getFactory() == null) {
|
||||||
reinitializeKeycloakSessionFactory();
|
reinitializeKeycloakSessionFactory();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue