Search in sources :

Example 46 with MockWebContext

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

the class BaseClientTests method testAjaxRequest.

@Test
public void testAjaxRequest() {
    final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
    client.setCallbackUrl(CALLBACK_URL);
    final MockWebContext context = MockWebContext.create().addRequestHeader(HttpConstants.AJAX_HEADER_NAME, HttpConstants.AJAX_HEADER_VALUE);
    final HttpAction e = (HttpAction) TestsHelper.expectException(() -> client.redirect(context));
    assertEquals(401, e.getCode());
    assertEquals(401, context.getResponseStatus());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) HttpAction(org.pac4j.core.exception.HttpAction) Test(org.junit.Test)

Example 47 with MockWebContext

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

the class OAuth20ClientTests method testSetState.

@Test
public void testSetState() throws MalformedURLException {
    FacebookClient client = new FacebookClient(KEY, SECRET);
    client.setCallbackUrl(CALLBACK_URL);
    client.setStateData("oldstate");
    final MockWebContext mockWebContext = MockWebContext.create();
    URL url = new URL(client.getRedirectAction(mockWebContext).getLocation());
    final Map<String, String> stringMap = splitQuery(url);
    assertEquals(stringMap.get("state"), "oldstate");
    URL url2 = new URL(client.getRedirectAction(mockWebContext).getLocation());
    final Map<String, String> stringMap2 = splitQuery(url2);
    assertEquals(stringMap2.get("state"), "oldstate");
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) URL(java.net.URL) Test(org.junit.Test)

Example 48 with MockWebContext

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

the class DirectFormClientTests method testGetCredentialsMissingUsername.

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

Example 49 with MockWebContext

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

the class HeaderClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final HeaderClient client = new HeaderClient(HEADER_NAME, PREFIX_HEADER, new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    context.addRequestHeader(HEADER_NAME, PREFIX_HEADER + VALUE);
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(VALUE, profile.getId());
}
Also used : 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 50 with MockWebContext

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

the class IpClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final IpClient client = new IpClient(new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    context.setRemoteAddress(IP);
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(IP, profile.getId());
}
Also used : 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)

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