use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class HeaderClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var client = new HeaderClient(NAME, new SimpleTestTokenAuthenticator());
client.setProfileCreator(null);
TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class OAuth20ClientTests method testGetRedirectionGithub.
@Test
public void testGetRedirectionGithub() {
final var action = (FoundAction) getClient().getRedirectionAction(MockWebContext.create(), new MockSessionStore()).get();
final var url = action.getLocation();
assertTrue(url != null && !url.isEmpty());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class OAuth20ClientTests method testSetState.
@Test
public void testSetState() throws MalformedURLException {
var client = new FacebookClient(KEY, SECRET);
client.setCallbackUrl(CALLBACK_URL);
client.getConfiguration().setStateGenerator(new StaticValueGenerator("oldstate"));
final var mockWebContext = MockWebContext.create();
var action = (FoundAction) client.getRedirectionAction(mockWebContext, new MockSessionStore()).get();
var url = new URL(action.getLocation());
final var stringMap = TestsHelper.splitQuery(url);
assertEquals(stringMap.get("state"), "oldstate");
action = (FoundAction) client.getRedirectionAction(mockWebContext, new MockSessionStore()).get();
var url2 = new URL(action.getLocation());
final var stringMap2 = TestsHelper.splitQuery(url2);
assertEquals(stringMap2.get("state"), "oldstate");
}
use of org.pac4j.core.context.session.MockSessionStore 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.context.session.MockSessionStore in project pac4j by pac4j.
the class SAML2AuthnRequestBuilderTests method testHttpSessionStoreGetterAndSetter.
@Test
public void testHttpSessionStoreGetterAndSetter() {
final WebContext webContext = MockWebContext.create();
final var messageStoreFactory = configuration.getSamlMessageStoreFactory();
final var store = messageStoreFactory.getMessageStore(webContext, new MockSessionStore());
final var builder = new SAML2AuthnRequestBuilder();
final var context = buildContext();
final var authnRequest = builder.build(context);
authnRequest.setAssertionConsumerServiceURL("https://pac4j.org");
store.set(authnRequest.getID(), authnRequest);
assertNotNull(store.get(authnRequest.getID()));
assertEquals("https://pac4j.org", authnRequest.getAssertionConsumerServiceURL());
}
Aggregations