Search in sources :

Example 6 with SessionRepresentation

use of org.keycloak.representations.account.SessionRepresentation in project keycloak by keycloak.

the class SessionRestServiceTest method testGetDevicesResponse.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testGetDevicesResponse() throws Exception {
    assumeTrue("Browser must be htmlunit. Otherwise we are not able to set desired BrowserHeaders", System.getProperty("browser").equals("htmlUnit"));
    oauth.setBrowserHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0) Gecko/20100101 Firefox/15.0.1");
    OAuthClient.AccessTokenResponse tokenResponse = codeGrant("public-client-0");
    joinSsoSession("public-client-1");
    List<DeviceRepresentation> devices = getDevicesOtherThanOther(tokenResponse.getAccessToken());
    assertEquals("Should have a single device", 1, devices.size());
    DeviceRepresentation device = devices.get(0);
    assertTrue(device.getCurrent());
    assertEquals("Windows", device.getOs());
    assertEquals("10", device.getOsVersion());
    assertEquals("Other", device.getDevice());
    List<SessionRepresentation> sessions = device.getSessions();
    assertEquals(1, sessions.size());
    SessionRepresentation session = sessions.get(0);
    assertEquals("127.0.0.1", session.getIpAddress());
    assertTrue(device.getLastAccess() == session.getLastAccess());
    List<ClientRepresentation> clients = session.getClients();
    assertEquals(2, clients.size());
    assertThat(session.getClients(), Matchers.hasItem(Matchers.hasProperty("clientId", anyOf(Matchers.is("public-client-0"), Matchers.is("public-client-1")))));
    assertThat(session.getClients(), Matchers.hasItem(Matchers.hasProperty("clientName", anyOf(Matchers.is("Public Client 0"), Matchers.is("Public Client 1")))));
}
Also used : DeviceRepresentation(org.keycloak.representations.account.DeviceRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) SessionRepresentation(org.keycloak.representations.account.SessionRepresentation) ClientRepresentation(org.keycloak.representations.account.ClientRepresentation) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 7 with SessionRepresentation

use of org.keycloak.representations.account.SessionRepresentation in project keycloak by keycloak.

the class SessionRestServiceTest method testNullOrEmptyUserAgent.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testNullOrEmptyUserAgent() throws Exception {
    assumeTrue("Browser must be htmlunit. Otherwise we are not able to set desired BrowserHeaders", System.getProperty("browser").equals("htmlUnit"));
    oauth.setBrowserHeader("User-Agent", null);
    OAuthClient.AccessTokenResponse tokenResponse = codeGrant("public-client-0");
    List<DeviceRepresentation> devices = queryDevices(tokenResponse.getAccessToken());
    assertEquals("Should have a single device", 1, devices.size());
    DeviceRepresentation device = devices.get(0);
    assertTrue(device.getCurrent());
    assertEquals("Other", device.getOs());
    assertEquals("Other", device.getDevice());
    List<SessionRepresentation> sessions = device.getSessions();
    assertEquals(1, sessions.size());
    SessionRepresentation session = sessions.get(0);
    assertEquals("127.0.0.1", session.getIpAddress());
    assertEquals(device.getLastAccess(), session.getLastAccess());
    assertEquals(1, session.getClients().size());
}
Also used : DeviceRepresentation(org.keycloak.representations.account.DeviceRepresentation) OAuthClient(org.keycloak.testsuite.util.OAuthClient) SessionRepresentation(org.keycloak.representations.account.SessionRepresentation) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Aggregations

SessionRepresentation (org.keycloak.representations.account.SessionRepresentation)7 Test (org.junit.Test)5 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)4 ClientRepresentation (org.keycloak.representations.account.ClientRepresentation)3 DeviceRepresentation (org.keycloak.representations.account.DeviceRepresentation)3 OAuthClient (org.keycloak.testsuite.util.OAuthClient)3 TokenUtil (org.keycloak.testsuite.util.TokenUtil)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 List (java.util.List)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Collectors (java.util.stream.Collectors)1 Matchers (org.hamcrest.Matchers)1 Matchers.anyOf (org.hamcrest.Matchers.anyOf)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Drone (org.jboss.arquillian.drone.api.annotation.Drone)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.assertTrue (org.junit.Assert.assertTrue)1