use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class CsrfAuthorizerTests method testNoTokenPostRequest.
@Test
public void testNoTokenPostRequest() {
final MockWebContext context = MockWebContext.create().addSessionAttribute(Pac4jConstants.CSRF_TOKEN, VALUE);
context.setRequestMethod(HttpConstants.HTTP_METHOD.POST.name());
Assert.assertFalse(authorizer.isAuthorized(context, null));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testAlreadyTried.
@Test
public void testAlreadyTried() {
final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
context.getSessionStore().set(context, client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
final HttpAction e = (HttpAction) TestsHelper.expectException(() -> client.redirect(context));
assertEquals(401, e.getCode());
assertEquals(401, context.getResponseStatus());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testStateParameter.
@Test
public void testStateParameter() {
final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
final MockWebContext context = MockWebContext.create();
TestsHelper.expectException(() -> client.redirect(context));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testSaveAlreadyTried.
@Test
public void testSaveAlreadyTried() {
final MockIndirectClient client = new MockIndirectClient(TYPE, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
client.setCallbackUrl(CALLBACK_URL);
final MockWebContext context = MockWebContext.create();
client.getCredentials(context);
assertEquals("true", context.getSessionStore().get(context, client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class BaseClientTests method testDirectClient.
@Test
public void testDirectClient() {
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);
final Credentials credentials = client.getCredentials(context);
assertNull(credentials);
}
Aggregations