use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DirectDigestAuthClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new DirectDigestAuthClient(new SimpleTestDigestAuthenticator());
client.setRealm(REALM);
final var context = MockWebContext.create();
context.addRequestHeader(AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
context.setRequestMethod(HTTP_METHOD.GET.name());
final var credentials = (DigestCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
var ha1 = CredentialUtil.encryptMD5(USERNAME + ":" + REALM + ":" + PASSWORD);
var serverDigest1 = credentials.calculateServerDigest(true, ha1);
var serverDigest2 = credentials.calculateServerDigest(false, PASSWORD);
assertEquals(DIGEST_RESPONSE, serverDigest1);
assertEquals(DIGEST_RESPONSE, serverDigest2);
assertEquals(USERNAME, profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class HeaderClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new HeaderClient(HEADER_NAME, PREFIX_HEADER, new SimpleTestTokenAuthenticator());
final var context = MockWebContext.create();
context.addRequestHeader(HEADER_NAME, PREFIX_HEADER + VALUE);
final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(VALUE, profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class ParameterClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator(), null);
TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class ParameterClientTests method testAuthentication.
@Test
public void testAuthentication() {
final var client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator());
client.setSupportGetRequest(SUPPORT_GET);
client.setSupportPostRequest(SUPPORT_POST);
final var context = MockWebContext.create();
context.addRequestParameter(PARAMETER_NAME, VALUE);
context.setRequestMethod(HttpConstants.HTTP_METHOD.GET.name());
final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
final var profile = (CommonProfile) client.getUserProfile(credentials, context, new MockSessionStore()).get();
assertEquals(VALUE, profile.getId());
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class IndirectBasicAuthClientTests method testMissingProfileCreator.
@Test
public void testMissingProfileCreator() {
final var basicAuthClient = new IndirectBasicAuthClient(NAME, new SimpleTestUsernamePasswordAuthenticator());
basicAuthClient.setCallbackUrl(CALLBACK_URL);
basicAuthClient.setProfileCreator(null);
TestsHelper.expectException(() -> basicAuthClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Aggregations