Search in sources :

Example 71 with MockWebContext

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

the class ParameterExtractorTests method testRetrieveNoGetParameter.

@Test
public void testRetrieveNoGetParameter() {
    final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.GET.name());
    final TokenCredentials credentials = getExtractor.extract(context);
    assertNull(credentials);
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 72 with MockWebContext

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

the class CasClientTests method testBackLogout.

@Test
public void testBackLogout() {
    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, LOGOUT_MESSAGE).setRequestMethod(HTTP_METHOD.POST.name());
    TestsHelper.expectException(() -> casClient.getCredentials(context), HttpAction.class, "Perfoming a 204 HTTP action");
    assertEquals(204, context.getResponseStatus());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Test(org.junit.Test)

Example 73 with MockWebContext

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

the class CasClientTests method testFrontLogout.

@Test
public void testFrontLogout() {
    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)).setRequestMethod(HTTP_METHOD.GET.name());
    assertNull(casClient.getCredentials(context));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) Test(org.junit.Test)

Example 74 with MockWebContext

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

the class CasClientTests method testGatewayOK.

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

Example 75 with MockWebContext

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

the class CasClientTests method testRenew.

@Test
public void testRenew() {
    final CasConfiguration configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    final CasClient casClient = new CasClient(configuration);
    casClient.setCallbackUrl(CALLBACK_URL);
    configuration.setRenew(true);
    final MockWebContext context = MockWebContext.create();
    casClient.redirect(context);
    assertTrue(context.getResponseLocation().indexOf("renew=true") >= 0);
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CasConfiguration(org.pac4j.cas.config.CasConfiguration) 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