Search in sources :

Example 1 with MockWebContext

use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.

the class DirectFormClientTests method testGetCredentialsMissingPassword.

@Test
public void testGetCredentialsMissingPassword() {
    final DirectFormClient formClient = getFormClient();
    final MockWebContext context = MockWebContext.create();
    assertNull(formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD)));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 2 with MockWebContext

use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.

the class DirectFormClientTests method testGetBadCredentials.

@Test
public void testGetBadCredentials() {
    final DirectFormClient formClient = getFormClient();
    final MockWebContext context = MockWebContext.create();
    assertNull(formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), PASSWORD)));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 3 with MockWebContext

use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.

the class DirectFormClientTests method testGetUserProfile.

@Test
public void testGetUserProfile() {
    final DirectFormClient formClient = getFormClient();
    formClient.setProfileCreator((credentials, context) -> {
        String username = credentials.getUsername();
        final CommonProfile profile = new CommonProfile();
        profile.setId(username);
        profile.addAttribute(Pac4jConstants.USERNAME, username);
        return profile;
    });
    final MockWebContext context = MockWebContext.create();
    final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context);
    assertEquals(USERNAME, profile.getId());
    assertEquals(CommonProfile.class.getName() + CommonProfile.SEPARATOR + USERNAME, profile.getTypedId());
    assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class));
    assertEquals(USERNAME, profile.getUsername());
    assertEquals(1, profile.getAttributes().size());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 4 with MockWebContext

use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.

the class FormClientTests method testGetCredentialsMissingPassword.

@Test
public void testGetCredentialsMissingPassword() {
    final FormClient formClient = getFormClient();
    final MockWebContext context = MockWebContext.create();
    TestsHelper.expectException(() -> formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD)), HttpAction.class, "Perfoming a 302 HTTP action");
    assertEquals(302, context.getResponseStatus());
    assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=&" + FormClient.ERROR_PARAMETER + "=" + FormClient.MISSING_FIELD_ERROR, context.getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 5 with MockWebContext

use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.

the class FormClientTests method testRedirectionUrl.

@Test
public void testRedirectionUrl() {
    final FormClient formClient = getFormClient();
    MockWebContext context = MockWebContext.create();
    formClient.redirect(context);
    assertEquals(LOGIN_URL, context.getResponseLocation());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Aggregations

MockWebContext (org.pac4j.core.context.MockWebContext)96 Test (org.junit.Test)91 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)20 CommonProfile (org.pac4j.core.profile.CommonProfile)18 CasConfiguration (org.pac4j.cas.config.CasConfiguration)10 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)5 HttpAction (org.pac4j.core.exception.HttpAction)5 CasProfile (org.pac4j.cas.profile.CasProfile)4 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)4 DigestCredentials (org.pac4j.http.credentials.DigestCredentials)3 AssertionImpl (org.jasig.cas.client.validation.AssertionImpl)2 CasRestProfile (org.pac4j.cas.profile.CasRestProfile)2 Credentials (org.pac4j.core.credentials.Credentials)2 TechnicalException (org.pac4j.core.exception.TechnicalException)2 KerberosCredentials (org.pac4j.kerberos.credentials.KerberosCredentials)2 URL (java.net.URL)1 IndirectClient (org.pac4j.core.client.IndirectClient)1 Cookie (org.pac4j.core.context.Cookie)1 PathParameterCallbackUrlResolver (org.pac4j.core.http.callback.PathParameterCallbackUrlResolver)1 JavaSerializationHelper (org.pac4j.core.util.JavaSerializationHelper)1