use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectFormClientTests method testGetUserProfile.
@Test
public void testGetUserProfile() {
final var formClient = getFormClient();
formClient.setProfileCreator((credentials, context, session) -> {
var username = ((UsernamePasswordCredentials) credentials).getUsername();
final var profile = new CommonProfile();
profile.setId(username);
profile.addAttribute(Pac4jConstants.USERNAME, username);
return Optional.of(profile);
});
final var context = MockWebContext.create();
final var profile = (CommonProfile) formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context, new MockSessionStore()).get();
assertEquals(USERNAME, profile.getId());
assertEquals(CommonProfile.class.getName() + Pac4jConstants.TYPED_ID_SEPARATOR + USERNAME, profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CommonProfile.class));
assertEquals(USERNAME, profile.getUsername());
assertEquals(1, profile.getAttributes().size());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectFormClientTests method testGetBadCredentials.
@Test
public void testGetBadCredentials() {
final var formClient = getFormClient();
final var context = MockWebContext.create();
assertFalse(formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), PASSWORD), new MockSessionStore()).isPresent());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectFormClientTests method testGetCredentialsMissingPassword.
@Test
public void testGetCredentialsMissingPassword() {
final var formClient = getFormClient();
final var context = MockWebContext.create();
assertFalse(formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD), new MockSessionStore()).isPresent());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectBasicAuthClientTests method testAuthenticationLowercase.
@Test
public void testAuthenticationLowercase() {
final var client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
final var context = MockWebContext.create();
final var header = USERNAME + ":" + USERNAME;
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER.toLowerCase(), "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 DirectDigestAuthClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var digestAuthClient = new DirectDigestAuthClient(new SimpleTestTokenAuthenticator(), null);
TestsHelper.expectException(() -> digestAuthClient.getUserProfile(new DigestCredentials(TOKEN, HTTP_METHOD.POST.name(), null, null, null, null, null, null, null), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Aggregations