Search in sources :

Example 16 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials 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

Test (org.junit.Test)16 MockCredentials (org.pac4j.core.credentials.MockCredentials)16 CommonProfile (org.pac4j.core.profile.CommonProfile)16 LinkedHashMap (java.util.LinkedHashMap)9 Clients (org.pac4j.core.client.Clients)4 HttpSession (javax.servlet.http.HttpSession)3 IndirectClient (org.pac4j.core.client.IndirectClient)3 MockIndirectClient (org.pac4j.core.client.MockIndirectClient)3 MockDirectClient (org.pac4j.core.client.MockDirectClient)1