use of org.pac4j.core.exception.http.StatusAction in project pac4j by pac4j.
the class JEEHttpActionAdapterTest method testError500.
@Test
public void testError500() throws IOException {
JEEHttpActionAdapter.INSTANCE.adapt(new StatusAction(500), context);
verify(response).sendError(500);
}
use of org.pac4j.core.exception.http.StatusAction in project pac4j by pac4j.
the class OidcRedirectTests method testAjaxRequestAfterStandardRequestShouldNotOverrideState.
@Test
public void testAjaxRequestAfterStandardRequestShouldNotOverrideState() throws MalformedURLException, URISyntaxException {
var client = getClient();
client.setCallbackUrl(CALLBACK_URL);
client.setAjaxRequestResolver(new AjaxRequestResolver() {
boolean first = true;
@Override
public boolean isAjax(final WebContext context, final SessionStore sessionStore) {
/*
* Considers that the first request is not ajax, all the subsequent ones are
*/
if (first) {
first = false;
return false;
} else {
return true;
}
}
@Override
public HttpAction buildAjaxResponse(final WebContext context, final SessionStore sessionStore, final RedirectionActionBuilder redirectionActionBuilder) {
return new StatusAction(401);
}
});
var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
final var firstRequestAction = (FoundAction) client.getRedirectionAction(context, sessionStore).orElse(null);
var state = TestsHelper.splitQuery(new URL(firstRequestAction.getLocation())).get("state");
try {
// noinspection ThrowableNotThrown
client.getRedirectionAction(context, sessionStore);
fail("Ajax request should throw exception");
} catch (Exception e) {
var stateAfterAjax = (State) sessionStore.get(context, client.getStateSessionAttributeName()).orElse(null);
assertEquals("subsequent ajax request should not override the state in the session store", state, stateAfterAjax.toString());
}
}
use of org.pac4j.core.exception.http.StatusAction in project pac4j by pac4j.
the class DefaultSecurityLogicTests method testAuthorizerThrowsRequiresHttpAction.
@Test
public void testAuthorizerThrowsRequiresHttpAction() {
final var profile = new CommonProfile();
final var profiles = new LinkedHashMap<String, CommonProfile>();
profiles.put(NAME, profile);
sessionStore.set(context, Pac4jConstants.USER_PROFILES, profiles);
final IndirectClient indirectClient = new MockIndirectClient(NAME, null, Optional.of(new MockCredentials()), new CommonProfile());
authorizers = NAME;
config.setClients(new Clients(CALLBACK_URL, indirectClient));
config.addAuthorizer(NAME, (context, store, prof) -> {
throw new StatusAction(400);
});
call();
assertEquals(400, action.getCode());
assertEquals(0, nbCall);
}
Aggregations