Search in sources :

Example 61 with MockWebContext

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

the class IpExtractorTests method testRetrieveIpFromHeaderUsingConstructor.

@Test
public void testRetrieveIpFromHeaderUsingConstructor() {
    final MockWebContext context = MockWebContext.create().addRequestHeader(HEADER_NAME, GOOD_IP).setRemoteAddress(LOCALHOST);
    // test for varargs
    final IpExtractor ipExtractor = new IpExtractor("fooBar", HEADER_NAME, "barFoo");
    final TokenCredentials credentials = ipExtractor.extract(context);
    assertEquals(GOOD_IP, credentials.getToken());
    // test for edge case of 1 header
    final IpExtractor ipExtractor2 = new IpExtractor(HEADER_NAME);
    final TokenCredentials credentials2 = ipExtractor2.extract(context);
    assertEquals(GOOD_IP, credentials2.getToken());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 62 with MockWebContext

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

the class IpExtractorTests method testRetrieveIpFromHeaderWithProxyIpCheck.

@Test
public void testRetrieveIpFromHeaderWithProxyIpCheck() {
    final MockWebContext context = MockWebContext.create().addRequestHeader(HEADER_NAME, GOOD_IP).setRemoteAddress(LOCALHOST);
    final IpExtractor ipExtractor = new IpExtractor();
    ipExtractor.setProxyIp(LOCALHOST);
    // test for varargs
    ipExtractor.setAlternateIpHeaders("fooBar", HEADER_NAME, "barFoo");
    final TokenCredentials credentials = ipExtractor.extract(context);
    assertEquals(GOOD_IP, credentials.getToken());
    // test for edge case of 1 header
    ipExtractor.setAlternateIpHeaders(HEADER_NAME);
    final TokenCredentials credentials2 = ipExtractor.extract(context);
    assertEquals(GOOD_IP, credentials2.getToken());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 63 with MockWebContext

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

the class KerberosClientsKerbyTests method testIndirectIncorrectAuth.

@Test
public void testIndirectIncorrectAuth() {
    // a request with an incorrect Kerberos token, yields NULL credentials also
    final MockWebContext context = MockWebContext.create().addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Negotiate " + "AAAbbAA123");
    assertGetCredentialsFailsWithAuthRequired(setupIndirectKerberosClient(), context, "Perfoming a 401 HTTP action");
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 64 with MockWebContext

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

the class RememberMeAuthorizationGeneratorTests method testBadRmeValue.

@Test
public void testBadRmeValue() {
    final RememberMeAuthorizationGenerator ag = new RememberMeAuthorizationGenerator<>();
    final MockWebContext context = MockWebContext.create().addRequestParameter("rme", "no");
    ag.generate(context, profile);
    assertFalse(profile.isRemembered());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) Test(org.junit.Test)

Example 65 with MockWebContext

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

the class RememberMeAuthorizationGeneratorTests method testGoodSpecialRmeValue.

@Test
public void testGoodSpecialRmeValue() {
    final RememberMeAuthorizationGenerator ag = new RememberMeAuthorizationGenerator<>("r", "y");
    final MockWebContext context = MockWebContext.create().addRequestParameter("r", "y");
    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