use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrieveNoGetParameter.
@Test
public void testRetrieveNoGetParameter() {
final var context = MockWebContext.create().setRequestMethod(HttpConstants.HTTP_METHOD.GET.name());
final var credentials = getExtractor.extract(context, new MockSessionStore());
assertFalse(credentials.isPresent());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrieveGetParameterOk.
@Test
public void testRetrieveGetParameterOk() {
final var context = MockWebContext.create().setRequestMethod(HttpConstants.HTTP_METHOD.GET.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
final var credentials = (TokenCredentials) getExtractor.extract(context, new MockSessionStore()).get();
assertEquals(VALUE, credentials.getToken());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IpRegexpAuthorizerTests method testNoPattern.
@Test(expected = TechnicalException.class)
public void testNoPattern() {
final var authorizer = new IpRegexpAuthorizer();
authorizer.isAuthorized(MockWebContext.create(), new MockSessionStore(), null);
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectBasicAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
final var context = MockWebContext.create();
final var header = USERNAME + ":" + USERNAME;
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8)));
final var credentials = (UsernamePasswordCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(USERNAME, profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectBasicAuthClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var basicAuthClient = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator(), null);
TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Aggregations