Search in sources :

Example 16 with MockIndirectClient

use of org.pac4j.core.client.MockIndirectClient in project pac4j by pac4j.

the class DefaultCallbackLogicTests method testCallback.

@Test
public void testCallback() {
    final String originalSessionId = request.getSession().getId();
    request.setParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, NAME);
    final CommonProfile profile = new CommonProfile();
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), profile);
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    config.getClients().init();
    call();
    final HttpSession session = request.getSession();
    final String newSessionId = session.getId();
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) session.getAttribute(Pac4jConstants.USER_PROFILES);
    assertTrue(profiles.containsValue(profile));
    assertEquals(1, profiles.size());
    assertNotEquals(newSessionId, originalSessionId);
    assertEquals(302, response.getStatus());
    assertEquals(Pac4jConstants.DEFAULT_URL_VALUE, response.getRedirectedUrl());
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) MockCredentials(org.pac4j.core.credentials.MockCredentials) HttpSession(javax.servlet.http.HttpSession) MockIndirectClient(org.pac4j.core.client.MockIndirectClient) IndirectClient(org.pac4j.core.client.IndirectClient) Clients(org.pac4j.core.client.Clients) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

MockIndirectClient (org.pac4j.core.client.MockIndirectClient)16 CommonProfile (org.pac4j.core.profile.CommonProfile)16 Clients (org.pac4j.core.client.Clients)15 Test (org.junit.Test)14 MockWebContext (org.pac4j.core.context.MockWebContext)7 WebContext (org.pac4j.core.context.WebContext)7 Client (org.pac4j.core.client.Client)6 LinkedHashMap (java.util.LinkedHashMap)3 HttpSession (javax.servlet.http.HttpSession)3 IndirectClient (org.pac4j.core.client.IndirectClient)3 MockCredentials (org.pac4j.core.credentials.MockCredentials)3