use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasProxyReceptorTests method testMissingPgtiou.
@Test
public void testMissingPgtiou() {
final CasProxyReceptor client = new CasProxyReceptor();
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
TestsHelper.expectException(() -> client.getCredentials(context.addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET_IOU, VALUE)), HttpAction.class, "Perfoming a 200 HTTP action");
assertEquals(200, context.getResponseStatus());
assertEquals("", context.getResponseContent());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasProxyReceptorTests method testOk.
@Test
public void testOk() {
final CasProxyReceptor client = new CasProxyReceptor();
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create().addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET, VALUE).addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET_IOU, VALUE);
TestsHelper.expectException(() -> client.getCredentials(context), HttpAction.class, "Perfoming a 200 HTTP action");
assertEquals(200, context.getResponseStatus());
assertTrue(context.getResponseContent().length() > 0);
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectCasClientTests method testNoTokenRedirectionExpected.
@Test
public void testNoTokenRedirectionExpected() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
final DirectCasClient client = new DirectCasClient(configuration);
final MockWebContext context = MockWebContext.create();
context.setFullRequestURL(CALLBACK_URL);
final HttpAction action = (HttpAction) TestsHelper.expectException(() -> client.getCredentials(context));
assertEquals(302, action.getCode());
assertEquals(addParameter(LOGIN_URL, CasConfiguration.SERVICE_PARAMETER, CALLBACK_URL), context.getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectCasProxyClientTests method testTokenExistsValidationOccurs.
@Test
public void testTokenExistsValidationOccurs() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
configuration.setProtocol(CasProtocol.CAS30_PROXY);
configuration.setDefaultTicketValidator((ticket, service) -> {
if (TICKET.equals(ticket) && CALLBACK_URL.equals(service)) {
return new AssertionImpl(TICKET);
}
throw new TechnicalException("Bad ticket or service");
});
final DirectCasProxyClient client = new DirectCasProxyClient(configuration, CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
context.setFullRequestURL(CALLBACK_URL + "?" + CasConfiguration.TICKET_PARAMETER + "=" + TICKET);
context.addRequestParameter(CasConfiguration.TICKET_PARAMETER, TICKET);
final TokenCredentials credentials = client.getCredentials(context);
assertEquals(TICKET, credentials.getToken());
final CommonProfile profile = credentials.getUserProfile();
assertTrue(profile instanceof CasProfile);
assertEquals(TICKET, profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasRestClientIT method internalTestRestBasic.
private void internalTestRestBasic(final CasRestBasicAuthClient client, int nbAttributes) {
final MockWebContext context = MockWebContext.create();
final String token = USER + ":" + USER;
context.addRequestHeader(VALUE, NAME + Base64.getEncoder().encodeToString(token.getBytes(StandardCharsets.UTF_8)));
final UsernamePasswordCredentials credentials = client.getCredentials(context);
final CasRestProfile profile = client.getUserProfile(credentials, context);
assertEquals(USER, profile.getId());
assertNotNull(profile.getTicketGrantingTicketId());
final TokenCredentials casCreds = client.requestServiceTicket(PAC4J_BASE_URL, profile, context);
final CasProfile casProfile = client.validateServiceTicket(PAC4J_BASE_URL, casCreds, context);
assertNotNull(casProfile);
assertEquals(USER, casProfile.getId());
assertEquals(nbAttributes, casProfile.getAttributes().size());
client.destroyTicketGrantingTicket(profile, context);
TestsHelper.expectException(() -> client.requestServiceTicket(PAC4J_BASE_URL, profile, context), TechnicalException.class, "Service ticket request for `#CasRestProfile# | id: " + USER + " | attributes: {} | roles: [] | permissions: [] | " + "isRemembered: false | clientName: CasRestBasicAuthClient | linkedId: null |` failed: (404) Not Found");
}
Aggregations