String refreshId = oauth.verifyRefreshToken(tokenResponse.getRefreshToken()).getId();
KeycloakSession session = keycloakRule.startSession();
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel userSession = session.sessions().getUserSession(realm, sessionId);
int last = userSession.getLastSessionRefresh();
session.getTransaction().commit();
session.close();
Thread.sleep(2000);
tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "password");
AccessToken refreshedToken = oauth.verifyToken(tokenResponse.getAccessToken());
RefreshToken refreshedRefreshToken = oauth.verifyRefreshToken(tokenResponse.getRefreshToken());
Assert.assertEquals(200, tokenResponse.getStatusCode());
session = keycloakRule.startSession();
realm = session.realms().getRealmByName("test");
userSession = session.sessions().getUserSession(realm, sessionId);
int next = userSession.getLastSessionRefresh();
session.getTransaction().commit();
session.close();
Assert.assertNotEquals(last, next);
session = keycloakRule.startSession();
realm = session.realms().getRealmByName("test");
int lastAccessTokenLifespan = realm.getAccessTokenLifespan();
realm.setAccessTokenLifespan(100000);
session.getTransaction().commit();
session.close();
Thread.sleep(2000);
tokenResponse = oauth.doRefreshTokenRequest(tokenResponse.getRefreshToken(), "password");
session = keycloakRule.startSession();
realm = session.realms().getRealmByName("test");
userSession = session.sessions().getUserSession(realm, sessionId);
next = userSession.getLastSessionRefresh();
session.getTransaction().commit();
session.close();
// lastSEssionRefresh should be updated because access code lifespan is higher than sso idle timeout
Assert.assertThat(next, allOf(greaterThan(last), lessThan(last + 6)));