use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectBasicAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final DirectBasicAuthClient client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator());
final MockWebContext context = MockWebContext.create();
final String header = USERNAME + ":" + USERNAME;
context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8)));
final UsernamePasswordCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
assertEquals(USERNAME, profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class DirectDigestAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final DirectDigestAuthClient client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
client.setRealm(REALM);
final MockWebContext context = MockWebContext.create();
context.addRequestHeader(AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
context.setRequestMethod(HTTP_METHOD.GET.name());
final DigestCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
String ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" + PASSWORD);
String serverDigest1 = credentials.calculateServerDigest(true, ha1);
String serverDigest2 = credentials.calculateServerDigest(false, PASSWORD);
assertEquals(DIGEST_RESPONSE, serverDigest1);
assertEquals(DIGEST_RESPONSE, serverDigest2);
assertEquals(USERNAME, profile.getId());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrieveGetParameterOk.
@Test
public void testRetrieveGetParameterOk() {
final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.GET.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
final TokenCredentials credentials = getExtractor.extract(context);
assertEquals(VALUE, credentials.getToken());
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrievePostParameterNotSupported.
@Test
public void testRetrievePostParameterNotSupported() {
final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.POST.name()).addRequestParameter(GOOD_PARAMETER, VALUE);
TestsHelper.expectException(() -> getExtractor.extract(context), CredentialsException.class, "POST requests not supported");
}
use of org.pac4j.core.context.MockWebContext in project pac4j by pac4j.
the class ParameterExtractorTests method testRetrieveNoPostParameter.
@Test
public void testRetrieveNoPostParameter() {
final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.POST.name());
final TokenCredentials credentials = postExtractor.extract(context);
assertNull(credentials);
}
Aggregations