Search in sources :

Example 6 with DeviceRepresentation

use of org.keycloak.representations.account.DeviceRepresentation 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

DeviceRepresentation (org.keycloak.representations.account.DeviceRepresentation)6 Test (org.junit.Test)3 SessionRepresentation (org.keycloak.representations.account.SessionRepresentation)3 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)3 OAuthClient (org.keycloak.testsuite.util.OAuthClient)3 IOException (java.io.IOException)2 ClientRepresentation (org.keycloak.representations.account.ClientRepresentation)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)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 NoCache (org.jboss.resteasy.annotations.cache.NoCache)1 Assert.assertEquals (org.junit.Assert.assertEquals)1