use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CookieClientTests method testAuthentication.
@Test
public void testAuthentication() {
final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
final MockWebContext context = MockWebContext.create();
final Cookie c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
context.getRequestCookies().add(c);
final TokenCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
assertEquals(c.getValue(), profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasClientTests method testGatewayMissing.
@Test
public void testGatewayMissing() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
final CasClient casClient = new CasClient(configuration);
casClient.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
casClient.redirect(context);
assertFalse(context.getResponseLocation().indexOf("gateway=true") >= 0);
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasClientTests method testFrontLogoutWithRelayState.
@Test
public void testFrontLogoutWithRelayState() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
final CasClient casClient = new CasClient(configuration);
casClient.setCallbackUrl(CALLBACK_URL);
casClient.init();
final MockWebContext context = MockWebContext.create().addRequestParameter(CasConfiguration.LOGOUT_REQUEST_PARAMETER, deflateAndBase64(LOGOUT_MESSAGE)).addRequestParameter(CasConfiguration.RELAY_STATE_PARAMETER, VALUE).setRequestMethod(HTTP_METHOD.GET.name());
final HttpAction action = (HttpAction) TestsHelper.expectException(() -> casClient.getCredentials(context));
assertEquals(TEMP_REDIRECT, action.getCode());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasClientTests method testRenewMissing.
@Test
public void testRenewMissing() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setLoginUrl(LOGIN_URL);
final CasClient casClient = new CasClient(configuration);
casClient.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
casClient.redirect(context);
assertFalse(context.getResponseLocation().indexOf("renew=true") >= 0);
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CasProxyReceptorTests method testMissingPgt.
@Test
public void testMissingPgt() {
final CasProxyReceptor client = new CasProxyReceptor();
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
try {
client.getCredentials(context.addRequestParameter(CasProxyReceptor.PARAM_PROXY_GRANTING_TICKET, VALUE));
} catch (final HttpAction e) {
assertEquals(200, context.getResponseStatus());
assertEquals("", context.getResponseContent());
}
}
Aggregations