Search in sources :

Example 81 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IpClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final var client = new IpClient(new SimpleTestTokenAuthenticator());
    client.setProfileCreator(null);
    TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 82 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class FormClientTests method testGetCredentials.

@Test
public void testGetCredentials() {
    final var formClient = getFormClient();
    final var context = MockWebContext.create();
    final var action = (FoundAction) TestsHelper.expectException(() -> formClient.getCredentials(context.addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), PASSWORD), new MockSessionStore()));
    assertEquals(302, action.getCode());
    assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=" + USERNAME + "&" + FormClient.ERROR_PARAMETER + "=" + CredentialsException.class.getSimpleName(), action.getLocation());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 83 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IpRegexpAuthenticatorTests method testValidateGoodIP.

@Test
public void testValidateGoodIP() {
    final var credentials = new TokenCredentials(GOOD_IP);
    authenticator.validate(credentials, null, new MockSessionStore());
    final var profile = (IpProfile) credentials.getUserProfile();
    assertEquals(GOOD_IP, profile.getId());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) IpProfile(org.pac4j.http.profile.IpProfile) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 84 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DigestExtractorTests method testRetrieveDigestHeaderComponents.

@Test
public void testRetrieveDigestHeaderComponents() {
    final var context = MockWebContext.create();
    context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, DIGEST_AUTHORIZATION_HEADER_VALUE);
    final var credentials = (DigestCredentials) digestExtractor.extract(context, new MockSessionStore()).get();
    assertEquals(DIGEST_RESPONSE, credentials.getToken());
    assertEquals(USERNAME, credentials.getUsername());
}
Also used : DigestCredentials(org.pac4j.http.credentials.DigestCredentials) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 85 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class ParameterExtractorTests method testRetrieveNoPostParameter.

@Test
public void testRetrieveNoPostParameter() {
    final var context = MockWebContext.create().setRequestMethod(HttpConstants.HTTP_METHOD.POST.name());
    final var credentials = postExtractor.extract(context, new MockSessionStore());
    assertFalse(credentials.isPresent());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4