use of org.keycloak.testsuite.arquillian.annotation.ModelTest in project keycloak by keycloak.
the class UserSessionProviderTest method testUpdateSessionInSameTransaction.
@Test
@ModelTest
public void testUpdateSessionInSameTransaction(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
UserSessionModel[] sessions = createSessions(session);
int lastRefresh = Time.currentTime();
session.sessions().getUserSession(realm, sessions[0].getId()).setLastSessionRefresh(lastRefresh);
assertEquals(lastRefresh, session.sessions().getUserSession(realm, sessions[0].getId()).getLastSessionRefresh());
}
use of org.keycloak.testsuite.arquillian.annotation.ModelTest in project keycloak by keycloak.
the class UserSessionProviderTest method testGetByClientPaginated.
@Test
@ModelTest
public void testGetByClientPaginated(KeycloakSession session) {
RealmModel realm = session.realms().getRealmByName("test");
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession kcSession) -> {
try {
for (int i = 0; i < 25; i++) {
Time.setOffset(i);
UserSessionModel userSession = kcSession.sessions().createUserSession(realm, kcSession.users().getUserByUsername(realm, "user1"), "user1", "127.0.0." + i, "form", false, null, null);
AuthenticatedClientSessionModel clientSession = kcSession.sessions().createClientSession(realm, realm.getClientByClientId("test-app"), userSession);
assertNotNull(clientSession);
clientSession.setRedirectUri("http://redirect");
clientSession.setNote(OIDCLoginProtocol.STATE_PARAM, "state");
clientSession.setTimestamp(userSession.getStarted());
userSession.setLastSessionRefresh(userSession.getStarted());
}
} finally {
Time.setOffset(0);
}
});
assertPaginatedSession(session, realm, realm.getClientByClientId("test-app"), 0, 1, 1);
assertPaginatedSession(session, realm, realm.getClientByClientId("test-app"), 0, 10, 10);
assertPaginatedSession(session, realm, realm.getClientByClientId("test-app"), 10, 10, 10);
assertPaginatedSession(session, realm, realm.getClientByClientId("test-app"), 20, 10, 5);
assertPaginatedSession(session, realm, realm.getClientByClientId("test-app"), 30, 10, 0);
}
use of org.keycloak.testsuite.arquillian.annotation.ModelTest in project keycloak by keycloak.
the class ClientModelTest method testClientRoleRemovalAndClientScopeSameTx.
@Test
@ModelTest
public void testClientRoleRemovalAndClientScopeSameTx(KeycloakSession session) {
// Client "from" has a role. Assign this role to a scope to client "scoped". Delete the role and make sure
// cache gets cleared
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionClientRoleRemoveTx1) -> {
currentSession = sessionClientRoleRemoveTx1;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
ClientModel from = realm.addClient("from");
RoleModel role = from.addRole("clientRole");
roleId = role.getId();
ClientModel scoped = realm.addClient("scoped");
scoped.setFullScopeAllowed(false);
scoped.addScopeMapping(role);
});
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionClientRoleRemoveTx2) -> {
currentSession = sessionClientRoleRemoveTx2;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
ClientModel scoped = realm.getClientByClientId("scoped");
ClientModel from = realm.getClientByClientId("from");
RoleModel role = currentSession.roles().getRoleById(realm, roleId);
from.removeRole(role);
// used to throw an NPE
assertThat("Scope Mappings is not 0", scoped.getScopeMappingsStream().count(), is(0L));
currentSession.clients().removeClient(realm, scoped.getId());
currentSession.clients().removeClient(realm, from.getId());
});
}
use of org.keycloak.testsuite.arquillian.annotation.ModelTest in project keycloak by keycloak.
the class ClientModelTest method testClientRoleRemovalAndClientScope.
@Test
@ModelTest
public void testClientRoleRemovalAndClientScope(KeycloakSession session) {
// Client "from" has a role. Assign this role to a scope to client "scoped". Delete the role and make sure
// cache gets cleared
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionClientRoleRemove1) -> {
currentSession = sessionClientRoleRemove1;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
assertThat("Realm Model 'original' is NULL !!", realm, notNullValue());
ClientModel from = realm.addClient("from");
RoleModel role = from.addRole("clientRole");
roleId = role.getId();
ClientModel scoped = realm.addClient("scoped");
scoped.setFullScopeAllowed(false);
scoped.addScopeMapping(role);
});
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionClientRoleRemove2) -> {
currentSession = sessionClientRoleRemove2;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
assertThat("Realm Model 'original' is NULL !!", realm, notNullValue());
ClientModel from = realm.getClientByClientId("from");
RoleModel role = currentSession.roles().getRoleById(realm, roleId);
from.removeRole(role);
currentSession.clients().removeClient(realm, from.getId());
});
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionClientRoleRemove3) -> {
currentSession = sessionClientRoleRemove3;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
assertThat("Realm Model 'original' is NULL !!", realm, notNullValue());
ClientModel scoped = realm.getClientByClientId("scoped");
// used to throw an NPE
assertThat("Scope Mappings must be 0", scoped.getScopeMappingsStream().count(), is(0L));
currentSession.clients().removeClient(realm, scoped.getId());
});
}
use of org.keycloak.testsuite.arquillian.annotation.ModelTest in project keycloak by keycloak.
the class ClientModelTest method json.
@Test
@ModelTest
public void json(KeycloakSession session) {
KeycloakModelUtils.runJobInTransaction(session.getKeycloakSessionFactory(), (KeycloakSession sessionJson) -> {
currentSession = sessionJson;
RealmModel realm = currentSession.realms().getRealmByName(realmName);
client = setUpClient(realm);
ClientRepresentation representation = ModelToRepresentation.toRepresentation(client, currentSession);
representation.setId(null);
for (ProtocolMapperRepresentation protocolMapper : representation.getProtocolMappers()) {
protocolMapper.setId(null);
}
realm = currentSession.realms().createRealm("copy");
ClientModel copyClient = RepresentationToModel.createClient(currentSession, realm, representation);
assertEquals(client, copyClient);
client.unregisterNode("node1");
client.unregisterNode("10.20.30.40");
currentSession.clients().removeClient(realm, client.getId());
currentSession.clients().removeClient(realm, copyClient.getId());
currentSession.realms().removeRealm(realm.getId());
});
}
Aggregations