Search in sources :

Example 26 with MockWebContext

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

the class CookieClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    final Cookie c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
    context.getRequestCookies().add(c);
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(c.getValue(), profile.getId());
}
Also used : Cookie(org.pac4j.core.context.Cookie) MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 27 with MockWebContext

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

the class CasClientTests method testGatewayMissing.

@Test
public void testGatewayMissing() {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    final CasClient casClient = new CasClient(configuration);
    casClient.setCallbackUrl(CALLBACK_URL);
    final MockWebContext context = MockWebContext.create();
    casClient.redirect(context);
    assertFalse(context.getResponseLocation().indexOf("gateway=true") >= 0);
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Test(org.junit.Test)

Example 28 with MockWebContext

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

the class CasClientTests method testFrontLogoutWithRelayState.

@Test
public void testFrontLogoutWithRelayState() {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    final CasClient casClient = new CasClient(configuration);
    casClient.setCallbackUrl(CALLBACK_URL);
    casClient.init();
    final MockWebContext context = MockWebContext.create().addRequestParameter(CasConfiguration.LOGOUT_REQUEST_PARAMETER, deflateAndBase64(LOGOUT_MESSAGE)).addRequestParameter(CasConfiguration.RELAY_STATE_PARAMETER, VALUE).setRequestMethod(HTTP_METHOD.GET.name());
    final HttpAction action = (HttpAction) TestsHelper.expectException(() -> casClient.getCredentials(context));
    assertEquals(TEMP_REDIRECT, action.getCode());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) HttpAction(org.pac4j.core.exception.HttpAction) Test(org.junit.Test)

Example 29 with MockWebContext

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

the class CasClientTests method testRenewMissing.

@Test
public void testRenewMissing() {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    final CasClient casClient = new CasClient(configuration);
    casClient.setCallbackUrl(CALLBACK_URL);
    final MockWebContext context = MockWebContext.create();
    casClient.redirect(context);
    assertFalse(context.getResponseLocation().indexOf("renew=true") >= 0);
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Test(org.junit.Test)

Example 30 with MockWebContext

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

the class CasProxyReceptorTests method testMissingPgt.

@Test
public void testMissingPgt() {
    final CasProxyReceptor client = new CasProxyReceptor();
    client.setCallbackUrl(CALLBACK_URL);
    final MockWebContext context = MockWebContext.create();
    try {
        client.getCredentials(context.addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET, VALUE));
    } catch (final HttpAction e) {
        assertEquals(200, context.getResponseStatus());
        assertEquals("", context.getResponseContent());
    }
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) HttpAction(org.pac4j.core.exception.HttpAction) 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