use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DefaultCallbackClientFinderTests method testDefaultClientDirectClientInURL.
@Test
public void testDefaultClientDirectClientInURL() {
final IndirectClient facebook = new MockIndirectClient("Facebook");
final DirectClient basicAuth = new MockDirectClient("BasicAuth");
final Clients clients = new Clients(CALLBACK_URL, basicAuth, facebook);
clients.init();
final MockWebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, "basicauth");
final DefaultCallbackClientFinder finder = new DefaultCallbackClientFinder();
final List<Client> result = finder.find(clients, context, "Facebook");
assertEquals(1, result.size());
assertEquals(facebook, result.get(0));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class HeaderExtractorTests method testBadHeader.
@Test
public void testBadHeader() {
final MockWebContext context = MockWebContext.create().addRequestHeader(BAD_HEADER, GOOD_PREFIX + VALUE);
final TokenCredentials credentials = extractor.extract(context);
assertNull(credentials);
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class HeaderExtractorTests method testBadPrefix.
@Test
public void testBadPrefix() {
final MockWebContext context = MockWebContext.create().addRequestHeader(GOOD_HEADER, BAD_PREFIX + VALUE);
TestsHelper.expectException(() -> extractor.extract(context), CredentialsException.class, "Wrong prefix for header: " + GOOD_HEADER);
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testNullCredentials.
@Test
public void testNullCredentials() {
final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
final MockWebContext context = MockWebContext.create();
client.setCallbackUrl(CALLBACK_URL);
assertNull(client.getUserProfile(null, context));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testIndirectClientWithImmediate.
@Test
public void testIndirectClientWithImmediate() {
final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
client.redirect(context);
final String redirectionUrl = context.getResponseLocation();
assertEquals(LOGIN_URL, redirectionUrl);
}
Aggregations