Search in sources :

Example 1 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.

the class DefaultSecurityLogicTests method testDoubleDirectClientChooseDirectClient.

@Test
public void testDoubleDirectClientChooseDirectClient() {
    final CommonProfile profile = new CommonProfile();
    profile.setId(NAME);
    final CommonProfile profile2 = new CommonProfile();
    profile2.setId(VALUE);
    final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
    final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
    config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
    clients = NAME + "," + VALUE;
    context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
    multiProfile = true;
    call();
    assertEquals(-1, context.getResponseStatus());
    assertEquals(1, nbCall);
    final LinkedHashMap<String, CommonProfile> profiles = (LinkedHashMap<String, CommonProfile>) context.getRequestAttribute(Pac4jConstants.USER_PROFILES);
    assertEquals(1, profiles.size());
    assertTrue(profiles.containsValue(profile2));
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockCredentials(org.pac4j.core.credentials.MockCredentials) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.

the class DefaultSecurityLogicTests method testDoubleIndirectClientBadOneChosen.

@Test
public void testDoubleIndirectClientBadOneChosen() {
    final IndirectClient indirectClient = new MockIndirectClient(NAME, RedirectAction.redirect(PAC4J_URL), new MockCredentials(), new CommonProfile());
    final IndirectClient indirectClient2 = new MockIndirectClient(VALUE, RedirectAction.redirect(PAC4J_BASE_URL), new MockCredentials(), new CommonProfile());
    config.setClients(new Clients(CALLBACK_URL, indirectClient, indirectClient2));
    clients = NAME;
    context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
    TestsHelper.expectException(() -> call(), TechnicalException.class, "Client not allowed: " + VALUE);
}
Also used : MockCredentials(org.pac4j.core.credentials.MockCredentials) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 3 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.

the class DefaultSecurityLogicTests method testNotAuthenticated.

@Test
public void testNotAuthenticated() {
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    clients = "";
    call();
    assertEquals(401, context.getResponseStatus());
}
Also used : MockCredentials(org.pac4j.core.credentials.MockCredentials) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 4 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.

the class DefaultSecurityLogicTests method testDoubleDirectClientChooseBadDirectClient.

@Test
public void testDoubleDirectClientChooseBadDirectClient() {
    final CommonProfile profile = new CommonProfile();
    profile.setId(NAME);
    final CommonProfile profile2 = new CommonProfile();
    profile2.setId(VALUE);
    final DirectClient directClient = new MockDirectClient(NAME, new MockCredentials(), profile);
    final DirectClient directClient2 = new MockDirectClient(VALUE, new MockCredentials(), profile2);
    config.setClients(new Clients(CALLBACK_URL, directClient, directClient2));
    clients = NAME;
    context.addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, VALUE);
    multiProfile = true;
    TestsHelper.expectException(() -> call(), TechnicalException.class, "Client not allowed: " + VALUE);
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) MockCredentials(org.pac4j.core.credentials.MockCredentials) Test(org.junit.Test)

Example 5 with MockCredentials

use of org.pac4j.core.credentials.MockCredentials in project pac4j by pac4j.

the class DefaultSecurityLogicTests method testNotAuthenticatedButMatcher.

@Test
public void testNotAuthenticatedButMatcher() {
    final IndirectClient indirectClient = new MockIndirectClient(NAME, null, new MockCredentials(), new CommonProfile());
    config.setClients(new Clients(CALLBACK_URL, indirectClient));
    config.addMatcher(NAME, context -> false);
    matchers = NAME;
    call();
    assertEquals(-1, context.getResponseStatus());
    assertEquals(1, nbCall);
}
Also used : MockCredentials(org.pac4j.core.credentials.MockCredentials) CommonProfile(org.pac4j.core.profile.CommonProfile) 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