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());
}
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());
}
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");
}
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());
}
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());
}
Aggregations