use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectFormClientTests method testGetCredentialsMissingPassword.
@Test
public void testGetCredentialsMissingPassword() {
final DirectFormClient formClient = getFormClient();
final MockWebContext context = MockWebContext.create();
assertNull(formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD)));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectFormClientTests method testGetBadCredentials.
@Test
public void testGetBadCredentials() {
final DirectFormClient formClient = getFormClient();
final MockWebContext context = MockWebContext.create();
assertNull(formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), PASSWORD)));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectFormClientTests method testGetUserProfile.
@Test
public void testGetUserProfile() {
final DirectFormClient formClient = getFormClient();
formClient.setProfileCreator((credentials, context) -> {
String username = credentials.getUsername();
final CommonProfile profile = new CommonProfile();
profile.setId(username);
profile.addAttribute(Pac4jConstants.USERNAME, username);
return profile;
});
final MockWebContext context = MockWebContext.create();
final CommonProfile profile = formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, USERNAME), context);
assertEquals(USERNAME, profile.getId());
assertEquals(CommonProfile.class.getName() + CommonProfile.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.MockWebContext in project pac4j by pac4j.
the class FormClientTests method testGetCredentialsMissingPassword.
@Test
public void testGetCredentialsMissingPassword() {
final FormClient formClient = getFormClient();
final MockWebContext context = MockWebContext.create();
TestsHelper.expectException(() -> formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD)), HttpAction.class, "Perfoming a 302 HTTP action");
assertEquals(302, context.getResponseStatus());
assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=&" + FormClient.ERROR_PARAMETER + "=" + FormClient.MISSING_FIELD_ERROR, context.getResponseHeaders().get(HttpConstants.LOCATION_HEADER));
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class FormClientTests method testRedirectionUrl.
@Test
public void testRedirectionUrl() {
final FormClient formClient = getFormClient();
MockWebContext context = MockWebContext.create();
formClient.redirect(context);
assertEquals(LOGIN_URL, context.getResponseLocation());
}
Aggregations