use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IndirectBasicAuthClientTests method testGetCredentialsGoodCredentials.
@Test
public void testGetCredentialsGoodCredentials() {
final var basicAuthClient = getBasicAuthClient();
final var header = USERNAME + ":" + USERNAME;
final var credentials = (UsernamePasswordCredentials) basicAuthClient.getCredentials(getContextWithAuthorizationHeader("Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))), new MockSessionStore()).get();
assertEquals(USERNAME, credentials.getUsername());
assertEquals(USERNAME, credentials.getPassword());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IpExtractorTests method testRetrieveIpOk.
@Test
public void testRetrieveIpOk() {
final var context = MockWebContext.create().setRemoteAddress(GOOD_IP);
final var credentials = (TokenCredentials) extractor.extract(context, new MockSessionStore()).get();
assertEquals(GOOD_IP, credentials.getToken());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class FormClientTests method testRedirectionUrl.
@Test
public void testRedirectionUrl() {
final var formClient = getFormClient();
var context = MockWebContext.create();
final var action = (FoundAction) formClient.getRedirectionAction(context, new MockSessionStore()).get();
assertEquals(LOGIN_URL, action.getLocation());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CookieClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
final var context = MockWebContext.create();
final var c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
context.getRequestCookies().add(c);
final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(c.getValue(), profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectBearerAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator());
final var context = MockWebContext.create();
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + TOKEN);
final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(TOKEN, profile.getId());
}
Aggregations