Search in sources :

Example 21 with MockWebContext

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

the class HttpMethodMatcherTests method testBadMethod.

@Test
public void testBadMethod() {
    final HttpMethodMatcher matcher = new HttpMethodMatcher(HTTP_METHOD.GET);
    final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.POST.name());
    assertFalse(matcher.matches(context));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 22 with MockWebContext

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

the class DefaultCallbackClientFinderTests method testQueryParameter.

@Test
public void testQueryParameter() {
    final IndirectClient facebook = new MockIndirectClient("Facebook");
    final DirectClient basicAuth = new MockDirectClient("BasicAuth");
    final IndirectClient cas = new MockIndirectClient("cas");
    final Clients clients = new Clients(CALLBACK_URL, facebook, basicAuth, cas);
    clients.init();
    final MockWebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "facebook   ");
    final ClientFinder finder = new DefaultCallbackClientFinder();
    final List<Client> result = finder.find(clients, context, null);
    assertEquals(1, result.size());
    assertEquals(facebook, result.get(0));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 23 with MockWebContext

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

the class DefaultCallbackClientFinderTests method testDefaultClientIndirectClientInURL.

@Test
public void testDefaultClientIndirectClientInURL() {
    final IndirectClient facebook = new MockIndirectClient("Facebook");
    final IndirectClient twitter = new MockIndirectClient("Twitter");
    final Clients clients = new Clients(CALLBACK_URL, twitter, facebook);
    clients.init();
    final MockWebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "Twitter");
    final DefaultCallbackClientFinder finder = new DefaultCallbackClientFinder();
    final List<Client> result = finder.find(clients, context, "Twitter");
    assertEquals(1, result.size());
    assertEquals(twitter, result.get(0));
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 24 with MockWebContext

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

the class HeaderExtractorTests method testRetrieveHeaderOk.

@Test
public void testRetrieveHeaderOk() {
    final MockWebContext context = MockWebContext.create().addRequestHeader(GOOD_HEADER, GOOD_PREFIX + VALUE);
    final TokenCredentials credentials = extractor.extract(context);
    assertEquals(VALUE, credentials.getToken());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 25 with MockWebContext

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

the class RememberMeAuthorizationGeneratorTests method testGoodRmeValue.

@Test
public void testGoodRmeValue() {
    final RememberMeAuthorizationGenerator ag = new RememberMeAuthorizationGenerator<>();
    final MockWebContext context = MockWebContext.create().addRequestParameter("rme", "true");
    ag.generate(context, profile);
    assertTrue(profile.isRemembered());
}
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